//***********************************************************
// MENU OBJECT
//***********************************************************
function menuObject(oName){
	this.name				= oName;
	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			= fnHideMenuNow;
	this.showMenu			= fnShowMenu;
	
	return this
};
//***********************************************************
function fnAppendMenuItem(oItem){
		if(oItem.dtlevel==0){
			this.itemCount	= this.items.push(oItem);
		}else{
			this.subMenuCount	= this.subMenus.push(oItem);
			if(oItem.id_section==this.section){
				this.handleMenu = oItem.id_section_parent;
			};
		};
};
//***********************************************************
function fnInitializeMenuItems(){
	
	//this.subMenus.sort(fnSortMenuItems);
	var debug = new String();
	var arrSbPosInSubMenus	= new Array();
	debug += "<ul class='menu_01'>";
	for(var i=0; i<this.itemCount; i++){
		var sbPosInSubMenus	= getSubMenuPos(this.subMenus, this.items[i].id_section);
		if(sbPosInSubMenus!=-1){
			debug += "<li>" + writeTopMenuItem(this.name, this.items[i].name, this.items[i].id_section) + "</li>\n";
			var mSbCount 	= arrSbPosInSubMenus.push(sbPosInSubMenus);
		}else{
			debug += "<li>" + writeTopMenuHref(this.items[i], this.name) + "</li>\n";
		};
	};
	debug += "</ul>\n";
	document.write(debug);
	//alert(debug);
	debug = "";
	for(var j=0; j<mSbCount; j++){
		var mParent = this.subMenus[arrSbPosInSubMenus[j]].id_section_parent;
		debug += '<style type="text/css">#Left' + mParent + '{position: absolute; visibility: hidden; top:0px; left:0px;}</style>\n';
		debug += '<div id="Left' + mParent + '" name="Left' + mParent + '" class="submenu" onmouseover="'+this.name+'.showMenu('+mParent+')" onmouseout="'+this.name+'.hideMenu()">\n';
		//debug += '<div align="right"><img src="img/submenu_top.gif" alt="" width="150" height="6" border="0"></div>\n';
		debug += '<nobr>\n';
		debug += '<ul class="submenu_01">\n';
		debug += writeSubMenuItems(this.subMenus, arrSbPosInSubMenus[j], mParent);
		debug += '</ul>\n';
		debug += '</nobr>\n';
		debug += '</div>\n';
	};
	document.write(debug);
	//alert(debug);
	BlockMenu = 0;
};
//***********************************************************
function fnHideMenu(mWhich){
	if (mWhich!=null)
		CountDownHideMenu = setTimeout("fnHideMenuNow(mWhich)", TimeOutToHide);
	else
		CountDownHideMenu = setTimeout("fnHideMenuNow()", TimeOutToHide);
		
}
//***********************************************************
function fnHideMenuNow(mWhich){
	if(BlockMenu==0){
		if(mWhich==null){mWhich = displayedMenu;};
		if(mWhich!=null){eval(WhatItUses+'"Left'+mWhich+'"'+useDaOrLa+'.visibility="hidden"');};
		displayedMenu = null;
	};
}
//***********************************************************
function fnShowMenu(cnt){
	if (BlockMenu==0){
		if (CountDownHideMenu) clearTimeout(CountDownHideMenu);
		if(displayedMenu!=null){this.hideMenuNow(displayedMenu)};
		displayedMenu = cnt;
 		whichlayer4setpos = "Left" + cnt;
		parentid = "Left" + cnt + "Section";
		PositionLayer(whichlayer4setpos, parentid);
		eval(WhatItUses+'"Left'+cnt+'"'+useDaOrLa+'.visibility="visible"');
	 };
};

