//***********************************************************
// MENU OBJECT
//***********************************************************
function menuObject(oName,nSection){
	this.name				= oName;
	this.section			= nSection;
	this.items				= new Array();
	this.itemCount			= 0;
	this.subMenus			= new Array();
	this.subMenuCount		= 0;
	this.handleMenu			= 0;
	
	this.appendItem			= fnAppendMenuItem;
	this.initialize			= fnInitializeMenuItems;
	
	this.hideMenu			= fnHideMenu;
	this.hideMenuNow		= fnReallyHideMenu;
	this.showMenu			= fnShowMenu;
	
	return this
};
//***********************************************************
function fnAppendMenuItem(oItem){
		if(oItem.dtlevel == 0){
			this.itemCount	= this.items.push(oItem);
			if(oItem.activeInTree){
				ActiveTopMenu = oItem.id_section;
			}
		}else if(oItem.dtlevel > 1){
			oItem = null;
		}else{
			this.subMenuCount	= this.subMenus.push(oItem);
			if(oItem.id_section == this.section){
				this.handleMenu = oItem.id_section_parent;
			};
		};
};
//***********************************************************
function fnInitializeMenuItems(){
	
	var menuHTML = "";
	var arrSbPosInSubMenus	= new Array();
	menuHTML += "<div id='menu_01'>";
	for(var i=0; i<this.itemCount; i++){
		var sbPosInSubMenus	= getSubMenuPos(this.subMenus, this.items[i].id_section);
		if(sbPosInSubMenus!=-1){
			var childSelected = isChildSelected(this.subMenus, this.items[i].id_section, this.section);
			menuHTML += writeTopMenuItem(this, this.items[i], childSelected);
			var mSbCount 	= arrSbPosInSubMenus.push(sbPosInSubMenus);
		}else{
			menuHTML += writeTopMenuHref(this, this.items[i]);
		};
	};
	menuHTML += "</div>\n";
	//alert(menuHTML);
	document.write(menuHTML);
	setActiveTab();
	
	for(var j=0; j<mSbCount; j++){
		var mParent = this.subMenus[arrSbPosInSubMenus[j]].id_section_parent;
		subMenuHTML += '<div id="Left' + mParent + '" name="Left' + mParent + '" class="subDHTMLmenu"  onmousemove="if (CountDownHideMenu) clearTimeout(CountDownHideMenu)"  onmouseout="' + this.name + '.hideMenu()">\n';
		subMenuHTML += '<ul>\n';
		subMenuHTML += writeSubMenuItems(this.subMenus, arrSbPosInSubMenus[j], mParent);
		subMenuHTML += '</ul>\n';
		subMenuHTML += '</div>\n';
	};
};
//***********************************************************
function fnHideMenu(mWhich){
	CountDownHideMenu = setTimeout("fnReallyHideMenu()", 500);
};
//***********************************************************
function fnReallyHideMenu(mWhich){
	if(BlockMenu==0){
		if(!mWhich){mWhich = displayedMenu;};
		if(mWhich != null){
			eval(WhatItUses+'"Left'+mWhich+'"'+useDaOrLa+'.visibility="hidden"');
			//zmena podbarveni ouska podle aktivni sekce stranky
			parentid = 'Left'+mWhich+'Section';
			if ((ActiveTopMenu) != mWhich){
				eval(WhatItUses+'"'+parentid+'"'+useDaOrLa+'.backgroundImage="url(img\/tab_nonactive.gif)"');
			}else{
				eval(WhatItUses+'"'+parentid+'"'+useDaOrLa+'.backgroundImage="url(img\/tab_active.gif)"');
			}
		};
		 displayedMenu = null;
	}
}

//***********************************************************
function fnShowMenu(cnt){
	if (BlockMenu==0){
		if(displayedMenu!=null){
			this.hideMenu(displayedMenu)
		};
		displayedMenu = cnt;
 		whichlayer4setpos = "Left" + cnt;
		parentid = "Left" + cnt + "Section";
		//zmena podbarveni aktivniho ouska
		eval(WhatItUses+'"'+parentid+'"'+useDaOrLa+'.backgroundImage="url(img\/tab_nonactive.gif)"');
		PositionLayer(whichlayer4setpos, parentid);
		eval(WhatItUses+'"Left'+cnt+'"'+useDaOrLa+'.visibility="visible"');
	 };
};

//***********************************************************
// MENU ITEM OBJECT
//***********************************************************
function menuItemObject(id_section, id_section_parent, dtlevel, name, redirurl, isActiveInTree){
	this.id_section			= id_section;
	this.id_section_parent	= id_section_parent;
	this.dtlevel			= dtlevel;
	this.name				= name;
	this.redirurl			= redirurl;
	this.activeInTree		= isActiveInTree;
	return this
};

