

var MHeight = 0;
var widthL1 = 150;

var widthRemain = 760 - widthL1;

var isDOMxx = (document.getElementById ? true : false);
var isIE4xx = ((document.all && !isDOMxx) ? true : false);
var isNS4xx = (document.layers ? true : false);

var menu = new Array();
var litNow = new Array();
var popTimerxx = 0;

var OverL1 = '#326432', BackL1 = '#3c8757';
var OverL2 = '#028EB4', BackL2 = '#326432';
var BackL3 = '#DD7722';
var BackL4 = '#eea000';
var BackL5 = '#3080dd';
var textL1 = '#ffffff';
var textL2 = '#555555'

var basepx = 87;
var heightL1 = 21;
var widthL2 = 185;

var popOldWidth = window.innerWidth;
var shead = '<td align=center valign=center width=14><img src='+basepath+'english/images/js/shead.gif border=0 height=13 width=14 ';
var search = '<td align=center valign=center width=14><img src='+basepath+'english/images/general/search.gif border=0 height=13 width=14 ';
var space = '<td align=center valign=center width=14><img src='+basepath+'english/images/general/spacer.gif border=0 height=13 width=14 ';
var HOME = '<td align=center valign=center width=14><img src='+basepath+'english/images/js/home.gif border=0 height=13 width=14 ';
var allow = '<td align=center valign=center width=14><img src='+basepath+'english/images/js/allow.gif border=0 height=13 width=14 ';
var changeText1 = '<div onmouseover=chtext1(this) onmouseout=chtext2(this)>';
var changeText2 = '</div>'

function chtext1(x){
x.style.color=textL2;
}
function chtext2(x){
x.style.color=textL1;
}

function bg() {
 if(navigator.appName=="Microsoft Internet Explorer") {
  document.body.background = 'http://www.epd.gov.hk/epd/english/images/general/epd_bkg_new_ie.gif';
 } else {
  document.body.background = 'http://www.epd.gov.hk/epd/english/images/general/epd_bkg_new_ns.gif';
 }
}

function writeMenus() {
if (!isDOMxx && !isIE4xx && !isNS4xx) return;

for (currMenu = 0; currMenu < menu.length; currMenu++) with (menu[currMenu][0]) {
var str = '', itemX = 0, itemY = 0;
var swapbackCol = backCol;
var swapoverCol = overCol;

for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem]) {
var itemID = 'menu' + currMenu + 'item' + currItem;
var w = (isVert ? width : length);
var h = (isVert ? length : width);

if(currMenu==0){
    backCol = swapbackCol;
  if(currItem==1){
     backCol = BackL3;
  }
  if(currItem==2){
     backCol = BackL4;
  }
//  if(currItem==menu[currMenu].length-1){
//    backCol = BackL5;
//  }
} else {
backCol = swapbackCol;
}

if (isDOMxx || isIE4xx) {
str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit; ';
if (backCol) str += 'background: ' + backCol + '; ';
str += '" ';

backCol = swapbackCol;
overCol = swapoverCol;
}
if (isNS4xx) {
str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
if (backCol) str += 'bgcolor="' + backCol + '" ';
backCol = swapbackCol;
overCol = swapoverCol;
}
if (borderClass) str += 'class="' + borderClass + '" ';

if (href == "")
{
	str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';

	str += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4xx && borderClass ? 3 : 0) + '">' + "<tr>"  + image + '<td align="left" height="' + (h - 7) + '" class="' + textClass + '">' +  text + '</td>';
}
else if (frame == "_blank")
{
str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';

str += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4xx && borderClass ? 3 : 0) + '">' + "<tr onmouseout=clearstatus(); onmouseover=cursorhand(this,'"+href+"'); onclick=window.open('http://pc211.epd-asg.gov.hk/gb/www.epd-asg.gov.hk/english/images/js/"+href+"');>"  + image + '<td align="left" height="' + (h - 7) + '"  class="' + textClass + '">' + text + '</td>';

}
else
{
str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';

str += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4xx && borderClass ? 3 : 0) + '">' + "<tr onmouseout=clearstatus(); onmouseover=cursorhand(this,'"+href+"'); onclick=gourl('"+href+"');>"  + image + '<td align="left" height="' + (h - 7) + '">' + '<a class="' + textClass + '" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') + text + '</a></td>';
}
if (target > 0) {

menu[target][0].parentMenu = currMenu;
menu[target][0].parentItem = currItem;

if (popInd) str += '<td class="' + textClass + '" align="right">' + popInd + '</td>';
}
str += '</tr></table>' + (isNS4xx ? '</layer>' : '</div>');
if (isVert) itemY += length + spacing;
else itemX += length + spacing;
}
if (isDOMxx) {
var newDiv = document.createElement('div');
document.getElementsByTagName('body').item(0).appendChild(newDiv);
newDiv.innerHTML = str;
ref = newDiv.style;
ref.position = 'absolute';
ref.visibility = 'hidden';
}

