

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 BackL6 = '#2060bb';
var textL1 = '#ffffff';
var textL2 = '#222222';

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+'tc_chi/images/front/shead.gif border=0 height=13 width=14 ';
var search = '<td align=center valign=center width=14><img src='+basepath+'tc_chi/images/front/search.gif alt=搜尋 border=0 height=13 width=14 ';
var space = '<td align=center valign=center width=14><img src='+basepath+'tc_chi/images/front/spacer.gif border=0 height=13 width=14 ';
var HOME = '<td align=center valign=center width=14><img src='+basepath+'tc_chi/images/front/home.gif alt=主頁 border=0 height=13 width=14 ';
var pdf = "<img src="+basepath+"tc_chi/images/front/get_adobe_reader.gif border=0 alt='取得 Adobe Reader'  height=31 width=88>";
var caring = "<img src="+basepath+"tc_chi/images/front/caring_org_0608.jpg border=0 alt='環保署獲頒「同心展關懷」2006/08年度標誌'  height=32 width=88>";
var efiling = "<img src="+basepath+"tc_chi/links/recommend/images/efiling_c.gif border=0 alt='電子報稅'  height=50 width=84>";
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 = basepath+'tc_chi/images/general/epd_bkg_new_ie.gif';
 } else {
  document.body.background = basepath+'tc_chi/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-4){
     backCol = BackL5;
  }
  if(currItem==menu[currMenu].length-3){
     backCol = '';
  }
  if(currItem==menu[currMenu].length-2){
     backCol = '';
  }    
  if(currItem==menu[currMenu].length-1){
     backCol = '';
  }  

} 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 (currMenu==0 && currItem==menu[currMenu].length-1 || currMenu==0 && currItem==menu[currMenu].length-2|| currMenu==0 && currItem==menu[currMenu].length-3){}else{ str += 'class="' + borderClass + '" ' };

str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';

str += '<table id="MENU" width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4xx && borderClass ? 3 : 0) + '">' + "<tr onmouseout=clearstatus(); onmouseover=cursorhand(this,'"+href+"'); onclick=gourl('"+href+"','"+frame+"');>"  + image + '<td align="left" height="' + (h - 7) + '">' + '<a class="' + textClass + '" >' + 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, length, 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+"主頁"+changeText2, basepath+'cindex.html', '', 1, 0, 0);
menu[0][2] = new Item1(shead, changeText1+"廢物"+changeText2, basepath+'tc_chi/environmentinhk/waste/waste_maincontent.html', '', 1, 0, 0);
menu[0][3] = new Item1(space, "問題與解決方案", basepath+'tc_chi/environmentinhk/waste/prob_solutions/waste_problems.html', '', 1, 0, 0);
menu[0][4] = new Item1(space, "資料與統計數字", basepath+'tc_chi/environmentinhk/waste/data/waste_data.html', '', 1, 0, 0);
menu[0][5] = new Item1(space, "公眾諮詢", basepath+'tc_chi/environmentinhk/waste/pub_consult/waste_consult.html', '', 1, 0, 0);
menu[0][6] = new Item1(space, "研究報告", basepath+'tc_chi/environmentinhk/waste/studyrpts/waste_studyrpts.html', '', 1, 0, 0);
menu[0][7] = new Item1(space, "指引與參考資料", basepath+'tc_chi/environmentinhk/waste/guide_ref/waste_guidelines.html', '', 1, 0, 0);
menu[0][8] = new Item1(space, "減少廢物計劃",'http://www.wastereduction.gov.hk','_blank', 1, 0, 0);
menu[0][9] = new Item1(space, "廢物收集/再造", basepath+'tc_chi/environmentinhk/waste/guide_ref/guide_ref_dwc.html', '', 1, 0, 0);
menu[0][10] = new Item1(space, "廢物處理設施", basepath+'tc_chi/environmentinhk/waste/manage_facility/manage_facility.html', '', 1, 0, 0);
menu[0][11] = new Item1(search, changeText1+"進階搜尋"+changeText2, basepath+'tc_chi/search/search.html', '', 1, 0, 0);
menu[0][12] = new Item1(space, '', '','', 0, 0, 0);
menu[0][13] = new Item1(space, pdf, 'http://www.chinese-t.adobe.com/products/acrobat/readstep2.html?c=hk', '_blank', 2.1, 0, 0);
//menu[0][13] = new Item1(space, caring, basepath+'tc_chi/caring/caring_logo.html', '_blank', 2.1, 0, 0);
menu[0][14] = new Item1(space, '', '', '_blank', 0, 0, 0);
//menu[0][14] = new Item1(space, efiling, 'http://www.ird.gov.hk/chi/ese/e_ctr.htm', '_blank', 2.1, 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,y) {
	if(y==''){
	window.location = x;
	} else {
	window.open(x,y);
	}
}

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-4 || changeArray[menuCount]==menu[menuCount].length-3 || changeArray[menuCount]==menu[menuCount].length-2 || changeArray[menuCount]==menu[menuCount].length-1) ){		
} 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);
}