$(function(){

	$('.shadow').fadeOut('slow');

	var count = 0, cur = 0, start = 0;

	$('.gallery img').each(function(){

		count++;
	});

	setTimeout(function(){

		next(start);

	},4000);


	function next(i){

		if(cur >= count-1){
			$('.gallery').css('left','0');
			cur = 0;
			i = 0;
			next(i);
			return
		}

		$('.shadow').fadeIn('slow',function(){

			cur = cur + 1;

			i = i -960;

			$('.gallery').animate(
				{ 'left':i+'px' },	
				2000,'easeOutQuart',function(){

				setTimeout(function(){

					$('.shadow').fadeOut('fast',function(){

						setTimeout(function(){
							next(i);
						},4000);

					});

				},1000);
			});
		});
	}
});

/*

$(function(){


	var count = 0, cur = 0, start = -960;
	images = ['slide1.jpg','slide2.jpg','slide3.jpg'];

	$.each(images, function(i){
		var img = new Image;

		if(i == (images.length - 1)){
			$(img).load(function(){

				setTimeout(function(){
					next();
				},4000);
			});
		}
		img.src = "images/"+this;
	});


	function next(){

		//alert('hello');

		$('.slideshow img').fadeOut('slow',function(){

			cur = cur + 1;

			if(cur >= images.length){
				cur = 0;
			}

			$('.slideshow').hide().html('<img src="images/'+images[cur]+'" alt="slideshow" />');


			//$('#display').css('background-position',start+' 0');

			setTimeout(function(){

				$('.slideshow').fadeIn('slow',function(){

					setTimeout(function(){
						start = start -960;
						next();
					},4000);

				});

			},1000);

		});

	}
  
});

*/