if (isIE4xx) {
document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
ref = getSty('menu' + currMenu + 'div');
}

if (isNS4xx) {
ref = new Layer(0);
ref.document.write(str);
ref.document.close();
}

for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
itemName = 'menu' + currMenu + 'item' + currItem;
if (isDOMxx || isIE4xx) menu[currMenu][currItem].ref = getSty(itemName);
if (isNS4xx) menu[currMenu][currItem].ref = ref.document[itemName];
   }
}
with(menu[0][0]) {
ref.left = x;
ref.top = y;
ref.visibility = 'visible';
   }
}

/* function Item(image, text, href, frame, tall, spacing, target) */
/* Edit Menu Here -- Start */

menu[0] = new Array();
menu[0][0] = new Menu(true, '', 0, basepx, widthL1, OverL1, BackL1, 'itemBorder', 'itemText');
menu[0][1] = new Item1(HOME, changeText1+"Home"+changeText2, 'http://pc211.epd-asg.gov.hk/gb/www.epd.gov.hk/epd/eindex.html', '', 1, 0, 0);
menu[0][2] = new Item1(shead, "API", '', '', 1, 0, 0);
menu[0][3] = new Item1(space, "Current API", basepath+'eindex.html', '', 1, 0, 0);
menu[0][4] = new Item1(space, "API Forecast", basepath+'english/forecast/forecast.html', '', 1, 0, 0);
menu[0][5] = new Item1(space, "Advice to Public", basepath+'english/api_you/action.html', '', 1, 0, 0);
menu[0][6] = new Item1(space, "Past 24 Hours API", basepath+'english/24api/24api.html', '', 1, 0, 0);
menu[0][7] = new Item1(space, "Past 24 Hours Pollutant Concentration", basepath+'english/24pollu/24pc.html', '', 2.4, 0, 0);
menu[0][8] = new Item1(space, "Past API Record", basepath+'english/pastapi/pastapie.html', '', 1, 0, 0);
menu[0][9] = new Item1(space, "API Monthly Summary", basepath+'english/apisum/apisum.html', '', 2, 0, 0);
menu[0][10] = new Item1(space, "API & You", basepath+'english/api_you/api_you.html', '', 1, 0, 0);
menu[0][11] = new Item1(space, "API and Air Monitoring Background Information", basepath+'english/backgd/backgd.html', '', 2.8, 0, 0);
menu[0][12] = new Item1(space, "Air Quality Reports", basepath+'english/report/report.html', '', 1, 0, 0);
menu[0][13] = new Item1(space, "Other Related Websites", basepath+'english/airweb/eair.html', '', 2, 0, 0);
menu[0][14] = new Item2(space, "Aerosol Optical Depth Satellite Image (from Hong Kong Observatory)", 'http://pc211.epd-asg.gov.hk/gb/www.weather.gov.hk/wxinfo/intersat/modis/sat.html?size=l&type=aod', '_blank', 3.8, 0, 0);



