$(function() {
	section = $("body").attr("class");
	sectionStr = "li#" + section + " a";
	
	navHighlightHold();
	fixIE6Dropdowns();
	setExternalLinks();
	setSidebarHovers();
	//subnavScrolls();

});

var section, sectionStr;	

// set external links
	function setExternalLinks() {
		$("a").each( function() {
			if ($(this).attr("rel") == "external") this.target = "_blank"; 
		});
	}
	
// fix ie6 dropdowns
	function fixIE6Dropdowns() {
		if($.browser.msie && $.browser.version == "6.0") {
			$("#navbar li").hover(
				function() { $(this).children("ul").show(); },
				function() { $(this).children("ul").hide(); }
			);
		}
	}	
	
// hold nav highlight when subnav on display
	function navHighlightHold() {
		$("#navbar li ul").hover(
			function() { 
				// -- over --
				$(this).siblings("a").css("background", "transparent url(../images/bg-nav-item.png) repeat-x bottom"); 
			},
			function() { 
				// -- out --
				$(this).siblings("a").css("background", "transparent url(../images/bg-nav-item.png) repeat-x top"); 
				// compensate for reset of default hover display
				$(this).siblings("a").hover(
					function() { $(this).css("background", "transparent url(../images/bg-nav-item.png) repeat-x bottom"); },
					function() { $(this).css("background", "transparent url(../images/bg-nav-item.png) repeat-x top"); }
				);
				resetSection();
			}
		);
	}
	
// reset our current section highlight
	function resetSection () {
		$(sectionStr).css("background-position", "bottom");
		//alert(sectionStr + " done");
	}
	
// set scroll animations for subnavs	
	function subnavScrolls() {
		$("#navbar li").hover(
			function() { 
				// -- over --
				$(this).children("ul").slideDown("fast");
				//$(this).children("ul").show();
			},
			function() { 
				// -- out --
				$(this).children("ul").slideUp("fast");
				//$(this).children("ul").hide();
				resetSection();
			}
		);
	}

// Set up sidebar hovers (could be done in CSS, except for IE6)
	function setSidebarHovers() {
		$("#secondaryContent div.secondaryItem").click( function() {
			var destination = $(this).find("h3 a").attr("href");
			window.location = destination;
		});
	
	
		$("#secondaryContent div.secondaryItem").hover(
			function() {
				$(this).find("p").css("border-bottom", "1px dotted #999");
				$(this).find("p a").css("color", "#999");
				$(this).css("cursor", "pointer");
			},
			function() {
				$(this).find("p").css("border-bottom", "none");
				$(this).find("p a").css("color", "#000");
				$(this).css("cursor", "normal");
			}
		);
	}



