$(document).ready(function(){ 
	cta.init(); 
} );

var cta = {
	selected: 0,
	wait: 5,
	speed: 400, 
	busy:false,
	init: function() {		
		if ($("#feature_promotion").length == 0) { return; }
		cta.items = $("#feature_promotion > li");
		cta.timeout = setTimeout("cta.select_next();", cta.wait*1000);
	},

	tween: function(id1, id2) {
		item1 = cta.items[id1];
		item2 = cta.items[id2];
		cta.busy=true;
		$(item1).fadeOut(cta.speed, function() { $(item2).fadeIn(cta.speed, function() { cta.busy=false; }); });
		cta.timeout = setTimeout("cta.select_next();", cta.wait*1000);

	},

	select_next: function() {
		item1 =cta.selected;
		cta.selected++;
		if (cta.selected>cta.items.length-1) { cta.selected=0; }
		if (item1==cta.selected) { return; }	
		cta.tween(item1, cta.selected);

	}
}

function select_race(element) {
	url = element.options[element.selectedIndex].value;
	if (url=='') { return; }
	
	window.location='http://betlight.co.uk/racing/'+url+'/';
}

