$(document).ready(function(){
	var totalBlocks = -1;
	var slideNumber = 0;
	var rotateInterval ;
	$("#_playPauseBtn").addClass("play");
	$("#_playPauseBtn").toggle(
	function(){
		$("#_playPauseBtn").removeClass("play");
		rotateInterval = setInterval(moveSlider,8000);
	},function(){
		$("#_playPauseBtn").addClass("play");
		clearInterval(rotateInterval)
	});
	$(".slideBlock").each(function(i){
		totalBlocks++;
	});
	$(".slideBlock").each(function(i){
		var nextPos = (i * (Math.floor(788/totalBlocks)))-25;
		var _title= $(this).attr("s_title");
		$("#slider").append("<a href='#' class ='posCircle' title="+_title+" alt="+_title+" style='left:"+nextPos+"px'></a>");
	});
	
	$(function() {
	
	$( "#slider" ).slider({
		value:0,
		min: 0,
		max: 788,
		step: Math.floor(788/totalBlocks),
		slide: function( event, ui ) {
			//$( "#camels" ).css( "left" , ui.value );
			$( "#camels" ).animate({left : ui.value},500);
			slideNumber = ui.value/Math.floor(788/totalBlocks);
			$( ".slidesHolder" ).animate({left : -(980)*(ui.value/Math.floor(788/totalBlocks))},500);
		}
	});
	//$( "#amount" ).val( "$" + $( "#slider" ).slider( "value" ) );
	});
	
	
	
	function moveSlider(){
		if(slideNumber<totalBlocks){
			$( "#slider" ).slider( "option", "value", (slideNumber+1)*Math.floor(788/totalBlocks) );
			$( "#camels" ).animate({left : (slideNumber+1)*Math.floor(788/totalBlocks)},500);
			$( ".slidesHolder" ).animate({left : -(980)*(slideNumber+1)},500);
			slideNumber++;
		}else{
			slideNumber = 0;
			$( "#slider" ).slider( "option", "value", 0 );
			$( "#camels" ).animate({left : (slideNumber)*Math.floor(788/totalBlocks)},500);
			$( ".slidesHolder" ).animate({left : -(980)*(slideNumber)},500);
			
		}
	}
});
