var vZone

function init(){ //Written in jquery syntax
	//Used in setZone and to set subdir syntax.

	vZone =  $("body").attr("rel");
	var vSubDir = vZone == "root" ? "" : "../";
	var vShadow = 'url(\"' + vSubDir + 'images/shadow.png\") no-repeat bottom right'; //Don't know why I have to do it this way just because I put the img in a subdir.

////    $("#nav ul a").prepend("&gt;&nbsp;");
//	$(".test_ul_shadow").wrap("<div class='ddshadow'></div>");

	var $mainmenu=$("#nav") //reference main menu UL
	var $submenus = $mainmenu.find("li>ul")
	var $vHeight
 	$submenus.each(function(i){
		if (!($.browser.msie && $.browser.version < 7)){//Turn off the shadow for IE6
			$(this).css({'visibility' : 'visible','display' : 'none', 'background' : vShadow, 'padding' : '0 8px 9px 0', '-moz-border-radius-bottomleft' : '17px', '-moz-border-radius-topright' : '17px', '-webkit-border-top-right-radius' : '17px', '-webkit-border-bottom-left-radius' : '17px'});
		}
		$(this).find('li:last').css({'border-bottom':'1px solid #5086b5','height':'auto'});
		$(this).find('li').css({'border-left':'1px solid #5086b5','border-right':'1px solid #5086b5'});
	}); //end $submenus.each()  


	var oZone; //object container

	if(vZone != "root")
	{//Use 'root' for homepage and any root-level pages for the value of the REL attribute in the BODY tag.
		oZone =  "#" + $("body").attr("rel") + ">a";
		$(oZone).addClass("zone_selected");
	}
	
	//FOR BETA: then delete
	setNavLinkRelativity();

	var d = new Date(); //write in the footer for the copyright year.
	//	$("#c_year").text(d.getFullYear());
}

function basename(path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    return b;
}

function setNavLinkRelativity(){
	var aA = document.getElementById("contentbody").getElementsByTagName("a");
	var vHref
	for(var i = 0; i<aA.length; i++){
		vHref = basename(aA[i].href, ".htm")
		if(vHref == "placeholder"){
			aA[i].onclick = function(){alert("Not linked yet or not yet built."); return false;}
		}
	}
}

function setlateral(){
//FOR THIS TO WORK, the classname of the BODY tag and the name of the htm file MUST BE THE SAME.
	var aA = document.getElementById("ul_tert_nav").getElementsByTagName("a");
	var vPrev, vPrevA; 
	var vCur, vNext, vNextA, filename;
	var vBody = document.getElementsByTagName('body')[0].className; //the page-name base
	var vLevel = $("body").attr("level"); //the page level, used for manipulating the navigation from a tert page to a secondary  page.
	var Prev, PrevA, Next, NextA
	var aLateral = document.getElementById("nav_lateral").getElementsByTagName("a");
	var aLabels = document.getElementById("nav_lateral").getElementsByTagName("span");

	var aLen = aA.length;
	for(var i=0; i<aLen; i++){
		filename = basename(aA[i].href, ".htm");
//alert(filename);		
		if(filename == vBody){//Establish what page is the CURRENT (vCur) page.
//alert(filename);		
			var a, b
			a = i>0 ? i-1 : null; //for PREV 
			b = i==aLen-1 ? null : i+1; //for NEXT
			vCur = aA[i].innerHTML;
			
			if((a>0) || (a != null)){
				vPrevA = basename(aA[a].href);
				vPrev = aA[a].innerHTML;
			
				if(aA[a].className.indexOf("tert_zone")>-1){ //We're on a Secondary-level menu item.
					if(vZone != "infocenter" && vZone != "about"){ //But we're not in the Info Center.
						vPrev = vPrev + " Overview"
					}
				}
	
				aLateral[0].href=vPrevA;
				aLabels[0].innerHTML = vPrev;
			}else{
				aLateral[0].style.display = "none"; //If there is no object for Previous.
				aLabels[1].style.display = "none"; //the separator pipe.
			}
			if(b){
				vNextA = basename(aA[b].href);
				vNext = aA[b].innerHTML; 
			
				if(aA[b].className.indexOf("tert_zone")>-1){ //We're on a Secondary-level menu item.
					if(vZone != "infocenter" && vZone != "about"){ //But we're not in the Info Center.
						vNext = vNext + " Overview"
					}
				}
				aLateral[1].href=vNextA;
				aLabels[4].innerHTML = vNext;
			}else{
				aLateral[1].style.display = "none"; //If there is no object for Next.
				aLabels[3].style.display = "none"; //the separator pipe.
			}
			break;
		}
	}
	if(vLevel == "l_1_1"){vCur = vCur + " Overview";} //This style of level is set like this only in the prodservices zone on subindex pages.
	aLabels[2].innerHTML = vCur;
	
	var tstr;
	
	for(var i=0; i<=4; i++)
	{
		tstr="";
		for(var j=0; j<aLabels[i].innerHTML.length; j++)
		{
			if (aLabels[i].innerHTML.charCodeAt(j)!=8482)
			{
				tstr=tstr+aLabels[i].innerHTML.charAt(j);// to get rid of &trade;
			}	
		}
//alert(tstr);		
		aLabels[i].innerHTML=tstr;
		aLabels[i].innerHTML=aLabels[i].innerHTML.replace(/<br>/i,' ');
                
	}
	return;
//NOTE: 1) We're adding " Overview" to the subindex pages here because we don't want it in the navigation margin.
//		2) The BODY class must be set to the filename base.
}

