/* =============================================================================
	スライドショー ver0.9
============================================================================= */

(function($) {
	$.fn.slide = function(settings) {
		settings = jQuery.extend({
			firstload		: 0,
			showmode		: "normal",	// [ random | normal ]
			action			: "auto",	// [ auto | click ]
			interval_mode	: "normal",	// [ random | normal ]
			interval_normal	: 8000,
			interval_min	: 8000,
			interval_max	: 6000,
			animation		: true,		// [ true | false ]
			fadespeed		: 1000
		}, settings);

		var _root	= this;
		var max		= $(this).find("li").length;
		var current	= settings.firstload;
		var change_mode;
		var TimerID;
		var click_check = false;

		//alert(current);
		
		

		$(this).find("li").not(":eq(" + current + ")").hide();

			$(".member_bt").click(function(){
				clearTimeout(TimerID);
				click_check = true;
				animation();
				//animation();
			}
			);

/*
				$(".member_bt").click(function(){
					clearTimeout(TimerID);
					animation();
				}
				);
*/

		if(settings.action == "auto") {
			intervalmode_check();
		}else if(settings.action == "click"){
			$(this).click(animation);
		}

		function intervalmode_check() {
			if(settings.interval_mode == "normal") {
				//TimerID;
				if(current == 1){
					TimerID = setTimeout(animation, settings.interval_min);
				}else{
					TimerID = setTimeout(animation, settings.interval_normal);
				}
				
				//alert(current);
			} else {
				/*var time = settings.interval_min + Math.floor(Math.random() * (settings.interval_max + 1));
				setTimeout(animation, time);*/
				TimerID;
			}
		}

		function animation() {
			var prev = $(_root).find("li").eq(current);
			var n = current;
			if(settings.showmode == "normal") {
				if(current == (max- 1)) {
					current = 0;
				} else {
					current++;
				}
			} else {
				if(current == (max- 1)) {
					current = 0;
				} else {
					current++;
				}
			}

			var next = $(_root).find("li").eq(current);

			if(n == current) {
				animation();
			} else {
				if(settings.animation == true) {
					
					prev.fadeOut(settings.fadespeed);


					next.fadeIn(settings.fadespeed);

					
				} else {
					prev.hide();
					next.show();
				}
				if(click_check == false){
					intervalmode_check();
				}else{
				
				}
			}
			
		}
		
		//}
		
		
	}
})(jQuery);


