/*
 * simpleCrossFade
 * Version 1.0  -  Updated: Sep. 15, 2011
 *
 * Copyright 2011 m-hand Yuuki Taniguchi
 * www.m-hand.com/
 *
 * imgをクロスフェードするプラグイン
 */

(function($){
	$.fn.simpleCrossFade = function (options) {
		var settings = {
			auto:true,
			speed:8000
		}
		settings = $.extend(settings, options);
		
		var org = {
			init : function($elm){
				$elm
					.css("position","relative")
					.find("img")
					.css({"display":"none","position":"absolute"})
					.end().find("img:first").css("display","block").addClass("active_img")
					.end().find("img:last").addClass("end_img");
			},
			crossFade : function($elm){
				var spd = 800;
				var $act =$elm.find(".active_img");
				var $next = $act.next();
				
				$act.fadeOut(spd).removeClass("active_img");
				if($act.hasClass("end_img")){
					$elm.find("img:first").fadeIn(spd).addClass("active_img");
				}else{
					$next.fadeIn(spd).addClass("active_img");
				}
			}
		}
		
		var $target = $(this);

		org.init($target);
		
		if(settings.auto){
			setInterval(function(){
				org.crossFade($target);	
			},
			settings.speed);
		}
	}
})(jQuery);
