//DD Tab Menu- Last updated April 27th, 07: http://www.dynamicdrive.com
//Only 1 configuration variable below

var tabmenu={
	currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/)

definemenu:function(tabid, dselected, context){
	this[tabid+"-menuitems"]=null
	this.addEvent(window, function(){tabmenu.init(tabid, dselected, context)}, "load")
},

showsubmenu:function(tabid, targetitem){
	 
	var menuitems=this[tabid+"-menuitems"]
	for (i=0; i<menuitems.length; i++){
		menuitems[i].className=""
		menuitems[i].style.color= ""
		menuitems[i].style.backgroundColor=""
		if (typeof menuitems[i].hasSubContent!="undefined") {
             
			document.getElementById(menuitems[i].getAttribute("rel")).style.display="none"
		}
	}
	targetitem.className="current"
	targetitem.style.color= "#ffffff"
	targetitem.style.backgroundColor= "#" + targetitem.getAttribute("rel").substr(4)
	if (typeof targetitem.hasSubContent!="undefined")
		document.getElementById(targetitem.getAttribute("rel")).style.display="block"
},

isSelected:function(anch, menuurl, context){
 

 
	if(window.location.href==menuurl ) {
		//alert('tutaj');
      return true;
	}  
// alert(anch);
var href = window.location.href;

var lastIdx =menuurl.lastIndexOf("/"); 
menuurl = menuurl.substr(0, lastIdx);
lastIdx =menuurl.lastIndexOf("/"); 
menuurl = menuurl.substr(0, lastIdx);
 

lastIdx =href.lastIndexOf("/"); 
href = href.substr(0, lastIdx);
lastIdx =href.lastIndexOf("/"); 
href = href.substr(0, lastIdx);
if(href==menuurl&&anch.className!="orphan") {

  return true;
} {
  return false;
}
 
//kolejny poziom

//alert("zakladka = "+menuurl + " adres = "+href);



//	return (window.location.href==menuurl )
 
	menuurl=menuurl.replace("http://"+window.location.host, "").replace(/^\//, "")
	menuurl=menuurl.substr(menuurl.indexOf("#") + 1)
 
// alert(menuurl);

	menuurl = menuurl.replace(/(:\d+)/, "")
    if (menuurl.charAt(0) != "/") {
       menuurl = "/" + menuurl
    }
	var context= "Microportals";
	menuurl = menuurl.replace(context + "/", "")
		//alert(menuurl);
//	menuurl = menuurl.substr(0, menuurl.indexOf("/"))
		//alert("2:"+menuurl);

	url = tabmenu.currentpageurl.replace(/(:\d+)/, "")
    if (url.charAt(0) != "/") {
       url = "/" + url
    }
	url = url.replace(context + "/", "")
	url = url.substr(0, url.indexOf("/"))
 
 
	return (url==menuurl)
},

addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
},

init:function(tabid, dselected, context){
 
	var menuitems=document.getElementById(tabid).getElementsByTagName("a")
	this[tabid+"-menuitems"]=menuitems
	for (var x=0; x<menuitems.length; x++){

		if (menuitems[x].getAttribute("rel") && menuitems[x].getAttribute("rel").substr(0, 1) == "s"){
			this[tabid+"-menuitems"][x].hasSubContent=true
			//	alert(menuitems[x].innerHTML);
			//menuitems[x].onclick=function(){tabmenu.showsubmenu(tabid, this);this.style.backgroundColor= "#" + this.getAttribute("rel").substr(4);return false;}
		}
		else //for items without a submenu, add onMouseout effect

			menuitems[x].onmouseout=function(){this.className=""}
		menuitems[x].onmouseover=function(){this.style.backgroundColor= "#" + this.getAttribute("rel").substr(4)}
		menuitems[x].onmouseout=function(){if (this.className!="current") this.style.backgroundColor=""}
		//alert("bez sub = "+menuitems[x].href+ " isSelected="+this.isSelected(menuitems[x].href, context));
		if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[x], menuitems[x].href, context)){
			tabmenu.showsubmenu(tabid, menuitems[x])
			var setalready=true
		}
		else if (parseInt(dselected)==x) {
			tabmenu.showsubmenu(tabid, menuitems[x])
			setalready=true
		}
	}
	if (typeof setalready=="undefined") {
		tabmenu.showsubmenu(tabid, menuitems[0])
	}
}
}
