//////////////////////////////////////////////////////////////////
/// 左ナビ開閉
//////////////////////////////////////////////////////////////////

/*
初期設定
----------------------------------------------------------------------*/
var DOC=document;

/*レフトナビ名
---------------------------------------------------*/
var lMUlObj='leftMenuOpenable';//カテゴリ枠ul要素
var lMUlONum='lMOLimitNum_';//カテゴリ枠ul要素
var lMLiCurObj='soatSet';//カレントli要素

/*スピード設定
---------------------------------------------------*/
var speedLMM=100;
var speedLML=200;

/*メニュー開閉しきい値上下限
---------------------------------------------------*/
var limNumMin=2;
var limNumMax=100;


/*
メインプロトコル
----------------------------------------------------------------------*/
$(DOC).ready(setLeftMenu);
function setLeftMenu(){
    $('.'+lMUlObj).each(function(){
// 初期表示数抽出
        var oClass=$(this).attr('class');
        var limitNum;
        // 全部見る・閉じるリンクの動作可否を制御する
        var noOpen=false;
        // 選択された項目のみを表示する
        var showSelectedOnly=false;
        // 標準表示
        if(oClass.indexOf(lMUlONum)!=-1){
            limitNum=oClass.slice(eval(oClass.indexOf(lMUlONum))+eval(lMUlONum.length),oClass.length);
            if(oClass.match('.*_noOpen')){
                limitNum=oClass.slice(eval(oClass.indexOf(lMUlONum))+eval(lMUlONum.length),oClass.indexOf('_noOpen'));
                noOpen=true;
            }
        // 選択された項目のみ
        }else if(oClass.indexOf("selectedOnly")!=-1){
            showSelectedOnly=true;
            if(oClass.match('.*_noOpen')){
                noOpen=true;
            }
        }

        limitNum=(limitNum<limNumMin)?limNumMin:limitNum;
        limitNum=(limitNum>limNumMax)?limNumMax:limitNum;
// 初期動作
        if($(this).find('li').size()<=limitNum){
            $(this).find('p').hide();
            $(this).next('p').hide();
            $(this).show();
            return;
        }
        $(this).find('li').hide();
        $(this).find('p').hide();
        $(this).show();

        if(showSelectedOnly) {
            $(this).next('p').hide();
// 開く
            if(!noOpen){
                $(this).next('p').click(function(){
                    if(!nUAuIE7) $(this).prev().find('ul').hide();
                    $(this).prev().find('li').show();
                    $(this).prev().find('li').css('display','block');
                    $(this).prev().find('p').fadeIn(speedLML);
                    $(this).prev().find('ul').fadeIn(speedLML);
                    $(this).hide();
                });
            }
            //if($(this).children('ul').children().hasClass(lMLiCurObj)){
            if($(this).children('ul').children().hasClass(lMLiCurObj)){
                $(this).find('ul').hide();
                //ジャンル選択時に例外になるもの（レフティ）
                $(this).find('#no_hide').show();
                $(this).find('#no_hide').find('ul').show();
                $(this).find('#no_hide').find('li').show();
                //選択項目の配下のulを表示
                $(this).find('.'+lMLiCurObj).parent('ul').show();
                $(this).find('.'+lMLiCurObj).find('ul').show();
                //選択項目の配下のliを表示
                $(this).find('.'+lMLiCurObj).show();
                $(this).find('.'+lMLiCurObj).children().find('li').show();
                $(this).next('p').show();
// 閉じる ： 選択項目ある場合
                if(!noOpen){
                    $(this).find('p').click(function(){
                        $(this).parent().find('ul').hide();
                        $(this).parent().find('li').hide();
                        //選択項目の配下のulを表示
                        $(this).parent().find('.'+lMLiCurObj).parent('ul').show();
                        $(this).parent().find('.'+lMLiCurObj).find('ul').show();
                        //選択項目の配下のliを表示
                        $(this).parent().find('.'+lMLiCurObj).show();
                        $(this).parent().find('.'+lMLiCurObj).children().find('li').show();

                        $(this).hide();
                        $(this).parent().next('p').fadeIn(speedLML);
                        $(this).parent().show();
                    });
                }
            }else{
// 閉じる ： 選択項目ない場合
                $(this).find('li').show();
            }
        }else{
// 開く
            if(!noOpen){
                $(this).next('p').click(function(){
                    if(!nUAuIE7) $(this).prev().find('ul').hide();
                    $(this).prev().find('li').show();
                    $(this).prev().find('li').css('display','block');
                    $(this).prev().find('p').fadeIn(speedLML);
                    $(this).prev().find('ul').fadeIn(speedLML);
                    $(this).hide();
                });
            }
            //if($(this).children('ul').children().hasClass(lMLiCurObj)){
            if($(this).children('ul').children().hasClass(lMLiCurObj)){
                $(this).find('.'+lMLiCurObj).show();
                for(var i=0;i<limitNum;i++){
                    $(this).find('li').eq(i).show();
                }
// 閉じる ： 選択項目ある場合
                if(!noOpen){
                    $(this).find('p').click(function(){
                        $(this).parent().find('li').hide();
                        $(this).parent().find('.'+lMLiCurObj).show();
                        for(var i=0;i<limitNum;i++){$(this).parent().find('li').eq(i).show();}
                        $(this).hide();
                        $(this).parent().next('p').fadeIn(speedLML);
                        $(this).parent().show();
                    });
                }
            }else{
                for(var i=0;i<limitNum;i++){
                    $(this).find('li').eq(i).show();
                }
// 閉じる ： 選択項目ない場合
                if(!noOpen){
                    $(this).find('p').click(function(){
                        $(this).parent().find('li').hide();
                        for(var i=0;i<limitNum;i++){$(this).parent().find('li').eq(i).show();}
                        $(this).hide();
                        $(this).parent().next('p').fadeIn(speedLML);
                        $(this).parent().show();
                    });
                }
            }
        }

    });
}


/*
ブラウザ判定
----------------------------------------------------------------------*/
var nUA=navigator.userAgent;

/*IE
---------------------------------------------------*/
var nUAuIE=nUA.indexOf("MSIE ")!=-1;

/*IE 7以下判定
---------------------------------------------------*/
var nUAuIE7=nUA.slice(nUA.indexOf("MSIE ")+"MSIE ".length,nUA.indexOf("MSIE ")+"MSIE ".length+1)<8;








