/* $Id: ready_func.js 1376 2010-12-27 04:33:04Z f-kinjou $ */

//画面表示時
$(document).ready(
    function(){
        var prtcl = location.protocol;
        var ghost = location.host;
        var rootDir = prtcl + '//' + ghost + '/';
        //var rootDir = prtcl + '//' + ghost + '/lequio/html/';

        //IEの判定
        var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;

        /************************/
        /** 外部jsはここに追加 **/
        /************************/

        //head内にjsへのリンクを追加する
        setOuters(rootDir + "js/navi.js");
        setOuters(rootDir + "contact/mailform.js");

        //detail.phpのみ有効
        if (isDetailPhp()) {setOuters(rootDir + "js/detail.js");}

        //角丸（IEは不可）
        if(!isIE){ setOuters(rootDir + "js/jquery.corner.js");}

        /******************************/
        /** 読み込む関数はここに追加 **/
        /******************************/
        //ポータルのメニュープルダウン(navi.js)
        ctrlNavi();

        //画面遷移時のエフェクト
        if(isEnterPhp(rootDir) ){
            $('#mainBody h2').fadeIn(1000);
            $('#mainBody ul').fadeIn(1000);
        }

        if(isChronos()){
            var altStr;
            var pos;
            $('div#naviOnTips img').mouseover(function(){

                this.src = this.src.replace('_off','_on');
                var imgNum = $('div#naviOnTips img').index(this);
                switch (imgNum) {
                    case 0:
                        pos = '-135';
                        break;
                    case 1:
                        pos = '-45';
                        break;
                    case 2:
                        pos = '45';
                        break;
                    case 3:
                        pos = '135';
                        break;
                }
//                if(imgNum == 0){ pos = '-100'; } else if(imgNum == 1) { pos = 0;} else { pos = 100; }
                altStr = this.alt;
                $('div#naviOnTips br.instAft').after('<div class="onTips" style="left:' + pos + 'px">' + altStr + '</div>');
                $('div.onTips').fadeIn(500);
            });
            $('div#naviOnTips img').mouseout(function(){
                this.src = this.src.replace('_on','_off');
                altStr = this.alt;
                $('div.onTips').remove();
            });
        }

        if(isChronos() && isIndexPhp()) {
            $('div.areaRight a#timenets').mouseover(function(){
                $('div.areaRight a#timenets img').toggle();
            });
            $('div.areaRight a#timenets').mouseout(function(){
                $('div.areaRight a#timenets img').toggle();
            });
        }

        //kss用（主に画面）
        if(isKssPhp() && isDetailPhp()){
            var sysParam;
            if(this.URL.indexOf('sysConf') != -1){
                sysParam = 'sysConf';

            } else if(this.URL.indexOf('sysFunc') != -1){
                sysParam = 'sysFunc';

            } else {
                sysParam = 'def';
            }
            kssDetailSwap(sysParam);
            $('ul#dtlNav a#' + sysParam).addClass('act');
            $('ul#dtlNav a:not(#' + sysParam + ')').removeClass('act');

            $('ul#dtlNav a').click(function(){
                if(this.id == 'sysConf'){
                    sysParam = 'sysConf';

                } else if(this.id == 'sysFunc'){
                    sysParam = 'sysFunc';

                } else if(this.id == 'sysReq'){
                    sysParam = 'sysReq';
                }
                kssDetailSwap(sysParam);
                $('ul#dtlNav a#' + sysParam).addClass('act');
                $('ul#dtlNav a:not(#' + sysParam + ')').removeClass('act');
            });

            $('table#confTable a').click(
                function(){
                    var idx = $('th').index(this.parentNode);
                    $('img.dispNone:eq(' + idx + ')').slideToggle(500);
                }
            );
        }

        //詳細ページナビ&lightbox
        if (isDetailPhp()) {

            var isAct = false;
            var dispNum;
            var navi;
            var lbLeng = $('ol#detailList li').length;
            if(lbLeng < 2){
                $('div.lbNext, div.lbPrev').hide();
            }
            $('ol#detailList li a').click(
                function(){
                    dispNum = parseInt($(this).attr("value"), 10);
                    navi = false;
                    isAct = lbNavi(navi, dispNum, lbLeng);
                    $(this).addClass('act');
                    $('a[value=' + dispNum + ']',this).addClass('act');
                    $('a[value!=' + dispNum + ']',this).removeClass('act');
                }
            );
            $('div[id^=dtl] div').click(
                function(){
                    dispNum = this.offsetParent.id;
                    dispNum = parseInt(dispNum.replace('dtl', ''), 10);
                    navi = $(this).attr('class');
                    isAct = lbNavi(navi, dispNum, lbLeng);
                    if(isAct && isAct != 'here'){
                        $('#detailList li a[value=' + isAct + ']').addClass('act');
                        $('#detailList li a[value!=' + isAct + ']').removeClass('act');
                    } else if(isAct == 'here') {

                    } else {
                        $('#detailList li a').removeClass('act');
                    }
                }
            );

        }// end

        //痛快シフト　トップ画像スライド関数
        if (isShift()){ksImageSlide();}

        //メールフォームで使用(contact/mailform.js)
        if (isContactPhp()) {resumeField('mailform');}

        // demo.php用関数
        if (isDemoPhp() && !isIE) {$("div#appDemo table th, div#appDemo table td").corner();}

        // price.php用関数
        if (isPricePhp()) {
//            $("div#appPrice table tr:odd").css('background-color', '#ffffff');
            $("div#appPrice table tr:odd td").css('background-color', '#ffffff');
//            $("div#appPrice table td").css('background', 'none');
        }

        // index.php用関数
        if (isIndexPhp() && !isIE) { $("div[class^='pointArea'] > div").corner("20px"); }

        //ksTabsタブ使う場合
        if (isPvcPhp() || isDemoPhp() || isSupport() || isDetailPhp() || (isShift() && isPricePhp())) {

            if($('input#tabSelected').val() == 2) {
                $('#pvcTabs > div:not(#pvcTab3)').hide();
                $('#pvcTabs ul li:eq(2)').addClass('tabAct');
            } else if($('input#tabSelected').val() == 1) {
                $('#pvcTabs > div:not(#pvcTab2)').hide();
                $('#pvcTabs ul li:eq(1)').addClass('tabAct');
            } else {
                $('#pvcTabs > div:not(#pvcTab1)').hide();
                $('#pvcTabs ul li:eq(0)').addClass('tabAct');
            }

            $('#pvcTabs > ul li').attr('data-corner','top 5px');
            if(!isIE){ $('#pvcTabs > div,#pvcTabs > ul li').corner('keep'); }

            $('#pvcTabs ul li').click(
                function(){
                    var cnt = $('#pvcTabs ul li').index(this);
                    $('#pvcTabs ul li').removeClass('tabAct');
                    $('#pvcTabs ul li:eq(' + cnt + ')').addClass('tabAct');

                    cnt += 1;
                    $('#pvcTabs > div#pvcTab' + cnt).fadeIn(500);
                    $('#pvcTabs > div:not(#pvcTab' + cnt + ')').hide();
                }
            );
        }

        // ログイン
        if (isLoginPhp()) {
            $(':input[name="loginId"]').keypress(function(e){
                if (e.keyCode == 13) {
                    $(':password').focus();
                }
            });
            $(':password').keypress(function(e){
                if (e.keyCode == 13) {
                    $(':button').focus();
                }
            });
        }
    }
);

