//ATU SLIDESHOW

$(function(){
	var currentID = 0;
	var activeID = 0;
	
	var buttonCount = $("#slideshow #slideshow_buttons div.slideshow_button").length;
	
	$("#slideshow #slideshow_buttons div.slideshow_button").css({ 'width' : Math.floor((610) / buttonCount) - 1 + 'px' });
	
	if(buttonCount == 5)$("#slideshow_button_4").css({'width' : Math.floor((610) / buttonCount) - 2 + 'px'});
	if(buttonCount == 4)$("#slideshow_button_3").css({'width' : Math.floor((610) / buttonCount) + 'px'});
	if(buttonCount == 2)$("#slideshow_button_1").css({'width' : Math.floor((610) / buttonCount) - 2 + 'px'});
	
	
	$("#slideshow_button_container").fadeIn()
	
	
	var timerInterval = 6000;
	
	var switched = true;
	
	 $("#slideshow #slideshow_buttons #slideshow_button_0").css({
					 'color' : '#ffffff',
					 'background-color' : '#c41526'
		});

	var atuTimer = $.timer(timerInterval, function(timer){
		if(currentID < buttonCount - 1)
		{
			currentID++;	
		} else {
			currentID = 0;	
		}
		
		showSlider(currentID);
		timer.reset(timerInterval);
	});

	$("div.slideshow_button").mouseover(function(){
		$mouse = $(this);
		
		var mouseID = $mouse.attr("id").split('_');
		
		if(mouseID[2] == activeID)return;
												 
		$(this).css({	'color' : '#ffffff',
					 	'background-color' : '#d48384'});					 
	
	}).mouseout(function(){
		
		$mouse = $(this);
		
		var mouseID = $mouse.attr("id").split('_');
		
		if(mouseID[2] == activeID)return;
		
		$(this).css({	'color' : '#c41526',
					 	'background-color' : '#FFFFFF'});	
	}).click(function(){
		
		$clicked = $(this);
		
		var clickedID = $clicked.attr("id").split('_');
		
		showSlider(clickedID[2]);
		
		atuTimer.stop();
		
	});
	
	
	function showSlider(id)
	{		
		if(!switched)return;
		switched = false;
		
		$current = $("#slideshow #slideshow_buttons #slideshow_button_" + id);
		
		$current.css({
					 'color' : '#ffffff',
					 'background-color' : '#c41526'
		});	
		
		
		$("#slideshow_content #slideshow_" + activeID).fadeOut("fast", function(){
			$("#slideshow_content #slideshow_" + id).fadeIn();
			switched = true;
		});
		

		
		$current.siblings(".slideshow_button").css({
			'color' : '#c41526',
			'background-color' : '#FFFFFF'
		});
		
		activeID = id;
	}
	
	
	
});

	