/*	$Revision: 1.11 $ */
(function(){
	var A={maxTabs:5,init:function()
	{
		var C=document.getElementById("pbs-home-tasks"),
		D=[],
		G=0,
		B=[],
		F,
		E=document.getElementById("pbs-home-task-nav");
		for(G=0;G<A.maxTabs;G++){
			F=document.getElementById("pbs-tab-content-"+G);
			if(F!==null)
			{
				B[B.length]=F
			}
		}
		A.tabs=E.getElementsByTagName("li");
		for(G=0;G<A.tabs.length;G++){
			if(G===0)
			{
				A.tabs.item(G).isFirst=true
			}
			else
			{
				if(G===(A.tabs.length-1))
				{
					A.tabs.item(G).isLast=true
				}
			}
		}
		for(G=0;G<B.length;G++){
			if(B[G].nodeName.toLowerCase()==="div")
			{
				D[D.length]=B[G]
			}
		}
		for(G=1;G<D.length;G++)
		{
			D[G].style.display="none"
		}
		B=jQuery("div.pbs-tab-content-submenu",C).get();
		for(G=0;G<B.length;G++)
		{
			A.setMenuStyles(B[G])
		}
		A.restoreActiveTabFromCookie()
	},
	setMenuStyles:function()
	{
		if(arguments.length<1)
		{
			return 
		}
		var B=arguments[0];
		B.style.backgroundColor="#FFFFFF";
		B.style.border="#CCC solid 1px";
		B.style.display="none";
		B.style.position="absolute";
		B.style.width="208px";
		B.style.zIndex="9"
	},
	deactivateAll:function()
	{
		var D=document.getElementById("pbs-home-tasks"),
		E,
		F;
		if(D===null)
		{
			return 
		}
		var C=jQuery("div.pbs-active",D).get();
		var B=C.length;
		for(E=0;E<B;E++)
		{
			F=C[E];
			pbsCommon.deleteClassName(F,"pbs-active");
			if(F.nodeName.toLowerCase()==="div")
			{
				F.style.display="none"
			}
		}
		B=A.tabs.length;
		for(E=0;E<B;E++)
		{
			F=A.tabs[E];
			if(F.isFirst)
			{
				F.className="pbs-first-tab"
			}
			else
			{
				if(F.isLast)
				{
					F.className="pbs-last-tab"
				}
				else
				{
					F.className=""
				}
			}
		}
	},
	focusContent:function(G)
	{
		var E=document.getElementById(G);
		var C=jQuery("a.pbs-access",E).get();
		var B=C.length;
		for(var D=0;D<B;D++)
		{
			var F=C[D];
			if(F.nodeName.toLowerCase()==="a")
			{
				F.focus();
				return 
			}
		}
	},
	setActive:function(D,F)
	{
		var C=null,
		E="",
		B=D.parentNode;
		A.deactivateAll();
		E=B.nodeName.toLowerCase();
		while(E!=="li"&&E!=="body"&&E!=="html")
		{
			B=B.parentNode
		}
		if(B.isFirst)
		{
			B.className="pbs-active-first-tab"
		}
		else
		{
			if(B.isLast)
			{
				B.className="pbs-active-last-tab"
			}
			else
			{
				B.className="pbs-active"
			}
		}
		A.setActivePrevious(B);
		A.setActiveNext(B);
		C=document.getElementById(F);
		C.className+=" pbs-active";
		C.style.display="block";
		A.focusContent(F);
		if(B.id)
		{
			A.setLastTabCookie(B.id)
		}
	},
	setActiveNext:function(C)
	{
		var B=A.getNextTab(C);
		if(B===null)
		{
			return 
		}
		if(B.isLast)
		{
			B.className="pbs-active-next-last-tab"
		}
		else
		{
			B.className="pbs-active-next-tab"
		}
	},
	setActivePrevious:function(C)
	{
		var B=A.getPreviousTab(C);
		if(B===null)
		{
			return 
		}
		if(B.isFirst)
		{
			B.className="pbs-active-first-previous-tab"
		}
		else
		{
			B.className="pbs-active-previous-tab"
		}
	},
	delay:400,
	delayedSetActive:function(B,C)
	{
		B._timerId=window.setTimeout(function(){A.setActive(B,C)},A.delay)
	},
	cancelSetActive:function(B)
	{
		if(B._timerId)
		{
			window.clearTimeout(B._timerId)
		}
		B._timerId=null
	},
	delayedHideHPT:function(C)
	{
		if(!pbsCommon.isDOM)
		{
			return
		}
		var B=document.getElementById(C);
		if(B===null)
		{
			return 
		}
		B._timerId=window.setTimeout(function(){A.hideHPT(C)},A.delay)
	},
	getNextTab:function(C)
	{
		if(typeof C.nextSibling==="undefined")
		{
			return null
		}
		var B=C.nextSibling;
		while(B!==null)
		{
			if(B.nodeName.toLowerCase()==="li")
			{
				return B
			}
			B=B.nextSibling
		}
		return null
	},
	getPreviousTab:function(C)
	{
		if(typeof C.previousSibling==="undefined")
		{
			return null
		}
		var B=C.previousSibling;
		while(B!==null){
			if(B.nodeName.toLowerCase()==="li")
			{
				return B
			}
			B=B.previousSibling
		}
		return null
	},
	getX:function(C)
	{
		var B=0;
		if(C.offsetParent)
		{
			while(C.offsetParent){
				B+=C.offsetLeft;
				C=C.offsetParent
			}
		}
		else
		{
			if(C.x)
			{
				B+=C.x
			}
		}
		return B
	},
	getY:function(B)
	{
		var C=0;
		if(B.offsetParent)
		{
			while(B.offsetParent){
				C+=B.offsetTop;
				B=B.offsetParent
			}
		}
		else
		{
			if(B.y)
			{
				C+=B.y
			}
		}
		return C
	},
	hideAllHPT:function()
	{
		if(A.hptCache===null)
		{
			A.hptCache=jQuery("div.pbs-tab-content-submenu",document.documentElement).get()
		}
		for(var B=0;B<A.hptCache.length;B++)
		{
			A.delayedHideHPT(A.hptCache[B].id)
		}
	},
	hideHPT:function(C)
	{
		if(!pbsCommon.isDOM)
		{
			return 
		}
		var B=document.getElementById(C);
		if(B===null)
		{
			return 
		}
		B.style.display="none";
		if(B._timerId)
		{
		    B._timerId=null
		}
	},
	setPosition:function(D)
	{
	    if(!D._triggerId)
	    {
	        return 
	    }
	    var C=document.getElementById(D._triggerId);
	    var B=A.getX(C);
	    var E=A.getY(C);
	    D.style.top=(E-D.offsetHeight+18)+"px";
	    if(pbsCommon.meta.cc=="il")
	    {
	        D.style.left=(B-D.offsetWidth)+"px"
	    }
	    else
	    {
	        D.style.left=(B+C.offsetWidth)+"px"
	    }
	},
	showHPT:function(B,E)
	{
	    if(!pbsCommon.isDOM)
	    {
	        return 
	    }
	    var D=document.getElementById(E);
	    if(D===null)
	    {
	        return 
	    }
	    var C=D.getElementsByTagName("a");
        if(C.length<1)
        {
            window.location=B.getAttribute("href");
            return 
        }
        if(D._timerId)
        {
            window.clearTimeout(D._timerId);
            D._timerId=null
        }
        if(B!==null)
        {
            if(!B.id||B.id===""||B.id===null)
            {
                B.id=pbsCommon.generateId()
            }
            D._triggerId=B.id}D.style.display="block";
            A.setPosition(D)
        },
        hptCache:null,
        hideSubmenuMarker:function()
        {
            var D=document.getElementById("pbs-interest-dd1");
            if(D===null)
            {
                return 
            }
            var C=D.getElementsByTagName("a");
            if(C.length>0)
            {
                return 
            }
            var B=document.getElementById("pbs-interest-dd1-trigger");
            B.className=B.className.replace(/pbs-tab-content-submenu-trigger/,"")
        },
        cancelDelayedHideHPT:function(C)
        {
            if(!pbsCommon.isDOM)
            {
                return 
            }
            var B=document.getElementById(C);
            if(B&&B._timerId)
            {
                window.clearTimeout(B._timerId)
            }
        },
        showAccountsTab:function()
        {
            var C,B;
            if(typeof window.SA_Message!=="string")
            {
                return 
            }
            C=window.SA_Message.replace(/audience=/,"");
            if(C.indexOf("all")!==0&&C.indexOf("pbs")!==0)
            {
                B=jQuery("li#pbs-home-tab-my-pbs > a:first");
                if(B.length<1)
                {
                    return 
                }
                if(!A.restoreActiveTabFromCookie())
                {
                    A.setActive(B.get(0),B.attr("href").replace(/#/,""))
                }
            }
        },
        getLastTabCookie:function()
        {
            var E=-1,B="",
            D=document.cookie,
            C=0,F="hplasttab=";
            E=D.indexOf(F);
            if(E<0)
            {
                return null
            }
            C=E+F.length;
            B=D.substring(C).replace(/;.*$/,"");
            return decodeURIComponent(B)
        },
        restoreActiveTabFromCookie:function()
        {
            var C,B,D=A.getLastTabCookie();
            if(D!==null)
            {
                B=document.getElementById(D);
                if(B!==null)
                {
                    C=B.getElementsByTagName("a");
                    if(C.length>0)
                    {
                        C=C.item(0);
                        D=C.getAttribute("href").replace(/^[^#]*#+/,"");
                        A.setActive(C,D);
                        return true
                    }
                }
            }
            return false
        },
        setLastTabCookie:function(C)
        {
            try
            {
                if(document.cookie.split(";").length<17||document.cookie.indexOf("hplasttab=")!=-1)
                {
                    document.cookie="hplasttab="+encodeURIComponent(C)
                }
            }
            catch(B){}
        }
    };
    window.pbsHomePageTabs=A;
    window.pbsHomePageTabs=A
})();