var tabClick = function(cnt){
	$('#pvcTabs ul li').removeClass('tabAct');
	$('#pvcTabs ul li:eq(' + cnt + ')').addClass('tabAct');
	$('#pvcTabs ul li:eq(' + cnt + ')').focus();
    cnt += 1;
    $('#pvcTabs > div#pvcTab' + cnt).fadeIn(500);
    $('#pvcTabs > div:not(#pvcTab' + cnt + ')').hide();
};


/**
 * scriptタグの動的書き出し
 * @param scriptPath
 * @return
 */
function setOuters(scriptPath) {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = scriptPath;
    $('head > script:last').after(script);
}

/**
 * 各画面の判定
 *
 */
function isDetailPhp() {
    return (location.pathname.indexOf('detail.php') != -1);
}
function isEnterPhp(root) {
    var urlSplit = location.href.split(root);
    if(urlSplit[1] == '' || urlSplit[1] == 'index.php'){
        return true;
    } else {
        return false;
    }
}
function isContactPhp(str) {
    var url = location.pathname||str;
    return (url.indexOf('contact/index.php') != -1);
}
function isKssPhp() {
    return (location.pathname.indexOf('kss/') != -1);
}
function isDemoPhp() {
    return (location.pathname.indexOf('demo.php') != -1);
}
function isPricePhp() {
    return (location.pathname.indexOf('price.php') != -1);
}
function isLoginPhp() {
    return (location.href.indexOf('login.php') != -1);
}
function isIndexPhp() {
    return (location.href.indexOf('index.php') != -1);
}
function isPvcPhp() {
    return (location.href.indexOf('privacy.php') != -1);
}
function isSupport() {
    return (location.href.indexOf('support.php') != -1);
}
function isShift() {
    return (location.href.indexOf('t_shift/') != -1);
}
function isChronos() {
    return (location.href.indexOf('chronos/') != -1);
}

