function findPos(el){
    x=0; y=0; var el,temp
    //el = document.all?document.all["rssimg"]:document.getElementById("rssimg");
    if(el.offsetParent){
      temp = el
      while(temp.offsetParent){ //Looping parent elements to get the offset of them as well
        temp=temp.offsetParent;
        x+=temp.offsetLeft
        y+=temp.offsetTop;
      }
    }
    x+=el.offsetLeft
    y+=el.offsetTop

  //Returning the x and y as an array
  return [x,y]
}

var dolphintabs={
	subcontainers:[], last_accessed_tab:null,

	revealsubmenu:function(curtabref){
	this.hideallsubs()
	if (this.last_accessed_tab!=null)
		this.last_accessed_tab.className=""
	if (curtabref.getAttribute("rel")) //If there's a sub menu defined for this tab item, show it
	document.getElementById(curtabref.getAttribute("rel")).style.display="block"
	
	var mainMenuObj = document.getElementById('dolphinnav');
	var parentWidth = mainMenuObj.offsetWidth;
	var subMenu	= document.getElementById(curtabref.getAttribute("rel"))
	
	var pos = findPos(curtabref);
	
	
	if(pos[0] == 0)
		pos[0] = 248;
	
	remPos = parentWidth - pos[0];
	
	if(pos[0]>450){
		leftPos = pos[0];	// - 220;
		leftPos = leftPos - (subMenu.offsetWidth - remPos) + subMenu.offsetLeft;
	}	
	else
		leftPos = pos[0] - 120;
		
	
	/*
	if(subMenu.offsetWidth > remPos){
		leftPos = leftPos - (subMenu.offsetWidth - remPos) + subMenu.offsetLeft;
	}	
	*/
	
	
	if(leftPos > 0 )
		subMenu.style.paddingLeft = leftPos + "px";
	
	curtabref.className="current"
	this.last_accessed_tab=curtabref
	},

	hideallsubs:function(){
	for (var i=0; i<this.subcontainers.length; i++)
		document.getElementById(this.subcontainers[i]).style.display="none"
	},


	init:function(menuId, selectedIndex){
	var tabItems=document.getElementById(menuId).getElementsByTagName("a")
		for (var i=0; i<tabItems.length; i++){
			if (tabItems[i].getAttribute("rel"))
				this.subcontainers[this.subcontainers.length]=tabItems[i].getAttribute("rel") //store id of submenu div of tab menu item
			if (i==selectedIndex){ //if this tab item should be selected by default
				tabItems[i].className="current"
				this.revealsubmenu(tabItems[i])
			}
			
		tabItems[i].onmouseover=function(){
		dolphintabs.revealsubmenu(this)
		}
		} //END FOR LOOP
	}

}