/* =============================================================================
	スライドショー 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	: 6000,
			interval_min	: 6000,
			interval_reset  : 18000,
			interval_max	: 10000,
			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;
		var initialize = false;

		$(this).find("li").not(":eq(" + current + ")").hide();

			$("#bt_green").click(function(){
				clearTimeout(TimerID);
				click_check = true;
				bt_current = 0;
				bt_animation();
				//animation();
			}
			);
			$("#bt_right_green").click(function(){
				clearTimeout(TimerID);
				click_check = true;
				bt_current = 1;
				current = current;
				bt_animation();
				//animation();
			}
			);
//			$("#bt_red").click(function(){
//				clearTimeout(TimerID);
//				click_check = true;
//				bt_current = 2;
//				current = current;
//				bt_animation();
				//animation();
//			}
//			);
//			
//			$("#bt_brack").click(function(){
//				clearTimeout(TimerID);
//				click_check = true;
//				bt_current = 3;
//				current = current;
//				bt_animation();
				//animation();
//			}
//			);
//

		if(settings.action == "auto") {
			intervalmode_check();
		}else if(settings.action == "click"){
			$(this).click(animation);
		}

		function intervalmode_check(initialize) {

			bt_color(current);

			if(settings.interval_mode == "normal") {
				if(initialize == true){
					TimerID = setTimeout(animation, settings.interval_reset);
					initialize = false;
				}else{
					//TimerID;
					if(current == 1){
						TimerID = setTimeout(animation, settings.interval_min);
					}else{
						TimerID = setTimeout(animation, settings.interval_normal);
					}
				}
			} 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{
				
				}
				
			}
			
		}

		/* ↓ ボタンが押された時のアニメーション ↓ */
		function bt_animation() {
			
			var prev = $(_root).find("li").eq(current);
			
			var next = $(_root).find("li").eq(bt_current);
			
			if(settings.animation == true) {
				prev.fadeOut(settings.fadespeed);
				next.fadeIn(settings.fadespeed);
			} else {
				prev.hide();
				next.show();
			}

			current = bt_current;/* 現在のカレントを保持 */

			bt_color(bt_current);

			click_check = false;/* 元に戻す処理 */

			initialize = true;/* 初期化 */

			intervalmode_check(initialize);
			

		}

		/* ↓ ボタンの透明度 ↓ */
		function bt_color(current){
		
					switch(current){
						case 0:
							document.getElementById('bt_green').className = 'op100';
							document.getElementById('bt_right_green').className = 'op30';
//							document.getElementById('bt_red').className = 'op30';
//							document.getElementById('bt_brack').className = 'op30';
							/*
							document.getElementById('bt_blue').className = 'op30';
							document.getElementById('bt_orange').className = 'op30';
							*/
							break;
						case 1:
							document.getElementById('bt_green').className = 'op30';
							document.getElementById('bt_right_green').className = 'op100';
//							document.getElementById('bt_red').className = 'op30';
//							document.getElementById('bt_brack').className = 'op30';
							/*
							document.getElementById('bt_blue').className = 'op30';
							document.getElementById('bt_orange').className = 'op30';
							*/
							break;
//						case 2:
//							document.getElementById('bt_green').className = 'op30';
//							document.getElementById('bt_right_green').className = 'op30';
//							document.getElementById('bt_red').className = 'op100';
//							document.getElementById('bt_brack').className = 'op30';
							/*
							document.getElementById('bt_blue').className = 'op30';
							document.getElementById('bt_orange').className = 'op30';
							*/
							break;
//						case 3:
//							document.getElementById('bt_green').className = 'op30';
//							document.getElementById('bt_right_green').className = 'op30';
//							document.getElementById('bt_red').className = 'op30';
//							document.getElementById('bt_brack').className = 'op100';
							/*
							document.getElementById('bt_blue').className = 'op30';
							document.getElementById('bt_orange').className = 'op30';
							*/
//							break;

					}
		}

		/* ↓ オブジェクトの中身を見るIE用 ↓ */
		function showObject(elm,type){
			var str = '「' + typeof elm + "」の中身";
			var cnt = 0;
			for(i in elm){
			if(type == 'html'){
			str += '<br />\n' + "[" + cnt + "] " + i.bold() + ' = ' + elm[i];
			}
			else {
			str += '\n' + "[" + cnt + "] " + i + ' = ' + elm[i];
			}
			cnt++;
			status = cnt;
			}
			return str;
		}

		/* ↓ 拡大表示 ↓ */
		/*
		$(function() {  

	    $('ul#button li img')  

	     .hover(  

	         function(){  

	             $(this).stop().animate({  

	                 'width':'93px',  

	                 'height':'93px',  

	                 'marginTop':'-47px'
	                 

	             },'fast');  

	         },  

	         function () {  

	             $(this).stop().animate({  

	                 'width':'31px',  

	                 'height':'31px',  

	                 'marginTop':'0px',
	                 

	             },'fast');  

	         }  

	     );  


		 });
		*/
		 /* ↑ 拡大表示 ↑ */


	}
})(jQuery);


