$(document).ready(function(){
	//current photo number
	var currentPhoto = 0;
	var photoNum = 6;
	//interval time
	var time = 3000;
	var theInt = null;
	
	var speed = 750;
	
	initPhoto();
	
	function initPhoto(){
		$('#mainIMG li').each(function(){
			var $photo = $(this);
			$photo.hide();
		});
		var $current = $('#mainIMG li:eq(' + currentPhoto + ')');
		$current.fadeIn(speed);
		theInt = setInterval(changePhoto, time);
	}
	function changePhoto(){
		clearInterval(theInt);
		var $current = $('#mainIMG li:eq(' + currentPhoto + ')');
		$current.fadeOut(speed, changeSrc);
		var nextPhoto = currentPhoto + 1;
		var $next = $('#mainIMG li:eq(' + nextPhoto + ')');
		$next.fadeIn(speed);
	}
	function changeSrc(){
		currentPhoto++;
		if (currentPhoto < photoNum - 1) {
			theInt = setInterval(changePhoto, time);
		}
	}
});

