$("#newNav").ready(function() { 
	
	$eqIndex=0;
	
	$("#newNav a").each(function(){
		
		$(this).attr("rel",$eqIndex); $eqIndex++;
		
	});
	
	if($("#ubuntuFirefox").length>0) { 
	
		$("#searchform #s").css({
			
			marginLeft: "-32px"
			
		});
		
		$("#searchform .submit").eq(0).css({
			
			marginLeft: "-16px",
			marginTop: "-24px"
			
		});
	
	}

	// Set current nav, dependent on the URL (for Phone, Carrier, etc. pages)
	
	if ($(".currentNavItem").length==0) {
		
		if($("#forumPage").length<1) {
			
			currentHREF=document.location.href.split("/");		
			if(currentHREF[3]=="category") { currentPage=currentHREF[4]; } else { currentPage=currentHREF[3]; }
			
		} else { currentPage="forum"; }
	
			switch(currentPage) {
		
				case "carriers":
					setCurrentTab(1);
					$("body").attr("rel","1");
				break;
				case "phones":
					setCurrentTab(2);
					$("body").attr("rel","2");
				break;
				case "tablets":
					setCurrentTab(3);
					$("body").attr("rel","2");
				break;
				case "contact":
					setCurrentTab(6);
					$("body").attr("rel","5");
				break;
				case "forum":
					setCurrentTab(5);
					$("body").attr("rel","4");
					break;
				default:
					setCurrentTab(0);
					$("body").attr("rel","0");
		
			}
		
	} else {
		
			if($(".currentNavItem").attr("rel")==4) {
	
				setCurrentTab(4);
				$("body").attr("rel","4");
	
			}
		
		}
	
	$("body").attr("rel",($("#newNav a.currentNavItem").attr("rel")));
	$("#temp_Content").attr("rel",($("body").attr("rel")));
	
	$("#newNav a").hover(
		function () {
			
			setCurrentTab($(this).attr("rel"));
			$("#temp_Content").attr("rel",$(this).attr("rel"));
			
		}
	);
	
	$("#allNavs").hover(function(){},function(){
			
		setCurrentTab($("body").attr("rel"));
		$("#temp_Content").attr("rel",$("body").attr("rel"));
		
	});
	
	$("#searchBox").click(function() {
		
		$(this).css({
	
			color: "#000",
			fontStyle: "normal"
					
		}).attr("value","");
										  
	});
	
	$("#newSubNav").hover(function(){
		
		setCurrentTab($("#temp_Content").attr("rel"));
										 
	});
	
	$(".tborder tr:odd").addClass("tcatOddRow");
		
	if($(".tborder").length) {
								 
		$theseAnchors="";
	
		$(".tNavBar").children("td").children("a").each(function(){
		
			$theseAnchors+="<li><a href=\""+$(this).attr("href")+"\">"+$(this).html()+"</a></li>";
														   
		});
		
		$("#newSubNav ul").eq(7).html($theseAnchors);
		
	}

});

function setCurrentTab(currentTab) {
	
	// Remove all remnants of the current tab definition.	
	$("#newNav a").each(function(){
		$(this).removeClass("currentNavItem").css({
			color: "#fff",
			background: "none"
		}).children("span").each(function(){ $(this).remove(); });
	});
	
	// Lock the current tab into an object and give it the appropriate class.
	theAnchor=$("#newNav a").eq(currentTab);	
	theAnchor.addClass("currentNavItem");
	
	// Hide current sub nav and show appropriate one (currentTab)	
	$("#newSubNav ul").css("display","none");			
	$("#newSubNav ul").eq(currentTab).css("display","block");
	
	// If they're using Internet Explorer, add a little round corner fix.  (the styles are in the newnav.css stylesheet)
	if($.browser.msie){ theAnchor.prepend("<span class='ieFixes'><span class='ieFixTL' style='width:"+theAnchor.width()+"px'></span><span class='ieFixTR' style='margin-left: "+(theAnchor.width()+12)+"px'></span></span>"); }
	
}
