/* _js/home.js */


// - execute on page load

$(document).ready(function(){

	// -- set sponsor rotation
	sponsorRotationInit();
});



// - sponsor rotation

// -- vars (config)
var sr_interval = 5000; // time (miliseconds) between each rotation
var sr_transition = 1000; // time (miliseconds) for the transitions 

// -- vars (private)
var sr_total = 0; // total number of sponsors
var sr_current = 0; // which sponsor is currently showing
var sr_target = 0; // which sponsor are we about to show

// -- initialize */
function sponsorRotationInit() {
	$('ul#sponsor_rotation > li').each(function() {
		sr_total++;
		$(this)
			.attr('rel', sr_total)
			.css('opacity', 0)
			.css('background-image', 'url('+$(this).find('img:first').attr('src')+')')
			.find('img:first').remove();
	});
	
	
	// --- set first item
	sponosorRotationCycle();
	
	// --- start auto-cycling
	if(sr_total > 1) {
		setInterval('sponosorRotationCycle()', sr_interval); 
	}
}


// -- cycle
function sponosorRotationCycle() {
	while(sr_target == sr_current) {
		sr_target = sponosorRotationGetTarget();
	}
	
	// --- fade out current
	if(sr_current) {
		$('ul#sponsor_rotation > li[rel='+sr_current+']')
			.fadeTo(sr_transition, 0)
	}
	
	// --- fade in target 
	$('ul#sponsor_rotation > li[rel='+sr_target+']')
		.fadeTo(sr_transition, 1)
		
	// --- set target as current
	sr_current = sr_target;	
}


// -- get random target
function sponosorRotationGetTarget() {
	return Math.floor(Math.random() * sr_total + 1); // get random item
}

//time stamp for flash connection ID
var current_date = new Date();
var connection_id = current_date.getTime();


