/******************************************************************************************************************/
// HIGHLIGHTS
/******************************************************************************************************************/

var current = -1;
var mytimer;
var num;


function loopItems(){
	current++;
	if (current >= num) current = 0; 
	
	$('#highlights .nav li').removeClass('sel');
	$('#highlights .nav li:eq('+ current +')').addClass('sel');
	
	$('#highlights .viewport li').hide();
	$('#highlights .viewport li:eq('+ current +')').fadeIn(500);
	
	mytimer = setTimeout('loopItems('+ current +')', 4000);
}

function handleHighlights(){
	$('#highlights .viewport li:eq(0)').show();
	$('#highlights .nav li:eq(0)').addClass('sel');
	
	num = $('#highlights .viewport li').size();
	
	if (num > 1) {
		// loop
		loopItems();
		
		// click
		$('#highlights .nav a').click(function(){
			clearTimeout(mytimer);
			
			myid = $(this).attr('href');
			
			$('#highlights .nav li').removeClass('sel');
			$(this).parents('li').addClass('sel');
			
			$('#highlights .viewport li').hide();
			$(myid).fadeIn(500);
			
			return false;
		});
	}
}

/******************************************************************************************************************/
// SPONSOR TICKER FUNCTIONS
/******************************************************************************************************************/

function BannerHoverHandle(){
	$('.sponsor .item').hover(function(){
		clearTimeout(BannerTimerId);
		index = $('.sponsor .item').index(this);
	}, function(){
		BannerRun(index);
	});
}

function BannerClickHandle(){
	$('.sponsor .bullet').click(function(){
		if (!$(this).hasClass('sel')){
			$('.sponsor .bullet').removeClass('sel');
			$(this).addClass('sel');
			
			clearTimeout(BannerTimerId);
			index = $('.sponsor .bullet').index(this);
			BannerRun(index);
		}
	});
}

function BannerShow(i){
	$('.sponsor .item').hide();
	$('.sponsor .item:eq('+ i +')').show();
	
	$('.sponsor .bullet').removeClass('sel');
	$('.sponsor .bullet:eq('+ i +')').addClass('sel');
}

function BannerRun(i){
	num2 = $('.sponsor .item').size();
	if (num2 > 1) {
		BannerShow(i)
		i++;
		if (i == num2) i = 0;
		BannerTimerId = window.setTimeout('BannerRun('+ i +')', 6000);
	}
}


/******************************************************************************************************************/
// On document load...
/******************************************************************************************************************/

$(function(){
	// highlights
	handleHighlights();
	
	// fancybox
	$('.fancybox').fancybox();
	
	// sponsor
	BannerRun(0);
	BannerHoverHandle();
	BannerClickHandle();
});