$(document).ready(function(){
	
	var totalScreenshots = 8;
	var currentScreenShot = 1;
	
	$("#screen"+currentScreenShot).css({opacity: '1', zIndex: '2'});
	
	$('#screenholder').click(function () {
		$("#screen"+currentScreenShot).stop().animate({opacity: 0},600, "easeOutQuad");
		$("#screen"+currentScreenShot).css({zIndex: '1'});
		if(currentScreenShot+1>totalScreenshots){
			currentScreenShot = 1	
		} else {
			currentScreenShot++;
		}
		$("#screen"+currentScreenShot).stop().animate({opacity: 1},1000, "easeOutQuad");
		$("#screen"+currentScreenShot).css({zIndex: '1'});
	});
	
	
	
	var inputDelayer=delayTimer(60);
	var waitDelayer=delayTimer(1200);
	var leftPosition = -280;
	
	inputDelayer(function(){moveImg()});
	
	function moveImg(){
		leftPosition = leftPosition+1;
		if(leftPosition > 100) {
			$('#cloud').stop().animate({opacity: 0, left:leftPosition + 30 },800);
			waitDelayer(function(){resetImg()});
		} else {
			$('#cloud').stop().animate({left: leftPosition},100);
			inputDelayer(function(){moveImg()});
		}
		
	}
	
	function resetImg() {
		leftPosition = -280;
		$('#cloud').css({opacity: '1', left: -280});
		inputDelayer(function(){moveImg()});
	}
	
	function delayTimer(delay){
     var timer;
     return function(fn){
          timer=clearTimeout(timer);
          if(fn)
               timer=setTimeout(function(){
               fn();
               },delay);
          return timer;
     }
	}
	
	
	
	
		
});
