//--<script>--

//--Global Menu variables--
var _IN_MENUITEM = false;
var _IN_MENUITEM_HEADER = false;
var _CURRENT_MENU_ITEM = null;
var _index = 0;

function Menu(w) {
//--Menu Object--
	this.width = w || 210;
	this.headerWidth = 100;
	this.length = 0;
	this.childItems = new Array();
	this.bgColor = '#f5f5f5';
	this.onMouseOverColor = '#c3f5b4';
	this.menuWidth = null;
	this.separator = null;
	this.menuAlign = 'left';
	this.borderColor = "";
	
	if (window.document.all) {
		this.isNS = false;
		this.isIE = true;
	}
	else {
		this.isNS = true;
		this.isIE = false;
	}
	
	this.addMenuItem = _addMenuItem;
	this.create = _create;
	this.setMenu = _setMenu;
}

function _setMenu(obj) {
	if (obj["width"]) this.width = obj["width"];
	if (obj["headerWidth"]) this.headerWidth = obj["headerWidth"];
	
	if (obj["bgColor"]) this.bgColor = obj["bgColor"];
	if (obj["onMouseOverColor"]) this.onMouseOverColor = obj["onMouseOverColor"];
	if (obj["menuWidth"]) this.menuWidth = obj["menuWidth"];
	if (obj["separator"]) this.separator = obj["separator"];
	if (obj["menuAlign"]) this.menuAlign = obj["menuAlign"];
	if (obj["borderColor"]) this.borderColor = obj["borderColor"];
	
	if (obj["items"]) {
		for (var i = 0; i < obj["items"].length; i++) {
			var lnk = obj["items"][i]
			this.addMenuItem(lnk["text"], lnk["href"], lnk["target"]);
		}
	}
	
	this.create();
}

function MenuItem(txt, href, target) {
//--MenuItem Object--
	this.length = 0;
	this.href = href || "javascript:_void()";
	this.childItems = new Array();
	this.text = txt;
	this.id = "idMenuHeader" + _index;
	this.subID = "idMenuItems" + _index;
	this.target = target || "_top";
	
	this.print = _print;
	this.addMenuItem = _addMenuItem;
}

function _addMenuItem(txt, href, target) {
	var _item = new MenuItem(txt, href, target);
	_item.isNS = this.isNS;
	_item.isIE = this.isIE;
	_item.bgColor = this.bgColor;
	_item.width = this.width;
	_item.menuAlign = this.menuAlign;
	_item.onMouseOverColor = this.onMouseOverColor;
	_item.borderColor = this.borderColor;
	_item.headerWidth = this.headerWidth;
	
	this.childItems[this.length++] = _item;
	_index++;
	
	return _item;
}

function _create() {
//--Displays the Menu Item--
	window.document.writeln('<table cellpadding="3" cellspacing="0" border="0"><tr>');
	
	for (var i = 0; i < this.childItems.length; i++) {
		this.childItems[i].print();
		if (this.separator && i < this.childItems.length - 1) {
			if (this.isNS)
				window.document.writeln('<td align="' + this.menuAlign + '"><div class="clsmMenuItemSeparator">' + this.separator + '</div><br></td>');
			else if (this.isIE)
				window.document.writeln('<td align="' + this.menuAlign + '"><div class="clsmMenuItemSeparator">' + this.separator + '</div></td>');
		}
	}
	
	window.document.writeln('</tr></table>');
}

function _print() {
	if (this.isNS) {
		window.document.writeln('<td width="' + this.headerWidth + '" align="' + this.menuAlign + '"><ilayer><div class="clsmMenuItemHeader">');
		window.document.writeln('<a target="' + this.target + '" href="' + this.href + '" onmouseover="_IN_MENUITEM_HEADER=true;show(window.document.layers.' + this.id + ')" onmouseout="_IN_MENUITEM_HEADER=false;_IN_MENUITEM=false;hide()">' + this.text + '</a>');
		window.document.writeln('</div></ilayer>');
		window.document.writeln('<ilayer id="' + this.id + '" clip="0,0">');
		window.document.writeln('<layer z-index="1" id="' + this.subID + '"  onmouseover="_IN_MENUITEM = true" onmouseout="_IN_MENUITEM=false;hide(this)" visibility="hide">');
		window.document.writeln('<body><table cellpadding="0" cellspacing="0" width="' + this.width + '" border="1" bordercolor="' + this.borderColor + '">');
		
		for (var i = 0; i < this.childItems.length; i++) {
			window.document.writeln('<tr><td align="' + this.menuAlign + '" width="' + this.width + '" bgcolor="' + this.bgColor + '"><ilayer><layer width="100%" height="100%" class="clsmMenuItem" onmouseover="this.bgColor=\'' + this.onMouseOverColor + '\'" onmouseout="this.bgColor=\'' + this.bgColor + '\'"><a href="' + this.childItems[i].href + '" target="' + this.childItems[i].target + '">' + this.childItems[i].text + '</a></layer></ilayer></td></tr>');
		}
		window.document.writeln('</body></table></layer></ilayer></td>');
	}
	else if (this.isIE) {
		window.document.writeln('<td width="' + this.headerWidth + '"><div align="' + this.menuAlign + '" class="clsmMenuItemHeader">');
		window.document.writeln('<a target="' + this.target + '" href="' + this.href + '" onmouseover="_IN_MENUITEM_HEADER=true;show(window.' + this.id + ')" onmouseout="_IN_MENUITEM_HEADER=false;_IN_MENUITEM=false;hide()">' + this.text + '</a>');
		window.document.writeln('</div><div onmouseover="_IN_MENUITEM = true" onmouseout="_IN_MENUITEM=false;hide()">');
		window.document.writeln('<div id="' + this.id + '" class="clsIEMenuItemDiv">');
		window.document.writeln('<table cellpadding="0" cellspacing="0" width="' + this.width + '" border="1" bordercolor="' + this.borderColor + '">');
		
		for (var i = 0; i < this.childItems.length; i++) {
			window.document.writeln('<tr><td bgcolor="' + this.bgColor + '"><div width="100%" height="100%" class="clsmMenuItem" onmouseover="this.style.backgroundColor=\'' + this.onMouseOverColor + '\'" onmouseout="this.style.backgroundColor=\'' + this.bgColor + '\'"><a href="' + this.childItems[i].href + '" target="' + this.childItems[i].target + '">' + this.childItems[i].text + '</a></div></td></tr>');
		}
		window.document.writeln('</table></div></div></td>');
	}
}

function show(obj) {
	_hide(true);
	_IN_MENUITEM = true;
	_CURRENT_MENU_ITEM = obj;
	
	if (window.document.layers) {
		obj.clip.width = 800;
		obj.clip.height = 800;
		obj.layers[0].visibility = 'show';
	}
	else{
		_CURRENT_MENU_ITEM.style.display = 'block';
	}
}

function hide() {
	window.setTimeout("_hide()", 100);
}

function _hide(bforce) {
	if (_CURRENT_MENU_ITEM == null) return;
	
	if (window.document.layers) {
		if ((!_IN_MENUITEM && !_IN_MENUITEM_HEADER) || bforce)
			_CURRENT_MENU_ITEM.layers[0].visibility = 'hide';
	}
	else {
		if ((!_IN_MENUITEM && !_IN_MENUITEM_HEADER) || bforce)
			_CURRENT_MENU_ITEM.style.display = 'none';
	}
}

function _void() { }