/**
 * ページのフェード効果
 * @param time
 * @return
 */
function onloadFade(time){
    $('body').hide();
    $('body').fadeIn(time);
}

/**
 * ライトボックス内のナビゲーション
 * @param className
 * @return
 */
function lbNavi(clsName, num, last){
    var fixNum;
    var lbOption = ".lbClose, .lbNext, .lbPrev";

    switch(clsName){
        case 'lbPrev':
            fixNum = num - 1;
            break;

        case 'lbNext':
            fixNum = num + 1;
            break;

        case 'lbHere':
            return 'here';

        case false:
            fixNum = num;
            break;

        default:
            return false;

    }

    if(fixNum == 1){ $("div.lbPrev").hide(); } else { $("div.lbPrev").show(); }
    if(fixNum == last){ $("div.lbNext").hide(); } else { $("div.lbNext").show(); }

    $("div#dtl0" + fixNum).lightbox_me({
        lightboxSpeed:'normal',
        closeSelector:lbOption,
        closeOverlay:false
    });

    return fixNum;

}

/**
 * 画像スライドショー
 * （規定の構造のhtmlで書かれていることが前提）
 */
function ksImageSlide() {

    //クリック要素
    var navElem = $('div#imgToggle').parent().children('a');
    //画像サイズ
    var imgSize = $('div#imgToggle > ul li > img').width();
    //最後の画像の位置
    var imgEnd = parseInt($('div#imgToggle > ul').width()) - imgSize;
    //初期の画像位置
    var defL = parseInt($('div#imgToggle > ul').css('left'));
    //修正後の画像位置
    var fixL;
    //二重実行禁止用
    var timeout;
    //アニメーションスピード(兼 二重実行禁止の目安)
    var timer = 400;
    //オートスライド
    var auto = false;

    $('a[title=prev]').css('visibility', 'hidden');

    if(!timeout || timeout < 1) {
      timeout = timer;
    }

//	if(auto){
//		for(var i=1; i<4; i++){
//			setTimeout(
//				function(){
//					$('a[title=next]').click();
//				}
//				,i * 3000
//			);
//		}
//	}
    if(auto){
    setTimeout(
                function(){
                    $('a[title=next]').click();
                }
                ,3000
            );
    }
    //二重クリック禁止
    navElem.bind("click",function() {

        navElem.css('visibility', 'hidden');
        setTimeout(
            function(){
                navElem.css('visibility', '');
              }
            ,timeout
        );
    });

    //スライド実行
    navElem.click(
        function(){

            //ナビゲーションタイトル
            var nav = $(this).attr('title');

            //※クリック時の※初期画像位置
            defL = parseInt($('div#imgToggle > ul').css('left'));

            switch(nav){
                case 'prev':
                    if(defL == 0){ return false; }
                    fixL = defL + imgSize;
                    break;

                case 'next':
                    if(Math.abs(defL) >= imgEnd){ return false; }
                    fixL = defL - imgSize;
                    break;

                default:
                    return false;
            }
            //スライド実行
            $('div#imgToggle > ul').animate({left:fixL}, timer, function(){
                if(fixL == 0){
                    $('a[title=prev]').css('visibility', 'hidden');
                } else if(Math.abs(fixL) >= imgEnd) {
                    $('a[title=next]').css('visibility', 'hidden');
                } else {
                    $(this).css('visibility', '');
                }

            });

        }
    );
}


function kssDetailSwap(sysParam){
    var spd = 400;
    switch(sysParam){

    case 'sysConf':
    default:
        $('h2#confTitle, h2#confTitle + p, h2#confTitle + p + table').fadeIn(spd);
        $('h2#sysTitle, h2#sysTitle + div').hide();
        $('h2#specTitle, h2#specTitle + p, div#pvcTabs').hide();
        break;

    case 'sysFunc':
        $('h2#confTitle, h2#confTitle + p, h2#confTitle + p + table').hide();
        $('h2#sysTitle, h2#sysTitle + div').fadeIn(spd);
        $('h2#specTitle, h2#specTitle + p, div#pvcTabs').hide();
        break;

    case 'sysReq':
        $('h2#confTitle, h2#confTitle + p, h2#confTitle + p + table').hide();
        $('h2#sysTitle, h2#sysTitle + div').hide();
        $('h2#specTitle, h2#specTitle + p, div#pvcTabs').fadeIn(spd);
        break;

    }
}

