var lastMenuId = 0;

var timer;

var mSheets = new Array();

var currZ = 100;

var mReady = false;

var mLeftPos = 326;





function MenuLink(textVal, linkVal, subVal){

	this.text = textVal;

	this.action = linkVal;

	this.submenu = subVal;

}



function menuHideAll(){

	for (var c in mSheets) mSheets[c].hide();

}



function menuHideTimerSet(){

	timer = window.setTimeout(menuHideAll, 100);

}



function menuHideTimerReset(){

	if (timer) window.clearTimeout(timer);

}



function menuAddLink(textVal, linkVal){

	this.links[this.links.length] = new MenuLink(textVal, linkVal, null);

}



function menuAddSubmenu(textVal, linkVal){

	this.links[this.links.length] = new MenuLink(textVal, linkVal, new MenuSheet(this));

}



function menuShow(leftVal, topVal){

	this.block.style.left = leftVal + "px";

	this.block.style.top = topVal + "px";

	this.block.style.display = "block";

}



function menuHide(){

	this.hideCh();

	this.block.style.display = "none";

}



function menuFlip(leftVal, topVal){

	var disp = this.block.style.display;

	if (disp == "none") this.show(leftVal, topVal);

	else this.hide();

}



function menuHideCh(){

	for (var c in this.links){

		curLink = this.links[c];

		if (curLink.submenu) curLink.submenu.hide();

	}

}



function menuCreate(path){

	var res = "<div class=\"menu-sh\" onmouseout=\"menuHideTimerSet()\" onmouseover=\"menuHideTimerReset()\"><table cellpadding=\"0\" cellspacing=\"0\" class=\"tab-menu-sh\">";

	var curLink;

	var newPath;

	if (path == null) path = "mSheets[" + this.id + "]";

	for (var c in this.links){

		curLink = this.links[c];

		res += "<tr valign=\"center\"><td class=\"blk-menu-sh";

		if (curLink.submenu) res += " blk-menu-arr";

		res += "\" onmouseover=\"setClass(this, 'blk-menu-sh-act";

		if (curLink.submenu) res += " blk-menu-arr-act";

		res += "'); ";

		res += path + ".hideCh()";

		if (curLink.submenu){

			newPath = path + ".links[" + c + "].submenu";

			res += "; " + newPath + ".show(getLeftPos(this) + this.offsetWidth, getTopPos(this) - 2)";

			curLink.submenu.create(newPath);

		}

		res += "\" onmouseout=\"setClass(this, 'blk-menu-sh";

		if (curLink.submenu) res += " blk-menu-arr";

		res += "')\" onclick=\"gotoURL('"+curLink.action+"')\" nowrap=\"nowrap\"><div style=\"background: url('images/dd_menu_arr.gif') no-repeat top left; padding-left: 6px; padding-top: 3px; padding-bottom: 3px\">" + curLink.text + "</div></td></tr>";

	}

	res += "</table></div>";

	this.block.innerHTML = res;

	//this.block.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";

}



function MenuSheet(parentObj){

	this.links = new Array();

	this.addLink = menuAddLink;

	this.addSubmenu = menuAddSubmenu;

	this.create = menuCreate;

	this.show = menuShow;

	this.hide = menuHide;

	this.flip = menuFlip;

	this.hideCh = menuHideCh;

	this.id = lastMenuId;

	lastMenuId++;

	this.parent = parentObj; 

	this.block = document.createElement("DIV");

	this.block.className = "blk-menu";

	this.block.style.position = "absolute";

	this.block.style.display = "none";

	this.block.style.zIndex = currZ;

	currZ++;

	this.block.id = "ms" + this.id;

	document.body.appendChild(this.block);

}



function showMenu(objVal, numVal, obj_left, obj_right){

	if (mReady){

		menuHideAll();

		objVal.className = "item act";

		/*

			Start: Search unfocus

		*/

		var search = document.getElementById("search_string");

		if (search != null)

		{

			search.blur();

		}

		/*

			End: Search unfocus

		*/

		document.getElementById(obj_left).className='sep light';

		document.getElementById(obj_right).className='sep light';

		if ( numVal >= 0 ) {

			mSheets[numVal].show(getLeftPos(objVal)-3, getTopPos(objVal)+21);

			menuHideTimerReset();

		}

	}

}



function hideMenu(objVal, numVal, obj_left, obj_right){

	if (mReady){

		menuHideTimerSet();

		document.getElementById(obj_left).className='sep';

		document.getElementById(obj_right).className='sep';

		objVal.className = "item";

	}

}
