/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
$(document).ready(function(){
	
	$(document).everyTime("8s", function(i) { 
		button1 = current1;
		current1++
		if (current1 == (images1+1) ) {current1 = 1}
			animateLeft(current1,button1);
		}
	);
	
	current1 = 1;
	button1 = 1;
	images1 = $(".contadordeslide1").length;
	width1 = 205;
	
	$('#pp1').animate({"left": "0px"}, 400, "swing");
	$('#bb1').css("backgroundPosition", "left bottom")
	$('#bb1 b').css("color","#fff");
	$('#loading').css("display","none");
	
	
	$("#next_lojas").click(function() {
		button1 = current1;
		current1++
		if (current1 == (images1+1) ) {current1 = 1}
			animateLeft(current1,button1)
	});
	$("#previous_lojas").click(function() {
		button1 = current1;
		current1--
		if (current1 == 0 ) {current1 = images1}
			animateRight(current1,button1)
	});
	
	$("#buttons div").click(function() {
		button1=current1;
		clickButton = $(this).attr('id');
		current1 = parseInt(clickButton.slice(1));
		if (current1 > button1)
			animateLeft(current1,button1)
		if (current1 < button1)
			animateRight(current1,button1)
	});
	
	function animateLeft(current1,button1) {
		$('#pp'+current1).css("left",width1 +"px");
		$('#pp'+current1).animate({"left": "0px"}, 400, "swing");
		$('#pp'+button1).animate({"left": -width1+"px"}, 400, "swing");
		setbutton()
	}
	function animateRight(current,button) {
		$('#pp'+current1).css("left",-width1+"px");
		$('#pp'+current1).animate({"left": "0px"}, 400, "swing");
		$('#pp'+button1).animate({"left": width1+"px"}, 400, "swing");
		setbutton()
	}
	function setbutton () {
		$('#bb'+button1).css("backgroundPosition", "left top")
		$('#bb'+button1+' b').css("color","#16a");
		$('#bb'+current1).css("backgroundPosition", "left bottom")
		$('#bb'+current1+' b').css("color","#fff");
	}

});


