var lastMenuId = 0;

var timer;

var mSheets = new Array();

var currZ = 100;

var mReady = false;

var menu_path = new Array();



function setClass(obj, cl){

	if (obj.className!=cl) obj.className = cl;

}



function MenuLink(textVal, linkVal, subVal){

	this.text = textVal;

	this.action = linkVal;

	this.submenu = subVal;

}



function menuHideAll(){

	mSheets.collect(function(mSheetscollect,c) {mSheetscollect.hide()});
	
}



function menuHideTimerSet(){

	timer = window.setTimeout(menuHideAll, 300);

}



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, obj){

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

	this.block.style.top = (topVal+21) + "px";

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

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

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

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

}



function menuHide(){

	this.hideCh();

	this.block.style.display = "none";
	
	this.title.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){

	//if (!mSheets) return;

	var res = "<div class=\"menu-sh\" onmouseout=\"menuHideTimerSet()\" onmouseover=\"menuHideTimerReset()\">";

	var me = this;
	
	var curLink;

	var newPath;
	
	var count=0;

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

	this.links.collect(function(linkscollect,c)
	{
		curLink = linkscollect
		
		if (count==0) 
		{
			if(me.ElTitle == "")
			{

			}
			else
			{
				me.title.innerHTML = "<a href=\""+me.ElTitleUrl+"\" title=\"\"><img src=\""+me.ElTitle+"\" alt=\"\" class=\"tab-menu-sh\" onmouseout=\"menuHideTimerSet()\" onmouseover=\"menuHideTimerReset()\" /></a>";
			}
			res += "<table cellpadding=\"0\" cellspacing=\"0\" class=\"tab-menu-sh\" style=\" border-top: #006dd2 1px solid;\">";			
				
			res += "<tr valign=\"center\"><td><img src=\""+site_url+"images/x.gif\" height=\"6px\" alt=\"\" /></td></tr>";
		}
		
		if (count!=0) 
		{
			res += "<tr valign=\"center\"><td><img src=\""+site_url+"images/menu/d_sep.gif\" alt=\"\" /></td></tr>";
		}
		
		count = 1;
		
		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)-1 + this.offsetWidth, getTopPos(this) - 28,this)";

			curLink.submenu.create_menu(newPath);

		}

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

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

		res += "')\" onclick=\"gotoURL('"+curLink.action+"')\" nowrap=\"nowrap\">" + curLink.text + "</td></tr>";
		
	});
	
	res += "<tr valign=\"center\"><td><img src=\""+site_url+"images/x.gif\" height=\"7px\" alt=\"\" /></td></tr>";

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

	this.block.innerHTML = res;

}



function MenuSheet(parentObj){

	this.links = new Array();

	this.addLink = menuAddLink;

	this.addSubmenu = menuAddSubmenu;
	
	this.ElTitle = "";	
	
	this.ElTitleUrl = "";	

	this.create_menu = 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;
	
	document.body.appendChild(this.block);

	currZ++;

	this.title = document.createElement("DIV");
	
	this.title.id = "ms" + this.id;
	
	this.title = document.createElement("DIV");

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

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

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

	this.title.style.zIndex = currZ;

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

	document.body.appendChild(this.title);
	

}



function showMenu(objVal, numVal){

	

	if (mReady){

		menuHideAll();

		/*objVal.className = "menu_item_selected";

		

		if ( document.getElementById(obj_left) )

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

		

		if ( document.getElementById(obj_right) )

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

		*/

		if ( numVal >= 0 && mSheets[numVal] ) {
			
			if( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) )
			{
				mSheets[numVal].show(getLeftPos(objVal)-12, getTopPos(objVal)+21,objVal);
			}
			else
			{
				mSheets[numVal].show(getLeftPos(objVal)-13, getTopPos(objVal)+21,objVal);
			}
			


			menuHideTimerReset();

		}

	}

}



function hideMenu(objVal, numVal){

	

	if (mReady){

		menuHideTimerSet();

	}

}