$(document).ready(function(){
	// таймер для смены картинок в варианте без флеша
	intervalID = window.setInterval(nextImage, 4000);
	$('#kaleidoscope').hover(function() {
			//Set the width and height according to the zoom percentage
			width = $('#kaleidoscope').width() * zoom;
			height = $('#kaleidoscope').height() * zoom;
			//Move and zoom the image
			//$('#kaleidoscope').find("#i"+imgID).fadeOut();
			clearInterval(intervalID);
			//Display the caption
			$('#caption'+imgID).fadeIn();
		},
		function() {
			intervalID = window.setInterval(nextImage, 4000);
			//Reset the image
			$("#i"+imgID).stop(false,true).animate({'width':$('#kaleidoscope').width(), 'height':$('#kaleidoscope').height(),}, {duration:100});	
			//Hide the caption
			$('div#caption'+imgID).fadeOut();
			//picTimer = window.setTimeout(nextImage, 4000);
		});

});

var move = 0;
var zoom = 1;

var imgID = '1';
function nextImage(){
	$("#i"+imgID).fadeOut(600);
	$('#kaleidoscope').hover(function() {
			//Set the width and height according to the zoom percentage
			width = $('#kaleidoscope').width() * zoom;
			height = $('#kaleidoscope').height() * zoom;
			//Move and zoom the image
			//$('#kaleidoscope').find("#i"+imgID).fadeOut();
			clearInterval(intervalID);
			picTimer = 0; 
			//Display the caption
			$('#caption'+imgID).fadeIn();
		},
		function() {
			//Reset the image
			$('#kaleidoscope').find("#i"+imgID).stop(false,true).animate({'width':$('#kaleidoscope').width(), 'height':$('#kaleidoscope').height(),}, {duration:100});	
			//Hide the caption
			$('div#caption'+imgID).fadeOut();
			intervalID = window.setInterval(nextImage, 4000);
			//picTimer = window.setTimeout(nextImage, 4000);
		});
	imgID++;
	if(imgID >= $("#kaleidoscope > a > img").length){ imgID = 1; }
	$("#i"+imgID).fadeIn(600);
	
}