//***********************************************************
// COMMON FNS FOR MENU OBJECT
//***********************************************************
function fnSortMenuItems(a,b){
	return a.dtlevel < b.dtlevel;
};
//***********************************************************
function getSubMenuPos(oArray, oParent){
	for(var k=0; k<oArray.length; k++){
		if(oArray[k].id_section_parent == oParent){
			return k
		};
	};
	return -1;
};
//***********************************************************
function isChildSelected(oArray, oParent, nSection){
	for(var i = 0; i < oArray.length; i++){
		if(oArray[i].id_section_parent == oParent && oArray[i].id_section == nSection){
			return true;
		};
	};
	return false;
}
//***********************************************************
function writeTopMenuItem(oMenu, oItem, bSelected){
	var oMOver = " onmouseover='" + oMenu.name + ".hideMenuNow();" + oMenu.name + ".showMenu("+ oItem.id_section +");'";
	var oMMove = " onmousemove='if (CountDownHideMenu) clearTimeout(CountDownHideMenu);'";
	var oMOut = " onmouseout='" + oMenu.name + ".hideMenu();'";
	return '<a href="#"' + oMOver + oMOut + oMMove +' onfocus="this.blur()" id="Left' + oItem.id_section + 'Section"  name="Left' + oItem.id_section + 'Section">' + oItem.name + '</a>\n';
};
//***********************************************************
function writeTopMenuHref(oMenu,oItem){
	var cls = "";
	var oMOver = "";
	if (oMenu != null){
		oMOver = " onmouseover='" + oMenu.name + ".hideMenuNow();'";
		if (oMenu.section == oItem.id_section) {
			cls = " class='active_tab'";
		}
	}
	var mHref = " href='" + ((oItem.redirurl!="") ? oItem.redirurl : "/Default.aspx?section=" + oItem.id_section) + "'";
	return '<a' + mHref + cls + ' onfocus="this.blur()"' + oMOver + '>' + oItem.name + '</a>\n';
};
//***********************************************************
function writeSubMenuItems(oItems, oStart, oParent){
	var oTxt = new String();
	for(var l=oStart; l<oItems.length; l++){
		if(oItems[l].id_section_parent == oParent){
			oTxt += '<li>' + writeTopMenuHref(null,oItems[l]) + '</li>\n';
		}else{
			return oTxt;
		};
	};
	return oTxt
};

//***********************************************************
// HANDLER FOR IE 5
//***********************************************************
if (Array.prototype && !Array.prototype.push) {
	Array.prototype.push = function() {
		for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
		return this.length;
	};
};

//***********************************************************
// GLOBAL FUNCTIONS AND PROPERTIES
//***********************************************************
	var subMenuHTML 		= new String();
	var BlockMenu			= 1;
	var displayedMenu		= null;
	var CountDownHideMenu	= null;
	var ActiveTopMenu		= 0;

	function PositionLayer(whichlayer4setpos, parentid)
	{ 
		 if (ie5 || ns6)
		 
		 {
		 	tl3x = mm_ElementX3rdgenbrowser(parentid)
	 		eval('document.getElementById("'+whichlayer4setpos+'").style.left='+tl3x+';');
			tl3y = mm_ElementY3rdgenbrowser(parentid) 
			tlhobj = document.getElementById(parentid)
			tl3y1 = tl3y + tlhobj.offsetHeight - 5
	 		eval('document.getElementById("'+whichlayer4setpos+'").style.top='+tl3y1+' ;');
		 }
		 
		 else
		 
		 {
		 	 eval(whichlayer4setpos+'.style.left=mm_ElementX('+parentid+');');
			 eval(whichlayer4setpos+'.style.top=mm_ElementY('+parentid+') + '+parentid+'.offsetHeight - 5;')
		 }	 
		 
	} 
	
	//pro starsi prohlizece
	function mm_ElementX(o)
	{var x = 0; do x += o.offsetLeft; while ((o = o.offsetParent)); return x;}
	//pro starsi prohlizece 
	function mm_ElementY(o)
	{var y = 0; do y += o.offsetTop; while ((o = o.offsetParent)); return y;}
	
	//pro nove prohlizece
	function mm_ElementX3rdgenbrowser(o)
	{var x = 0; var hlpobjX3 = 0;
	hlpobjX3 = document.getElementById(o)
	do x += hlpobjX3.offsetLeft;
    while ((hlpobjX3 = hlpobjX3.offsetParent));
	return x;}

	//pro nove prohlizece 
	function mm_ElementY3rdgenbrowser(o)
	{var y = 0; var hlpobjY3 = 0; 
	hlpobjY3 = document.getElementById(o)
	do y += hlpobjY3.offsetTop;
	while ((hlpobjY3 = hlpobjY3.offsetParent));
	return y;}

//***********************************************************
	function setActiveTab(){
		if (ActiveTopMenu != 0) {
			parentid = 'Left'+ActiveTopMenu+'Section';
			if(document.getElementById(parentid) || document.all[parentid]){
				eval(WhatItUses+'"'+parentid+'"'+useDaOrLa+'.backgroundImage="url(img\/tab_active.gif)"');
			}
		}	
	}