/*function writeSeconderyNav(){
	//Using the global variable set by init, get the 
	
	var aSecondaryLinks = document.getElementById(vZone).getElementsByTagName("ul")[0].getElementsByTagName('a')
//	var aSecondaryLinks =  $("#"+vZone+" ul a");
	var lSecondaryLinks = aSecondaryLinks.length-1;
	//get tertiary-nav container
	var oTertNavContainer = document.getElementById("ul_tert_nav");
	var oLI, oA, aText, aHref
	for(var i = 0; i<lSecondaryLinks; i++){
		oLI = document.createElement("li");

		oA = document.createElement("a");
		aText = document.createTextNode(aSecondaryLinks[i].innerHTML); //Text for the link.
		aHref = basename(aSecondaryLinks[i].href) //HREF for the link.
		
		oA.setAttribute('href',aHref); //Set the HREF for the new link.
		oA.innerHTML=aText;			//Set the text for the link.
//alert(aText);		
		oLI.className = "li_bottomrule";
		oTertNavContainer.appendChild(oLI); //Add the new link to the UL container.

//		oLI.nodeValue = "<a href='"+basename(aSecondaryLinks[lSecondaryLinks].href)+"'>"+aSecondaryLinks[i].innerHTML +"</a>"
//		$("ul_tert_nav").html("<li class='li_bottomrule'><a href='"+basename(aSecondaryLinks[i].href)+"'>"+ aSecondaryLinks[i].innerHTML +"</a></li>");
	} //End for loop
} //End writeSeconderyNav
*/

var vPage
function cyclehomepages(){
	var numbspons = 10;  //= number+1 of sponsors to rotate
	var randomnumber=Math.floor(Math.random()*numbspons);
	if(randomnumber == 0){randomnumber=1;} 
	if (location.href=="http://www.dbcompensation.com/") {randomnumber=3;}
	vPage = "hp_" + randomnumber + ".htm";
    	document.getElementById("hp_if").src = vPage;
}	

//Overview Notes:
// * the BODY class is must be set to filename base for all pages except level 1.0 index pages. Those are set to "index".
// * the BODY REL attribute is always set to the name of the zone, which is the same as the ID of the zone's LI global-nav label container.
// * The tertiary navigation scheme is different for zones with actual tertiary navigation and those with only Secondary navigation presented in the left-margin. 
