$(document).ready(function(){
	//Tabs
	$(".tabs a").bind("click", function(){
		tabSwitch(parseInt($(this).attr("href").substring(1)),$(this).parent().parent().attr("class"));
		return false;
	});
	
	//DL Stuff 
	dlNumTabs = $(".tabContainer").size(); //Checks how many tabs there are
	dlToggle();
	$("ul#dlNav a").bind("click", function(){ //binds functions to dl nav
		if($(this).attr("href")=="#toggle"){
			dlToggle();
		} else {
			if(dlRunning) dlToggle();
			dlCycle($(this).attr("href").substring(1));
		}
		return false;
	});
	document.onkeydown = arrowSwitch;
	document.onkeyup = arrowCancel;
	
	//Gallery links
	$('a[@rel$="gallery"]').click(function(){ //makes galleries pop!
		window.open($(this).attr("href"),"Gallery","width=780,height=530,resizable=1,scrollbars=0");
		return false;
	});	
	
	$('#allTeams a').click(function(){ // Sets team links at the top to open in a new window
		this.target = "_blank";
	});
	
	//subnav
	$("ul#mainNav ul").each(function(i){
		if($(this).css("display") == "block") openNav = this;
	});
	
	$("ul#mainNav").bind("mouseout", function(){
		navOut = setTimeout("hideNav();",300);
	});
	
	$("ul#mainNav li ul li").bind("mouseover", function(){
		clearTimeout(navOut)
		$(this).parent().addClass("active");
	});
	
	$("ul#mainNav li ul").bind("mouseover", function(){
		clearTimeout(navOut)
		$(this).addClass("active");
	});	

	$("ul#mainNav li ul").parent().bind("mouseover", function(){
		clearTimeout(navOut)
		$(this).children("ul").addClass("active");
	});	
	
	$("#mainNav a").bind("mouseover", function(){
		clearTimeout(navOut)
		var subNav = $(this).parent().children("ul");
		if(!$(this).parent().parent().parent().is("li")) {
			$("#mainNav li ul.active").removeClass("active");
			$("#subNav").removeClass("active");
			if(openNav != false) {
				$(openNav).hide();
				if($(subNav).html() == $(openNav).html()) $(openNav).show();
			}
		}
		
		if($(subNav).size() == 1) {
			$(subNav).addClass("active");
		}
	});

/* Removed per req: 36600.
	//init scoreboard!
	$("a.btn_slide").bind("click", function(){
		slide($(this).attr("rel"),"div#scrollingBox ul","a.btn_slide",54,500);
		return false;
	});
	getScoreboardXML();
*/
	
	//image hovers on nfl shop on homepage
	$("#nflShop ul a").mouseover(function(){
		defaultImage = $("#nflShop img").attr("src");
		$("#nflShop a.shopLink").attr("href",$(this).attr("href"));
		$("#nflShop img").attr("src",$(this).attr("rel"));
	});


});

var navOut; //timeout used to hide the subnav
var openNav = false; //used to keep track of which nav is opened by default.

function hideNav() {
	$("#mainNav li ul.active").removeClass("active");
	if(openNav != false) $(openNav).show(); //restores the default nav if there is one
}
