// JavaScript Document
jQuery(document).ready(function(){
	num=-1;
	current=0;
	
	massivText = ['animation/text1.png', 'animation/text2.png', 'animation/text3.png', 'animation/text4.png'];
	massivImg = ['animation/img1.png', 'animation/img2.png', 'animation/img3.png', 'animation/img4.png'];
    
	jQuery("#slideshow .show").html("<img src='"+ massivText[0] +"' class='text'/><img src='"+massivImg[0]+"' class='pic'/>");
	jQuery("#slideshow .next").html("<img src='"+ massivText[1] +"' class='text'/><img src='"+massivImg[1]+"' class='pic'/>");
	
	setTimeout("slideShow()", 4000 );
	intervalID = setInterval('slideShow()', 7000);
	
	jQuery("#navigation div").click(function(){
		jQuery(this).removeClass("current");
		num = jQuery(this).attr("class");
		current=num;
		clearInterval(intervalID);
		jQuery("#navigation img").removeClass("current");
		//$(this).addClass("current");

		if (num==0){
			massivText = ['animation/text4.png', 'animation/text1.png', 'animation/text2.png', 'animation/text3.png'];
			massivImg = ['animation/img4.png', 'animation/img1.png', 'animation/img2.png', 'animation/img3.png'];
		} else {
			massivText = ['animation/text1.png', 'animation/text2.png', 'animation/text3.png', 'animation/text4.png'];
			massivImg = ['animation/img1.png', 'animation/img2.png', 'animation/img3.png', 'animation/img4.png'];
		}
		
		for (var i=0; i<num-1; i++){
			var removedItem_1 = massivText.shift(); // удаляем первый элемент
    		massivText.push(removedItem_1);
	
			var removedItem_2 = massivImg.shift(); // удаляем первый элемент
    		massivImg.push(removedItem_2);
		}		
		
		jQuery("#slideshow .next").html("<img src='"+ massivText[1] +"' class='text'/><img src='"+massivImg[1]+"' class='pic'/>");
		slideShow();	
		
		intervalID = setInterval('slideShow()', 7000);	
	});
})


function addPic(){
		if (num<0){
			if (current<3){
				current++;
			} else{
				current=0;
			}
		} else {
			num=-1;
		}
	
		jQuery("#navigation div").removeClass("current");
		jQuery("#navigation div").each(function(){
			if(jQuery(this).attr("class")==current){
				jQuery(this).addClass("current");
			}
		})
		
		var removedItem_1 = massivText.shift(); // удаляем первый элемент
    	massivText.push(removedItem_1);
	
		var removedItem_2 = massivImg.shift(); // удаляем первый элемент
    	massivImg.push(removedItem_2);
		
		jQuery("#slideshow .next").html("<img src='"+ massivText[1] +"' class='text'/><img src='"+massivImg[1]+"' class='pic'/>");	
	
}

function slideShow(){
	jQuery(".show .text" ).animate({ left: -1200}, {duration: 1000, complete: function(){callback();}});
	jQuery(".show .pic").animate({ left: 12200}, {duration: 1100, easing: 'easeInCubic'});
}

function callback() {
	jQuery(".show").remove();
	jQuery(".next").addClass("show");
	jQuery( ".next .text" ).animate({ left: 0 }, {duration: 500, easing: 'easeOutCubic'});
	jQuery( ".next .pic" ).animate({ left: 0  }, {duration:1200, easing: 'easeOutCubic'});			
			
	jQuery(".show").removeClass("next");	
	jQuery("#slideshow").append("<div class='item next' ></div>");
			
	addPic();	
	
	//num=-1;
};

