var var_total;
var current = 1;
var var_next = 1;
var timer;

jQuery(document).ready(function() {
	var_total 	= jQuery('.promo .stats .total').text();
	toogleImage(current);
	if(var_total > 1) {
		timer 	= setInterval(autoToogleImage, 3500);
		jQuery('.promo .nav .icon').click(function() {
			clearInterval(timer);
			toogleImage(jQuery(this).attr('rel'));
		});
		//jQuery('.promo').hover(function(){ 
		//	jQuery('.promo .thumbnails').slideDown(100);
		//});		
		//jQuery('.promo').mouseleave(function(){ 
		//	jQuery('.promo .thumbnails').slideUp(100);
		//});
	} 
	else {
		jQuery('.promo .navigation').hide();
	}
});

 
function prevValue() {
	var_current = jQuery('.promo .stats .current').text(); 
	if(var_current == 1) {
		var_prev = var_total;
	} else {
		var_prev = var_current-1;
	}
	//alert('prev: '+var_prev);
	return var_prev; 
}

function nextValue() {
	if(var_next == var_total) {
		var_next = 1;
	} else {
		var_next = var_next+1;
	}
	//alert(var_next);
	return var_next; 
}

function autoToogleImage() {
	next_val = nextValue(); 
	toogleImage(next_val);
}

function toogleImage(show_id) {
	if(show_id == 'prev') {
		show_id = prevValue();
	}
	if(show_id == 'next') {
		show_id = nextValue();
	}
	
	jQuery('.promo .stats .current').text(show_id);
	
	jQuery('.promo .entry').hide();
	jQuery('.promo .entry_'+show_id).fadeIn();
	
	jQuery('.promo .nav .icon').removeClass('current');
	jQuery('.promo .nav .icon_'+show_id).addClass('current');
}


	


