/* JSCookMenu v2.0.3 (c) Copyright 2002-2006 by Heng Yuan http://jscook.sourceforge.net/JSCookMenu/
   rebuild by qass 2006.12.20 */
var JSCookMenu =
{ idCount: 0,
  idName: 'cmSubMenuID',
	timeOut: null,
	currentItem: null,
	noAction: {},
	noClick: {},
  split: {},
  menuList: [],
  itemList: [],
  frameList: [],
  frameListSize: 0,
  frameIDCount: 0,
  frameMasking: true,
  clicked: false,
  hideObjects: 0,
  imagePath: '',
  theme: { prefix: 'jscMenu',
           mainFolderLeft: '&nbsp;',
           mainFolderRight: '&nbsp;',
           mainItemLeft: '&nbsp;',
           mainItemRight: '&nbsp;',
           mainSpacing: 0,
           subSpacing: 0,
           delay: 500,
           zIndexStart: 1000,
           zIndexInc: 5,
           subMenuHeader: null,
           subMenuFooter: null,
           offsetHMainAdjust: [0, -1],
           offsetVMainAdjust: [-1, 0],
           offsetSubAdjust: [1, 0],
           clickOpen: 1,
           effect: null
         },
HSplit: function() { return [this.noClick, '<td class="' + this.prefix + 'MenuItemLeft"></td><td colspan="2"><div class="' + this.prefix + 'MenuSplit"></div></td>']; },
MainHSplit: function() { return [this.noClick, '<td class="' + this.prefix + 'MainItemLeft"></td><td colspan="2"><div class="' + this.prefix + 'MenuSplit"></div></td>']; },
MainVSplit: function() { return [this.noClick, '|']; },
getImage: function(strImgName) { return '<img alt="" src="' + this.imagePath + strImgName + '" />'; },
getSubMenu: function(subMenu, subID, zIndexStart, menuInfo, menuID) {
  var prefix = this.theme.prefix, str = '<div class="' + prefix + 'SubMenu" id="' + subID + '" style="z-index: ' + zIndexStart + ';position: absolute; top: 0px; left: 0px;">';
	if (this.theme.subMenuHeader) str += this.theme.subMenuHeader;
	str += '<table summary="sub menu" id="' + subID + 'Table" cellspacing="' + this.theme.subSpacing + '" class="' + prefix + 'SubMenuTable">';
	var strSub = '', item, idSub, hasChild, i, classStr, len = subMenu.length;
	for (i=5; i<len; ++i) {
		item = subMenu[i];
		if(!item) continue;
		if(item==this.split) item = this.splitItem(0, true);
		item.parentItem = subMenu, item.subMenuID = subID, hasChild = (item.length > 5), idSub = hasChild ? this.newID() : null, classStr = prefix + 'Menu' + (hasChild ? 'Folder' : 'Item');
		str += '<tr class="' + prefix + 'MenuItem"' + (item[0]!=this.noClick ? this.actionItem(item, 0, idSub, menuInfo, menuID) : this.noClickItem(item, 0, idSub, menuInfo, menuID)) + '>';
		if(item[0]==this.noAction || item[0]==this.noClick) {
			str += item[1] + '</tr>';
			continue;
		}
		str += '<td class="' + classStr + 'Left">' + (item[0]!=null ? item[0] : (hasChild ? this.getImage('spacer.gif') : this.getImage('spacer.gif'))) + '</td><td class="' + classStr + 'Text">' + item[1] + '</td><td class="' + classStr + 'Right">';
		if (hasChild) {
			str += this.getImage('arrow.gif');
			strSub += this.getSubMenu(item, idSub, zIndexStart + this.theme.zIndexInc, menuInfo, menuID);
		} else str += this.getImage('blank.gif');
		str += '</td></tr>';
	}
	str += '</table>';
	if (this.theme.subMenuFooter) str += this.theme.subMenuFooter;
	str += '</div>' + strSub;
	return str;
},
allocMenu: function(menu, orient) {
	var menuID = this.menuList.length;
	this.menuList[menuID] = {menu: menu, orient: orient};
	return menuID;
},
newID: function() { return this.idName + (++this.idCount); },
actionItem: function(item, isMain, idSub, menuInfo, menuID) {
  var index = this.itemList.length;
	this.itemList[index] = item, idSub = (!idSub) ? 'null' : ("'" + idSub + "'");
	var clickOpen = this.theme.clickOpen, onClick = (clickOpen == 3) || (clickOpen == 2 && isMain), param = 'this,' + isMain + ',' + idSub + ',' + menuID + ',' + index;
	return (onClick ? (' onmouseover="JSCookMenu.itemMouseOver(' + param + ',false)" onmousedown="JSCookMenu.itemMouseDownOpenSub(' + param + ')"') : (' onmouseover="JSCookMenu.itemMouseOverOpenSub(' + param + ')" onmousedown="JSCookMenu.itemMouseDown(' + param + ')"')) + ' onmouseout="JSCookMenu.itemMouseOut(' + param + ')" onmouseup="JSCookMenu.itemMouseUp(' + param + ')"';
},
noClickItem: function(item, isMain, idSub, menuInfo, menuID) {
  var index = this.itemList.length;
	this.itemList[index] = item, idSub = (!idSub) ? 'null' : ("'" + idSub + "'");
	var param = 'this,' + isMain + ',' + idSub + ',' + menuID + ',' + index;
	return ' onmouseover="JSCookMenu.itemMouseOver(' + param + ')" onmouseout="JSCookMenu.itemMouseOut(' + param + ')"';
},
splitItem: function(isMain, vertical) { return eval('JSCookMenu.' + (isMain ? ('Main' + (vertical ? 'HSplit' : 'VSplit')) : 'HSplit') + '()'); },
itemMouseOver: function(obj, isMain, idSub, menuID, index, calledByOpenSub) {
	if(!calledByOpenSub && this.clicked) {
		this.itemMouseOverOpenSub(obj, isMain, idSub, menuID, index);
		return;
	}
	clearTimeout(JSCookMenu.timeOut);
	if(this.itemList[index].isDisabled) return;
	thisMenu = this.getThisMenu(obj);
	if(!obj.cmMenuID) { obj.cmMenuID = menuID, obj.cmIsMain = isMain; }
	if (!thisMenu.cmItems) thisMenu.cmItems = [];
	var i;
	for(i=0; i<thisMenu.cmItems.length; ++i) if(thisMenu.cmItems[i]==obj) break;
	if(i==thisMenu.cmItems.length) thisMenu.cmItems[i] = obj;
	if(this.currentItem) {
		if(this.currentItem==obj || this.currentItem==thisMenu) {
			var item = this.itemList[index];
			this.setStatus(item);
			return;
		}
		var thatMenuInfo = this.menuList[this.currentItem.cmMenuID], thatMenu = this.getThisMenu(this.currentItem);
		if(thatMenu!=thisMenu.cmParentMenu) {
			this.currentItem.className = this.theme.prefix + (this.currentItem.cmIsMain ? 'MainItem' : 'MenuItem');
			if(thatMenu.id!=idSub) this.hideMenu(thatMenu, thisMenu, thatMenuInfo);
		}
	}
	this.currentItem = obj;
	this.resetMenu(thisMenu);
	var item = this.itemList[index], isDefaultItem = this.isDefaultItem(item);
	if (isDefaultItem) obj.className = this.theme.prefix + (isMain ? 'MainItemHover' : 'MenuItemHover');
	this.setStatus(item);
},
itemMouseOverOpenSub: function(obj, isMain, idSub, menuID, index) {
	clearTimeout (JSCookMenu.timeOut);
	if(this.itemList[index].isDisabled) return;
	this.itemMouseOver(obj, isMain, idSub, menuID, index, true);
	if(idSub) this.showSubMenu(obj, isMain, this.getObject(idSub), this.menuList[menuID]);
},
itemMouseOut: function(obj, isMain, idSub, menuID, index) {
	var delayTime = this.theme.delay;
	this.timeOut = window.setTimeout('JSCookMenu.hideMenuTime()', delayTime);
	window.defaultStatus = '';
},
itemMouseDown: function(obj, isMain, idSub, menuID, index) {
	if(this.itemList[index].isDisabled) return;
	if(this.isDefaultItem(this.itemList[index])) {
		var prefix = this.theme.prefix;
		obj.className = obj.cmIsMain ? (prefix + 'MainItemActive') : (prefix + 'MenuItemActive');
	}
},
itemMouseDownOpenSub: function(obj, isMain, idSub, menuID, index) {
  if(this.itemList[index].isDisabled) return;
	this.clicked = true;
	this.itemMouseDown(obj, isMain, idSub, menuID, index);
	if(idSub) this.showSubMenu (obj, isMain, this.getObject(idSub), this.menuList[menuID]);
},
itemMouseUp: function(obj, isMain, idSub, menuID, index) {
	if(this.itemList[index].isDisabled) return;
	var item = this.itemList[index], link = null, target = '_self';
	if(item.length>2) link = item[2];
	if(item.length>3 && item[3]) target = item[3];
	if(link != null) {
		this.clicked = false;
		window.open(link, target);
	}
	var menuInfo = this.menuList[menuID], prefix = this.theme.prefix, thisMenu = this.getThisMenu(obj), hasChild = (item.length > 5);
	if (!hasChild) {
		if(this.isDefaultItem(item)) obj.className = obj.cmIsMain ? (prefix + 'MainItem') : (prefix + 'MenuItem');
		this.hideMenu(thisMenu, null, menuInfo);
	} else {
		if (this.isDefaultItem (item)) obj.className = obj.cmIsMain ? (prefix + 'MainItemHover') : (prefix + 'MenuItemHover');
	}
},
moveSubMenu: function(obj, isMain, subMenu, menuInfo) {
	var orient = menuInfo.orient, offsetAdjust;
	if (isMain) offsetAdjust = orient.charAt(0)=='h'? this.theme.offsetHMainAdjust : this.theme.offsetVMainAdjust;
	else offsetAdjust = this.theme.offsetSubAdjust;
	if (!isMain && orient.charAt(0)=='h') orient = 'v' + orient.charAt(1) + orient.charAt(2);
	var mode = String(orient), p = subMenu.offsetParent, subMenuWidth = this.getWidth(subMenu), horiz = this.getHorizontalAlign(obj, mode, p, subMenuWidth);
	if (mode.charAt(0)=='h') {
		subMenu.style.top = (mode.charAt(1)=='b' ? (this.getYAt(obj, p) + this.getHeight(obj) + offsetAdjust[1]) : (this.getYAt(obj, p) - this.getHeight(subMenu) - offsetAdjust[1])) + 'px';
		subMenu.style.left = (horiz=='r' ? (this.getXAt(obj, p) + offsetAdjust[0]) : (this.getXAt(obj, p) + this.getWidth(obj) - subMenuWidth - offsetAdjust[0])) + 'px';
	} else {
		subMenu.style.top = (mode.charAt(1)=='b' ? (this.getYAt (obj, p) + offsetAdjust[1]) : (this.getYAt (obj, p) + this.getHeight (obj) - this.getHeight (subMenu) + offsetAdjust[1])) + 'px';
	  subMenu.style.left = (horiz=='r' ? (this.getXAt (obj, p) + this.getWidth (obj) + offsetAdjust[0]) : (this.getXAt (obj, p) - subMenuWidth - offsetAdjust[0])) + 'px';
	}
	if (horiz!=orient.charAt(2)) orient = orient.charAt(0) + orient.charAt(1) + horiz;
	return orient;
},
getHorizontalAlign: function(obj, mode, p, subMenuWidth) {
	var horiz = mode.charAt(2), body = document.body;
	if (!body) return horiz;
	var browserLeft, browserRight;
	if (window.innerWidth) {
		browserLeft = window.pageXOffset, browserRight = window.innerWidth + browserLeft;
	} else if(body.clientWidth) {
		browserLeft = body.clientLeft, browserRight = body.clientWidth + browserLeft;
	} else return horiz;
	if(mode.charAt(0)=='h') {
		if(horiz=='r' && (this.getXAt(obj) + subMenuWidth)>browserRight) horiz = 'l';
		if(horiz=='l' && (this.getXAt(obj) + this.getWidth(obj) - subMenuWidth)<browserLeft) horiz = 'r';
	} else {
		if(horiz=='r' && (this.getXAt(obj, p) + this.getWidth(obj) + subMenuWidth)>browserRight) horiz = 'l';
		if(horiz=='l' && (this.getXAt(obj, p) - subMenuWidth)< browserLeft) horiz = 'r';
	}
	return horiz;
},
showSubMenu: function(obj, isMain, subMenu, menuInfo) {
	var prefix = this.theme.prefix;
	if(!subMenu.cmParentMenu) {
		var thisMenu = this.getThisMenu(obj);
		subMenu.cmParentMenu = thisMenu;
		if (!thisMenu.cmSubMenu) thisMenu.cmSubMenu = [];
		thisMenu.cmSubMenu[thisMenu.cmSubMenu.length] = subMenu;
	}
	var effectInstance = subMenu.cmEffect;
	if(effectInstance) effectInstance.showEffect (true);
	else {
		var orient = this.moveSubMenu(obj, isMain, subMenu, menuInfo), forceShow = false;
		subMenu.cmOrient = orient;
		if(subMenu.style.visibility!= 'visible' && this.theme.effect) {
			try {
				effectInstance = this.theme.effect.getInstance(subMenu, orient);
				effectInstance.showEffect(false);
			} catch (e) {
				forceShow = true, subMenu.cmEffect = null;
			}
		} else forceShow = true;
		if (forceShow) {
			subMenu.style.visibility = 'visible';
		}
	}
	if(!this.hideObjects) {
		this.hideObjects = 2;
		try {
		  if (window.opera) if (parseInt(navigator.appVersion)<9) this.hideObjects = 1;
		} catch (e) {}
	}
	if(this.hideObjects==1) {
		if(!subMenu.cmOverlap) subMenu.cmOverlap = [];
		this.hideControl("IFRAME", subMenu);
		this.hideControl("OBJECT", subMenu);
	}
},
resetMenu: function(thisMenu) {
  var prefix = this.theme.prefix;
	if(thisMenu.cmItems) {
		var i, str, items = thisMenu.cmItems;
		for(i=0; i<items.length; ++i) {
			if(items[i].cmIsMain) {
				if(items[i].className==(prefix + 'MainItemDisabled')) continue;
			} else {
				if(items[i].className == (prefix + 'MenuItemDisabled')) continue;
			}
			if(items[i].cmIsMain) str = prefix + 'MainItem'; else str = prefix + 'MenuItem';
			if(items[i].className != str) items[i].className = str;
		}
	}
},
hideMenuTime: function() {
	this.clicked = false;
	if(this.currentItem) {
		var menuInfo = this.menuList[this.currentItem.cmMenuID];
		this.hideMenu(this.getThisMenu(this.currentItem), null, menuInfo);
		this.currentItem = null;
	}
},
hideThisMenu: function(thisMenu, menuInfo) {
	var effectInstance = thisMenu.cmEffect;
	if(effectInstance) effectInstance.hideEffect(true);
	else {
		thisMenu.style.visibility = 'hidden';
		thisMenu.style.top = '0px';
		thisMenu.style.left = '0px';
		thisMenu.cmOrient = null;
	}
	this.showControl(thisMenu);
	thisMenu.cmItems = null;
},
hideMenu: function(thisMenu, currentMenu, menuInfo) {
  var prefix = this.theme.prefix, str = prefix + 'SubMenu';
  if(thisMenu.cmSubMenu) for(var i=0; i<thisMenu.cmSubMenu.length; ++i) this.hideSubMenu(thisMenu.cmSubMenu[i], menuInfo);
	while(thisMenu && thisMenu!=currentMenu) {
		this.resetMenu(thisMenu);
		if(thisMenu.className==str) this.hideThisMenu(thisMenu, menuInfo); else break;
		thisMenu = this.getThisMenu(thisMenu.cmParentMenu);
	}
},
hideSubMenu: function(thisMenu, menuInfo) {
	if(thisMenu.style.visibility == 'hidden') return;
	if(thisMenu.cmSubMenu) for(var i=0; i<thisMenu.cmSubMenu.length; ++i) this.hideSubMenu(thisMenu.cmSubMenu[i], menuInfo);
	this.resetMenu(thisMenu);
	this.hideThisMenu (thisMenu, menuInfo);
},
hideControl: function(tagName, subMenu) {
	var x = this.getX(subMenu), y = this.getY(subMenu), w = subMenu.offsetWidth, h = subMenu.offsetHeight;
	var i, obj;
	for(i=0; i < document.all.tags(tagName).length; ++i) {
		obj = document.getElementsByTagName(tagName)[i];
		if(!obj || !obj.offsetParent) continue;
		var ox = this.getX(obj), oy = this.getY(obj), ow = obj.offsetWidth, oh = obj.offsetHeight;
		if(ox>(x + w) || (ox + ow) < x) continue;
		if(oy > (y + h) || (oy + oh) < y) continue;
		if(obj.style.visibility == 'hidden') continue;
		subMenu.cmOverlap[subMenu.cmOverlap.length] = obj;
		obj.style.visibility = 'hidden';
	}
},
showControl: function(subMenu) {
	if (subMenu.cmOverlap) for(var i = 0; i<subMenu.cmOverlap.length; ++i) subMenu.cmOverlap[i].style.visibility = "";
	subMenu.cmOverlap = null;
},
getThisMenu: function(obj) {
  var prefix = this.theme.prefix, str1 = prefix + 'SubMenu', str2 = prefix + 'Menu';
	while (obj) {
	  if(obj.className==str1 || obj.className==str2) return obj;
		obj = obj.parentNode;
	}
	return null;
},
isDefaultItem: function(item) {
	if(item==this.split || item[0]==this.noAction || item[0] == this.noClick) return false;
	return true;
},
getObject: function(subID) { return document.getElementById(subID); },
getWidth: function(obj) {
	var width = obj.offsetWidth;
	if(width>0 || !this.isTRNode(obj)) return width;
	if(!obj.firstChild) return 0;
	return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + this.getWidth(obj.lastChild);
},
getHeight: function(obj) {
	var height = obj.offsetHeight;
	if(height>0 || !this.isTRNode (obj)) return height;
	if(!obj.firstChild) return 0;
	return obj.firstChild.offsetHeight;
},
getX: function(obj) {
	if(!obj) return 0;
	var x = 0;
	do{ x += obj.offsetLeft, obj = obj.offsetParent; } while(obj);
	return x;
},
getXAt: function(obj, elm) {
	var x = 0;
	while (obj && obj!=elm) {
	  x += obj.offsetLeft, obj = obj.offsetParent;
	}
	if(obj==elm) return x;
	return x - this.getX(elm);
},
getY: function(obj) {
	if (!obj) return 0;
	var y = 0;
	do { y += obj.offsetTop, obj = obj.offsetParent; } while(obj);
  return y;
},
isTRNode: function(obj) { return obj.tagName.toLowerCase() == "tr"; },
getYAt: function(obj, elm) {
  var y = 0;
	if (!obj.offsetHeight && this.isTRNode(obj)) {
    obj = obj.firstChild, y -= obj.parentNode.firstChild.firstChild.offsetTop;
	}
	while (obj && obj != elm) { y += obj.offsetTop, obj = obj.offsetParent; }
	if(obj == elm) return y;
	return y - this.getY(elm);
},
setStatus: function(item) {
	var descript = '';
	if (item.length > 4) descript = (item[4] != null) ? item[4] : (item[2] ? item[2] : descript);
	else if(item.length > 2) descript = (item[2] ? item[2] : descript);
	window.defaultStatus = descript;
},
buildMenu: function(node) {
  if(!node) return [];
  var thePID, theID, objNode = {}, leng = node.length, arrMenu = [];
  arrMenu.push([null, node[0].name, node[0].url, node[0].target, null]);
  for(var i=1; i<leng; i++) {
    thePID = node[i].pid, theID = node[i].id;
    objNode[theID] = [null, node[i].name, node[i].url, node[i].target, null];
    if(objNode[thePID]) {
      objNode[thePID][objNode[thePID].length] = objNode[theID];
    } else {
      arrMenu[arrMenu.length] = objNode[theID];
    }
  }
  return arrMenu;
},
//----------------------------------
draw: function(menu, strPath, arrTop, orient) {
	if(!orient) orient = 'hbr';  // [hv][ub][lr]
	if(strPath) this.imagePath = strPath;
	menu = this.buildMenu(menu, arrTop);
  var prefix = this.theme.prefix, menuID = this.allocMenu(menu, orient), menuInfo = this.menuList[menuID];
  var strSub = '', vertical;
	var str = '<table summary="main menu" class="' + prefix + 'Menu" cellspacing="' + this.theme.mainSpacing + '">';
	if (orient.charAt(0)=='h') { str += '<tr>', vertical = false; } else { vertical = true; }
	var i, item, hasChild, idSub, classStr, leng = menu.length;
	for (i=0; i<leng; ++i) {
		item = menu[i];
		if(!item) continue;
		hasChild = (item.length > 5), idSub = hasChild ? this.newID() : null, classStr = prefix + 'Main' + (hasChild ? 'Folder' : 'Item');
		item.menu = menu;
		str += (vertical ? '<tr' : '<td') + ' class="' + prefix + 'MainItem"' + this.actionItem(item, 1, idSub, menuInfo, menuID) + '>';
		if(item == this.split) item = this.splitItem(1, vertical);
		if (item[0]==this.noAction || item[0]==this.noClick) {
			str += item[1] + (vertical? '</tr>' : '</td>');
			continue;
		}
		str += (vertical ? '<td' : '<span') + ' class="' + classStr + 'Left">' + (item[0] == null ? (hasChild ? this.theme.mainFolderLeft : this.theme.mainItemLeft) : item[0]);
		str += (vertical ? '</td><td' : '</span><span') + ' class="' + classStr + 'Text">' + item[1];
		str += (vertical ? '</td><td' : '</span><span') + ' class="' + classStr + 'Right">';
		str += (hasChild ? this.theme.mainFolderRight : this.theme.mainItemRight) + (vertical ? '</td></tr>' : '</span></td>');
		if (hasChild) strSub += this.getSubMenu(item, idSub, this.theme.zIndexStart, menuInfo, menuID);
	}
	if (!vertical) str += '</tr>';
	str += '</table>' + strSub;
	document.write(str);
}

}