/* Edit Menu Here -- End */

nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');

if (isNS4xx) document.captureEvents(Event.CLICK);
document.onclick = clickHandle;

function AddMenuHeight(y) {
        MHeight = MHeight + y - 1;
}

function cursorhand(x,y) {
	x.style.cursor = 'hand';
    window.status = y;
}

function clearstatus() {
 	window.status='';
}

function gourl(x) {
	window.location = x;
}

function getRef(id) {
if (isDOMxx) return document.getElementById(id);
if (isIE4xx) return document.all[id];
if (isNS4xx) return document.layers[id];
}

function getSty(id) {
return (isNS4xx ? getRef(id) : getRef(id).style);
}

function popOver(menuNum, itemNum) {
clearTimeout(popTimerxx);
hideAllBut(menuNum);
litNow = getTree(menuNum, itemNum);
changeCol(litNow, true);
targetNum = menu[menuNum][itemNum].target;
if (targetNum > 0) {
thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
with (menu[targetNum][0].ref) {
left = parseInt(thisX + menu[targetNum][0].x);
top = parseInt(thisY + menu[targetNum][0].y);
visibility = 'visible';
      }
   }
}

function popOut(menuNum, itemNum) {
if ((menuNum == 0) && !menu[menuNum][itemNum].target)
hideAllBut(0)
else
popTimerxx = setTimeout('hideAllBut(0)', 500);
}

function getTree(menuNum, itemNum) {

itemArray = new Array(menu.length);

while(1) {
itemArray[menuNum] = itemNum;

if (menuNum == 0) return itemArray;
itemNum = menu[menuNum][0].parentItem;
menuNum = menu[menuNum][0].parentMenu;
   }
}

function changeCol(changeArray, isOver) {
for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
if (changeArray[menuCount]) {
newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
// Change the colours of the div/layer background.
with (menu[menuCount][changeArray[menuCount]].ref) {

//if(menuCount==0 && (changeArray[menuCount]==1 || changeArray[menuCount]==2 || changeArray[menuCount]==menu[menuCount].length-1) ){
if(menuCount==0 && (changeArray[menuCount]==1 || changeArray[menuCount]==2) ){
} else {
if (isNS4xx) bgColor = newCol;
else backgroundColor = newCol;
}
         }
      }
   }
}
function hideAllBut(menuNum) {
var keepMenus = getTree(menuNum, 1);
for (count = 0; count < menu.length; count++)
if (!keepMenus[count])
menu[count][0].ref.visibility = 'hidden';
changeCol(litNow, false);
}

function Menu(isVert, popInd, x, y, width, overCol, backCol, borderClass, textClass) {

this.isVert = isVert;

this.popInd = popInd;

this.x = x;
this.y = y;
this.width = width;
this.overCol = overCol;
this.backCol = backCol;
this.borderClass = borderClass;
this.textClass = textClass;
this.parentMenu = null;
this.parentItem = null;
this.ref = null;

}

function Item1(image, text, href, frame, length, spacing, target) {
this.image = image + ' name="' + text + '"></td>';
this.text = text;
this.href = href;



this.frame = frame;

if(length > 1) {
  this.length = (length - 1) * heightL1 * 1.6;
} else {
  this.length = length * heightL1;  
}
AddMenuHeight(this.length);

this.spacing = spacing;
this.target  = target;
this.ref	 = null;
}

function Item2(image, text, href, frame, length, spacing, target) {
this.image = image + ' name="' + text + '"></td>';
this.text  = text;
this.href  = href;
this.frame = frame;

if(length > 2) {
  this.length = heightL1 * (1.6 + (length-2)*0.7);
} else if(length > 1) {
  this.length = heightL1 * 1.6;
} else {
  this.length = length * heightL1;  
}

this.spacing = spacing;
this.target = target;
this.ref = null;
}

function moveRoot()
{
 with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);
}

function clickHandle(evt)
{
 if (isNS4xx) document.routeEvent(evt);
 hideAllBut(0);
}

