(function($){
    $.fn.singleSlide = function(options) {
        // 初期値を設定
        var defaults = {
            'moveWidth' : "585",
            'duration' : 800,
            'target'    : '#layout_photo_other',
            'infoSelector'    : '#photo_other_info',
            'prevSelector' : '.other_navi_prev',
            'nextSelector' : '.other_navi_next'
        };
        
        // オプションの初期値を設定
        var setting = $.extend(defaults, options);
        var targetUL = $("ul:not('.typelink')" ,$(setting.target));
        var listImg = $("img:not('.typelink')" ,targetUL);
        
        var completeFunc = true;
        var countList = $("li:not('.typelink')",targetUL).length;
        var currentListNo = 1;
        
        // 初期化メソッド
        var init = function(){
        
            $('.typelink').attr("style","cursor:pointer;cursor:hand;margin:0;padding:0;");
        
            listImg.each(function() {
                $(this).attr("class","other_navi_next");
                $(this).attr("style","cursor:pointer;cursor:hand;margin:0;padding:0;");
            });
            printInfo();
            return;
        }
        
        
        var next = function() {
        
            if(countList > currentListNo){
                if(completeFunc){
                
                    var defVal = targetUL.css("margin-left");
                    var val = defVal.replace( /[^-0-9\s]+/g, '' ).split( /\s+/ );
                    var moveVal = (parseInt(val) + parseInt(-1 * setting.moveWidth)) + "px";
                
                    completeFunc = false;
                    targetUL.animate({
                        marginLeft: moveVal
                    },{
                        duration: setting.duration,
                        complete: function(){completeFunc = true;}
                    });
                    currentListNo = currentListNo + 1;
                    printInfo();
                }
            } else {
                reset();
            }
            return;
        };
        
        
        // プラグインで使用するメソッド
        var prev = function() {
        
            if(countList >= currentListNo && currentListNo > 1){
                if(completeFunc){
                
                    var defVal = targetUL.css("margin-left");
                    var val = defVal.replace( /[^-0-9\s]+/g, '' ).split( /\s+/ );
                    var moveVal = (parseInt(val) + parseInt(setting.moveWidth)) + "px";
            
            
                    completeFunc = false;
                    targetUL.animate({
                        marginLeft: moveVal
                    },{
                        duration: setting.duration,
                        complete: function(){completeFunc = true;}
                    });
                    currentListNo = currentListNo - 1;
                    printInfo();
                }
            } else {
                reset();
            }
            return;
        };
        
        var changePointer = function(){
            if($(this).attr("style")){
                $(this).attr("style",$(this).attr("style")+"cursor:pointer;cursor:hand;");
            } else {
                $(this).attr("style","cursor:pointer;cursor:hand;");
            }
            
            return;
        }
        
        
        var reset = function() {
            targetUL.animate({marginLeft: "0"},setting.duration);
            currentListNo = 1;
            printInfo();
            return;
        }
        
        
        var last = function() {
        
            var moveVal = (-1* (parseInt(countList)-1) * parseInt(setting.moveWidth)) + "px";
            targetUL.animate({marginLeft: moveVal},setting.duration);
            currentListNo = countList;
            printInfo();
            
            return;
        }
        
        var printInfo = function() {
            $(setting.infoSelector).html("page " + currentListNo + " / " + countList );
            return;
        }
        
        
        // セレクタで指定した要素を処理
        
        init();
        
        
        //イベントディスパッチ
        this.each(function() {
            $(setting.prevSelector).click(prev);
            $(setting.nextSelector).click(next);
            
            $(setting.prevSelector).hover(changePointer);
            $(setting.nextSelector).hover(changePointer);
        });
        
        

        // メソッドチェーン用
        return this;
    };
})(jQuery);


jQuery(function(){
    var singleSleide = jQuery("#layout_photo_other").singleSlide();
});
