(function($) {
	$.fn.simplePhotoSlide = function(options) {
	
		var opts = $.extend({}, $.fn.simplePhotoSlide.defaults, options);
		var spacer = '<img src="http://www.sinato.jp/wp-content/themes/sinato/_img/img-spacer.gif" width="600" class="img-spacer"/>';
		
		return this.each(function(){
			
			$(this).addClass('worksImgs');
			$(this).append(spacer);
			
			$img = $(this).children('img').not('img.img-spacer');
			if($img.length > -1){
				$img.fadeOut(0);
				$img.eq(0).fadeIn(1200, function(){
					$('.img-spacer').fadeOut(0);
				});
				$img.css('position', 'absolute');
	
				$img.hover(
					function(){
						$(this).css('cursor', 'pointer');
					},
					function(){
						$(this).css('cursor', 'default');
					}
				);
				
				var j = 0;
				$img.click(changePhoto);
				$('.next-bt').click(changePhoto);
			}
			
			function changePhoto(){
				j++;
				var imgNum = j%$img.length;
				var imgPreNum;
				
				if(j == 0) imgPreNum = $img.length - 1;
				else imgPreNum = imgNum - 1;
				$('#single p').append(spacer);
				$img.eq(imgPreNum).stop(true, false).fadeOut(opts.fadeOutTime);
				$img.eq(imgNum).stop(true, false).fadeIn(opts.fadeInTime, function(){
					$('.img-spacer').fadeOut(0);
				});				
			}
			
		});
	};
	
	$.fn.simplePhotoSlide.defaults = {
		fadeOutTime: 800,
		fadeInTime: 800
	};
	
})(jQuery);
