//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
$(window).load(function() {
	if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".navtop > li").hover(function() {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		// this adds flyout support for IE 6
		$(".navtop > li li ").hover(function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		
	} else {
		// this is need for safari when nav covers flash
		$(".navtop li ul").hover(function () {
			$(this).addClass("redraw");
		},
		function () {
			$(this).removeClass("redraw");
		});
	}
	
	
	//home page storyloader
	if($('.pull div').length > 0)
	{
		$('.pull div').fadeOut(0);
		
		//add .selected to random subnav item
		var rand_no = Math.floor(4*Math.random());	
		
		$($('#navsub li')[rand_no]).addClass('selected');
		
		$('.pull div').load($('#navsub li a')[rand_no].href +  ' .pullsource div', function(){
			$(this).fadeIn('slow');
		});
	}
	
	$('#navsub li a').each(function(){
		a = $(this);
		img = $(this).find('img');
		text = $(a).text();
		$(a).text('');
		$(a).append(img);
		$('<span></span>').appendTo(a).text(text);
	});
	
	var href = "";
	$('#navsub li a').each(function(){		
		$(this).click(function(){
			var href = this.href;
			$('#navsub li.selected').removeClass('selected');
			$(this).parent('li').addClass('selected');
			$('.pull div').fadeOut('slow', function(){
				$(this).load(href + " .pullsource div", function(){
						$(this).fadeIn('slow');
				});
				
			});
			return false;
		});
	
	});
	
});

