$(document).ready(function() {

	// For each link containing -off, set up a -on hover
	$("img[src*='-off']").each(function() {
	
		// Preload on state
		var img = new Image();
		img.src = $(this).attr("src").replace(/-off/,"-on");
		
		// If this is within the navigation, then put the hover on the <li> so it stays switched during dropdown navs
		if ($(this).parent().parent().parent().parent().attr("id") != "main-nav")
		{
			// Set up the hover switcher
			$(this).hover(function() {
				$(this).attr("src",$(this).attr("src").replace(/-off/,"-on"));
			}, function() {
				$(this).attr("src",$(this).attr("src").replace(/-on/,"-off"));
			});
		}
		
	
	});
	
	$("#main-nav > ul > li, #main-nav-f > ul > li").hover(function() {
		$(this).children("a").addClass("hover");
		$(this).find("ul").show();
	}, function() {
		$(this).parent().find("a.hover").removeClass("hover");
		$(this).find("ul").hide();
	});
	
	// For browers that don't support our css :first-child
	$("#main-nav > ul > li > ul > li:first-child, #main-nav-f > ul > li > ul > li:first-child").addClass("first-child");
	
	if ($("#slider").length > 0)
	{
		// Homepage features
		$("#slider").flash({
			swf: 'flash/slider.swf',
			height: 303,
			width: 665
		});
		
		$(".stories, .careers").jScrollPane({ scrollbarWidth: 11 });
	}
	
	if ($("#slider-f").length > 0)
	{
		// Homepage features
		$("#slider-f").flash({
			swf: 'flash/slider-f.swf',
			height: 303,
			width: 665
		});
		
		$(".stories, .careers").jScrollPane({ scrollbarWidth: 11 });
	}

	if ($("#photo").length > 0)
	{
		$("#photo").cycle({
			random: 1,
			timeout: 8000,
			speed: 2000
		});
	}
});
