var slider = {

	stimer: 0,
			
	sinit : function(){
		$("#slider img").css("opacity", 0);
		$("#slider img").eq(0).animate({ "opacity":1 }, 300);
		slider.sstart();
		slider.saction();
	},

	sanimation : function( next ){
	
		clearInterval( slider.stimer );
		delete( slider.stimer );
				
		$("#slider img.view").animate({ "opacity":0 }, 300, function(){
			$("#slider img.view").removeClass("view");
			$("#slider img").eq(next).addClass("view").animate({ "opacity":1 }, 300);
			$("span.current").animate({ "right":"-15px" }, 200, function(){
				$("span.current").removeClass("current");
				$("span.ctrl").eq(next).animate({ "right":"0px" }, 200, function(){
					$("span.ctrl").eq(next).addClass("current");
					slider.sstart();
					spanClicked = 0;
				});	
			});		
		});
	
	},
	
	sstart : function(){
		
		clearInterval( slider.stimer );
		delete( slider.stimer );
		
		slider.stimer = window.setInterval(function(){
			var totalItens = $("span.ctrl").length;
			var currentIndex = $("span.current").index();
			var next = currentIndex + 1;
			
			if( (currentIndex + 1) < totalItens )
				slider.sanimation( next );
			else
				slider.sanimation( 0 );
		}, 8000);
	
	},
	
	saction: function(){
		
		$("span.ctrl").unbind("mouseover").bind("mouseover", function(){
			var self = $(this);
			self.stop().animate({ "right":"0px" }, 200);
		});
		
		$("span.ctrl").unbind("mouseout").bind("mouseout", function(){
			var self = $(this);
			var $_thisIndex = self.index();
			if( $_thisIndex != $("span.ctrl.current").index())
				self.stop().animate({ "right":"-15px" }, 200);
			
		});
		
		$("span.ctrl").unbind("click").bind("click", function(){
			
			spanClicked = 1;
			
			var self = $(this);
			var $_thisIndex = self.index();
		
			self.css("right","0px");

			if( $_thisIndex != $("span.current").index())
				slider.sanimation( $_thisIndex );
			
		});
		
	}
		
}

var spanClicked = 0;

$(document).ready(function(){
	
	//slider.sinit(); 

	$(".summertime").unbind("click").bind("click", function(){
		location.href = "http://www.kaz.com.br/colecao/";
	});
});