//***********************************************************
// MENU ITEM OBJECT
//***********************************************************
function menuItemObject(id_section, id_section_parent, dtlevel, name, redirurl){
	this.id_section			= id_section;
	this.id_section_parent	= id_section_parent;
	this.dtlevel			= dtlevel;
	this.name				= name;
	this.redirurl			= redirurl;
	
	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 writeTopMenuItem(oMenuName, oItemName, cnt){
	var oMOver = " onmouseover='" + oMenuName + ".hideMenuNow();" + oMenuName + ".showMenu(" + cnt + ");'";
	var oMOut = " onmouseout='" + oMenuName + ".hideMenu()'";
	return '<a href="#" onfocus="this.blur()"' + oMOver + oMOut + '" id="Left' + cnt + 'Section"  name="Left' + cnt + 'Section">' + oItemName + '</a>';
};
//***********************************************************
function writeTopMenuHref(oItemObject, oItemName){
	var oMOver = (oItemName==null) ? "" : " onmouseover='" + oItemName + ".hideMenuNow();'";
	var oMOut = (oItemName==null) ? "" : " onmouseout='" + oItemName + ".hideMenu()'";
	var mHref = (oItemObject.redirurl!="") ? oItemObject.redirurl : "/?section=" + oItemObject.id_section;
	return '<a href="' + mHref + '" onfocus="this.blur()"' + oMOver + oMOut + '>' + oItemObject.name + '</a>';
};
//***********************************************************
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(oItems[l], null) + '</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;
	};
};

//***********************************************************
// COMMON
//***********************************************************
var BlockMenu			= 1;
var displayedMenu		= null;
var leftSubmenuPosition	= 190;
var CountDownHideMenu;
var TimeOutToHide = 500;
var HOffsetLineSubmenu = 5;
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);
var WhatItUses = "document.all["; 
var useDaOrLa = "].style";
if(navigator.appName == "Microsoft Internet Explorer"){
	var strVerze = navigator.appVersion; 
	var index = strVerze.indexOf("MSIE"); 
	var MajorVersion = strVerze.substring(index+5,index+8); 
	if(MajorVersion>5){var ie = 55;};
};
if (ie5 || ns6 || (navigator.userAgent.indexOf("Opera") > -1)) {
	WhatItUses="document.getElementById("; 
	useDaOrLa=").style";
}
function PositionLayer(whichlayer4setpos, parentid){
	if (ie5 || ns6){
		el = document.getElementById(whichlayer4setpos);
		tlhobj = document.getElementById(parentid)
		tl3x = mm_ElementX3rdgenbrowser(parentid) 
		tl3x1 = tl3x + leftSubmenuPosition;
		eval('document.getElementById("'+whichlayer4setpos+'").style.left='+(tl3x1)+';');
		tl3y = mm_ElementY3rdgenbrowser(parentid) 
		tl3y1 = (tl3y+HOffsetLineSubmenu+el.offsetHeight<document.body.clientHeight+document.body.scrollTop)? tl3y+HOffsetLineSubmenu : tl3y-el.offsetHeight+tlhobj.offsetHeight-HOffsetLineSubmenu;
	 	eval('document.getElementById("'+whichlayer4setpos+'").style.top='+(tl3y1)+' ;');
	}
	else {
		eval(whichlayer4setpos+'.style.left='+leftSubmenuPosition)
		eval(whichlayer4setpos+'.style.top=mm_ElementY('+parentid+') + '+parentid+'.offsetHeight -1;')
 	}
} 

//pro starsi prohlizece 
function mm_ElementY(o){
	var y = 0; 
	do y += o.offsetTop; while ((o = o.offsetParent)); 
	return y;
}
function mm_ElementX(o){
	var x = 0; 
	do x += o.offsetLeft; while ((o = o.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 mm_ElementX3rdgenbrowser(o){
	var x = 0; 
	var hlpobjX3 = 0; 
	hlpobjX3 = document.getElementById(o)
	do x += hlpobjX3.offsetLeft; while ((hlpobjX3 = hlpobjX3.offsetParent));
	return x;
}
