/*
Navigation Flyout
*/
$(function() {
	$("#navigation_primary li:not(.current) ul").hide();

	$("#navigation_primary").mouseleave(
		function() {
			$("#navigation_primary li a:not(ul ul a)").removeClass("hover");
			$(this).find("li:not(.current) ul").hide();
		}
	);

	$("#navigation_primary li.current").mouseover(
		function() {
			$("#navigation_primary li a:not(ul ul a)").removeClass("hover");
			$("#navigation_primary li:not(.current) ul:visible").hide();
		}
	);

	$("#navigation_primary li:not(.current) a:not(ul ul a)").mouseover(
		function() {
			var top_element = $(this);
			$("#navigation_primary li a:not(ul ul a)").removeClass("hover");

			// No other elements visible
			if (!$("#navigation_primary ul:visible").size()) {
				$(this).next("ul").show();
				$(this).addClass("hover");
			}
			// Menu already showing
			else {
				$("#navigation_primary li:not(.current) ul:visible").hide();
				top_element.next("ul").show();
				top_element.addClass("hover");


			}
		}
	);
});



/*
Random background image
*/
$(function() {
	$("div.bg_background").hide();
	var randomImages = ['bg_1','bg_2','bg_5','bg_7','bg_8','bg_10'];
	var rndNum = Math.floor(Math.random() * randomImages.length);
	$("#bg_left").html("<img src=\"/_images/bg/" + randomImages[rndNum] + "_left.jpg\" alt=\"\" />");
	$("#bg_left").after("<img src=\"/_images/bg/" + randomImages[rndNum] + "_right.jpg\" alt=\"\" id=\"bg_right\" />");
	$("div.bg_background").show();
});



/*
Rollovers for the input type="image".
Thanks to Atlanta Jones:
http://www.atlantajones.com/2008/07/02/even-easier-jquery-rollovers/
*/
$.fn.rollOver = function() {
	// Set the original src
	rollsrc = $(this).attr("src");
	if (rollsrc) {
		rollON = rollsrc.replace('off', 'on');
		newImg = new Image(); // create new image obj
		$(newImg).attr("src", rollON); // set new obj's src
	}
	
	this.mouseover(function() {
		imgsrc = $(this).attr("src");
		if (typeof(imgsrc) != 'undefined') {
		imgsrcON = imgsrc.replace('off', 'on');
		$(this).attr("src", imgsrcON);
		}
	});

	// Handle mouseout
	this.mouseout(function(){
		if (typeof(imgsrc) != 'undefined') {
		$(this).attr("src", imgsrc);
		}
	});
};



/*
Initialize
*/
$(function() {
	$(".rollover").rollOver();
	
	$('#content_primary').supersleight({shim: '/_images/shim.gif'});
	
	$("#headline h1 span.little").dropShadow({left: 1, top:2, blur:0, opacity:.5});
	$("#content_secondary .links_secondary a span").dropShadow({left: 1, top:2, blur:0, opacity:.5});
	$("#navigation_primary li a span:not(ul ul li a span)").dropShadow({left: 1, top:2, blur:0, opacity:.5});
	$("#navigation_primary li.current li a span").dropShadow({left: 1, top:3, blur:0, opacity:.5});
	$("#news_highlight p.date").dropShadow({left: 1, top:2, blur:0, opacity:.5});
	
	$("#feature").hover(
		function() {
			$(this).find("p").toggleClass("hover");
		},
		function() {
			$(this).find("p").toggleClass("hover");
		}
	);
});