// JavaScript Document
/*var animating = false;
$(function(){
	$(".sHolder").hover(
	  function () {
		maximize(this);
	  },
	  function () {
		minimize(this);
	  }
	);
});

function maximize(target){
	if(animating == true) return;
	animating = true;
	$(".sHolder").each(function(index, element) {
       
		if(element != target){
			
			$(element).animate({"width":"15px"},1000,'swing', function(){animating = false});		
			
		}
		else{
			
			$(element).animate({"width":"939px"},1000,'swing');		
		
		}
		
    });
	
}


function minimize(target){
	
	$(".sHolder").each(function(index, element) {	
		$(element).animate({"width":"323px"},300, function(){animating = false});		
	});
}*/

$(function(){
	
	//init
	var oldorder=0;
	var poz = 0;
	var total=0;
	var slideshow;
	var on="on";
	$(".sHolder ").each(function(index, element) {
		if(index != poz) {
			$(this).hide();
			on = "";
		}
		
	    var html = "<div class='imageButton "+on+"' rel="+index+"></div>";
		$(this).css("left",970*index);
		$("#control").append(html);
		total++;
		
    });
	$(".imageButton").hover(
		function(){
		//disable slideshow
		
			clearInterval(slideshow);
		
		},
		function(){
		//enable slideshow	
			
			//slideshow = setInterval(slideShow,6000);
			
		});
	
	$(".imageButton").click(function(){
		
		poz = $(this).attr("rel");
		slide(poz);
		
	});
	
	function slide(number){
	
		var order= number;

		if(order == oldorder) return;
		
		$(".imageButton").each(function(index, element) {
			if(index==number)
				$(element).addClass("on");
			else
				$(element).removeClass("on");
        });
		
		$(".sHolder").each(function(index, element) {
			$(element).show();
			
        });
		$("#picture-holder").animate({marginLeft:-970*order},500,"linear",function(){
			
			$(".sHolder ").each(function(index, element) {
		
				if(index != order) $(element).hide();
	   
			});
			
		});
		
		oldorder = order;
		
	}
	
	function slideShow(){

		poz++;
		if(poz==total) poz=0;	
		slide(poz);
		
	}
	
	//slideshow = setInterval(slideShow,8000);
	
});



