// Search and replace: promo_carousel

$(document).ready(function() {
	// update stats total
	$('.promo_carousel .stats .total').html( $('.promo_carousel .entry').size() );
	
	// bind nav buttons 
	$('.promo_carousel .nav .button').click( function() {
		if( $('.promo_carousel .entry').size() > 1 ) {
			clearInterval(promo_carousel_interval);
		}
		change_promo_carousel( $(this).attr('rel') );
	});
	
	// auto toggle
	if( $('.promo_carousel .entry').size() > 1 ) {
		promo_carousel_interval = setInterval(function() {
			change_promo_carousel('next');
		},3500);
	}
	
	// init promo_carousel
	change_promo_carousel(1);
});

function change_promo_carousel(rel) {
	// get variables
	aCurrent 	= $('.promo_carousel .stats .current').html()*1;
	aTotal		= $('.promo_carousel .stats .total').html()*1;
	// decide settings
	if( rel == 'next' ) {
		showId = aCurrent == aTotal ? 1 : aCurrent+1;
	} else if( rel == 'prev' ) {
		showId = aCurrent == 1 ? aTotal : aCurrent-1;
	} else {
		showId = rel;
	}
	// update stats
	$('.promo_carousel .stats .current').html(showId);
	// update navigation
	$('.promo_carousel .nav .button').removeClass('current');
	$('.promo_carousel .nav .button_'+showId).addClass('current');
	// change promo
	$('.promo_carousel .entry').hide();
	$('.promo_carousel .stats .current').html(showId);
	$('.promo_carousel .entry_'+showId).fadeIn('fast');
}

