$(document).ready(function(){
	promo_prepare();
});


var promo_iterator = 1;
var promo_max = 0;
var promo_interval;
function promo_prepare() {
	$(".promo").hide();
	$("#promo"+promo_iterator).show();
	$("#promo_switch span").each(function(){
		var c = $(this).attr("sid");
		if(c > promo_max) promo_max = c;
		if(c == promo_iterator) {
			$(this).addClass("s");
			$(this).children(".wpix").css("width","0px");
		} else {
			$(this).removeClass("s");
		}
		
		$(this).click(function(){
			promo_switch(c);
		});
	});
	
	promo_interval = setInterval("promo()", 10000);
}

function promo() {
	promo_iterator++;
	if(promo_iterator > promo_max) promo_iterator = 1;
	$(".promo").hide();
	$("#promo"+promo_iterator).show();
	$("#promo_switch span").each(function(){
		var c = $(this).attr("sid");
		if(c == promo_iterator) {
			$(this).addClass("s");
			$(this).children(".wpix").css("width","0px");
		} else {
			$(this).removeClass("s");
			
		}
	});
}

function promo_switch(i) {
	clearTimeout(promo_interval);
	promo_iterator = i;
	if(promo_iterator > promo_max) promo_iterator = 1;
	$(".promo").hide();
	$("#promo"+promo_iterator).show();
	$("#promo_switch span").each(function(){
		var c = $(this).attr("sid");
		if(c == promo_iterator) {
			$(this).addClass("s");
		} else {
			$(this).removeClass("s");
		}
	});
	promo_interval = setInterval("promo()", 7000);
}

