/*

	ImageChanger ver2.0 for jQuery(gt Ver 1.3.2) 
	Developped  by Coichiro Aso
	Copyright Codesign.verse 2009　http://codesign.verse.jp/
	Licensed under the MIT license:http://www.opensource.org/licenses/mit-license.php/

	コピーライト書いてますが、削除しない限り
	ご自由にお使い頂けます
	ただし使用の際は、自己責任でお願いします。

-------------------------------------------------------------------------------------------*/

/*note
やばいー！jQueryってなんだ？ってレベルでいろいろ忘れてるぜ！おれ大丈夫じゃないな！
というくらいの新作です。
------------------------------------------------------------------------------------------*/
(function($) {

    $.fn.imgchanger = function(options) {

        //オプション設定
        var defaults = {
            speed: 500,
            fimg: 0
        };

        //変数・定数設定
        var options = $.extend(defaults, options);
        var target = $(this);
        var bimg = $("#mainimgs li img");
        var bban = $("#num img");
        var bban2 = $("#banimgs li img");
        var ids = 0;
        var ids2 = 0;
        var ids3 = 0;
        var fimg = 0;
        var timer;

        function Load() {
            fimg = options.fimg;
            bimg.hide();

            if (ids < fimg) {
                if (ids == 0) {
                    ids2 = fimg - 1;
                } else {
                    ids2 = ids - 1;
                }

                $(bban[ids2]).attr("src", $(bban[ids2]).attr("src").replace('_on', "_off"));
                $(bban[ids]).attr("src", $(bban[ids]).attr("src").replace('_off', "_on"));
                $(bimg[ids]).fadeIn(options.speed);
                ids = ids + 1;
                clearTimeout(timer);
                timer = setTimeout(eval("Load"), "5000");
            } else {
                ids = 0;

                if (ids == 0) {
                    ids2 = fimg - 1;
                } else {
                    ids2 = ids - 1;
                }
                $(bban[ids2]).attr("src", $(bban[ids2]).attr("src").replace('_on', "_off"));
                $(bban[ids]).attr("src", $(bban[ids]).attr("src").replace('_off', "_on"));
                $(bimg[ids]).fadeIn(options.speed);
                ids = ids + 1;
                clearTimeout(timer);
                timer = setTimeout(eval("Load"), "5000");
            }
        }

        bban.hover(
            //マウスオーバー時
	        function() {
	            clearTimeout(timer);
	            ids3 = $(this).attr("class");
	            bimg.hide();
	            $(bban[ids3]).attr("src", $(bban[ids3]).attr("src").replace('_off', "_on"));
	            $(bimg[ids3]).fadeIn(options.speed);
	        },
            //マウスアウト時
	        function() {
	            $(bban[ids3]).attr("src", $(bban[ids3]).attr("src").replace('_on', "_off"));
	            clearTimeout(timer);
	            timer = setTimeout(eval("Load"), "5000");
	        }
	    );

        bimg.hover(
            //マウスオーバー時
	        function() {
                clearTimeout(timer);
	        },
            //マウスアウト時
	        function() {
	            clearTimeout(timer);
	            timer = setTimeout(eval("Load"), "5000");
	        }
        );

        Load();


    }
})(jQuery);
