//////////////////////////////////////////////////////
//
//	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);
		
		$($('.navsub li.first')).addClass('selected');
		
		$('.pull div').load($('.navsub li a')[0].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);
	});
	*/
	
	$('.random').cycle({cleartypeNoBg:true});
 
	
	var interval = interval = setInterval(function(){doNext();},5000);
	
	function doNext() {
		curri = 0;
		lis = $('.navsub li');
		for(var i = 0; i < lis.length; i++){
			if($(lis[i]).hasClass('selected')) {
				curri = i;
				break;
			}
		}
		nexti = (curri + 1) % lis.length;
		current = $(lis[curri]);
		next = $(lis[nexti]);
		changeSlide(current,next);
	}
	
	function changeSlide(current, next) {
		current.removeClass('selected');
		next.addClass('selected');
		//fade out and fade in	
		var nexthref = next.find('a').attr('href');
		$('.pull div').fadeOut('slow', function(){			
			$(this).load(nexthref + " .pullSource div", function(){
					$(this).fadeIn('slow');
			});
		});
		clearInterval(interval);
		interval = setInterval(function(){doNext();},5000);
	}
	
	$('.navsub li a').click(function(){
		next = $(this).parent('li');
		current = $('.navsub li.selected');
		changeSlide(current,next);
		return false;
	});
	
	$('a.next').click(function() {		
		doNext();
		return false;
	});


	
	
});

$(function(){
	
	//numItems = $('#homeNews .scroller #content > div.item').length
	$('#homeNews .scroller').serialScroll({
		prev: '#homeNews .prev img',
		next: '#homeNews .next img',
		cycle:false,
		items: '#content div',
		duration: 500,
		axis:'y',
		easing:'linear',
		step:2,
		exclude: 1,
	});
});

