var virtualTop = 0;
// メニュー、検索パネル制御用ハッシュ
var panel_status = {
    menu : 0,
    body : 0,
    tile_body : 1,
    example_body : 0,
    tile1 : 0,
    tile2 : 0
}
var removeHttpString = function(str){
    return str.replace('https://' , '').replace('http://' , '');
}

/**
 * URLからコントローラー名、アクション名を取得
 */
var getContAction = function(){
    var url_array = removeHttpString(document.URL).split('/');
    var cont_action = {
        cont : '' ,
        action : ''
    };
    if(url_array[1]) {
        cont_action.cont = url_array[1];
    } else {
        cont_action.cont = 'default';
    }

    if(url_array[2]) {
        cont_action.action = url_array[2];
    } else {
        cont_action.action = 'default';
    }
    return cont_action;
};

var isIE7 = function(){
    if(!jQuery.support.opacity){
        if(!jQuery.support.style){
            if (typeof document.documentElement.style.maxHeight != "undefined") {
                return true;
            }
        }
    }
    return false;
}
var isIE6 = function(){
    if(!jQuery.support.opacity){
        if(!jQuery.support.style){
            if (typeof document.documentElement.style.maxHeight == "undefined") {
                return true;
            }
        }
    }
    return false;
};

$(function(){
    // init
    // 検索パネル
    $("div.slide_search_body").hide();
    $("div.tile_search").show();
    $("div.tile_menu1").hide();
    $("div.tile_menu2").hide();
    $("div.example_search").hide();
    $("p.search_clear p.menu_close p.search_execute").css("cursor" , "pointer");
    // グローバルメニュー
    $("div.global_menu").hide();

    // グローバルメニューのオープン
    $("a.menu_open").click(function(){
        if(panel_status.menu == 1) {
            $("div.global_menu").slideUp("fast");
            panel_status.menu = 0;
        } else {
            $("div.global_menu").slideDown("fast");
            panel_status.menu = 1;
        }
        return false;
    });
    // グローバルメニュー閉じる
    $("a.menu_close").click(function(){
        $("div.global_menu").slideUp("fast");
        panel_status.menu = 0;
        return false;
    });

    // 検索パネルのオープン
    $("a.search_open").click(function(){
        if(panel_status.body == 1) {
            $("div.slide_search_body").slideUp("fast");
            panel_status.body = 0;
        } else {
            $("div.slide_search_body").slideDown("fast");
            panel_status.body = 1;
        }
        return false;
    });
    // 施工例検索のオープン
    $("a.example_search_open").click(function(){
        if(panel_status.example_body == 1) {
            return false;
        }
        $("div.tile_search").slideUp("fast" , function(){
            $("div.example_search").slideDown("fast");
        });
        // 画像切替
        $("img.tile_search_image").attr("src" , "/images/common/img_search_ttl_item.gif");
        $("img.example_search_image").attr("src" , "/images/common/img_search_ttl_case_a.gif");
        panel_status.tile_body = 0;
        panel_status.example_body = 1;
        return false;
    });
    // タイル例検索のオープン
    $("a.tile_search_open").click(function(){
        if(panel_status.tile_body == 1) {
            return false;
        }
        $("div.example_search").slideUp("fast" , function(){
            $("div.tile_search").slideDown("fast");
        });
        // 画像切替
        $("img.tile_search_image").attr("src" , "/images/common/img_search_ttl_item_a.gif");
        $("img.example_search_image").attr("src" , "/images/common/img_search_ttl_case.gif");
        panel_status.tile_body = 1;
        panel_status.example_body = 0;
        return false;
    });
    // タイル検索メニュー1オープン
    $("a.tile_menu1_open").click(function(){
        if(panel_status.tile1 == 1) {
            $("div.tile_menu1").slideUp("fast");
            $("img.arrow_b1").attr("src", "/images/search/img_arrow_b_open.gif");
            panel_status.tile1 = 0;
        } else {
            $("div.tile_menu1").slideDown("fast");
            $("img.arrow_b1").attr("src", "/images/search/img_arrow_b_close.gif");
            panel_status.tile1 = 1;
        }
        return false;
    });
    // タイル検索メニュー2オープン
    $("a.tile_menu2_open").click(function(){
        if(panel_status.tile2 == 1) {
            $("div.tile_menu2").slideUp("fast");
            $("img.arrow_b2").attr("src", "/images/search/img_arrow_b_open.gif");
            panel_status.tile2 = 0;
        } else {
            $("div.tile_menu2").slideDown("fast");
            $("img.arrow_b2").attr("src", "/images/search/img_arrow_b_close.gif");
            panel_status.tile2 = 1;
        }
        return false;
    });

    // 検索実行
    $("p.search_execute").click(function(){
        if(panel_status.example_body == 1) {
            $("div.example_search form").submit();
        } else if(panel_status.tile_body == 1) {
            $("div.tile_search form").submit();
        }
        return false;
    });
    // 検索パネル閉じる
    $("p.search_close").click(function(){
        $("div.slide_search_body").slideUp("fast");
        panel_status.body = 0;
        return false;
    });
    // 検索条件のクリア
    $("p.search_clear").click(function(){
        if(panel_status.tile_body == 1) {
            // タイル検索の条件クリア
            $("input#SearchCode").val("");
            $("input#SearchTileName").val("");
            $("input:[type=radio]").attr("checked" , false);
            // セレクトの解除
            $("div.tile_search form select").each(function(){
                this.selectedIndex = 0;
            });
        } else if(panel_status.example_body == 1){
            // 施工例検索の条件クリア
            // セレクトの解除
            $("div.example_search form select").each(function(){
                this.selectedIndex = 0;
            });

        }
        return false;
    });
    $("#SearchCode , #SearchTileName").keypress(function(e){
        // Enter押下時に実行
        if(e.which == 13){
            if(panel_status.example_body == 1) {
                $("div.example_search form").submit();
            } else if(panel_status.tile_body == 1) {
                $("div.tile_search form").submit();
            }
        }
    });
});

function IE6FooterFix(fixed_number , left_fix){
    var $footer = $('div#footer').css({'position':'absolute','top':0,'left':0});
    var IE_space = $(window).height();
    $footer.css('top' , $(document).scrollTop() + IE_space - fixed_number);
    $(window).scroll(function(){
        $footer.css('top' , $(document).scrollTop() + IE_space - fixed_number);
    });
    $(window).resize(function(){
        IE_space = $(window).height();
        $footer.css('top' , $(document).scrollTop() + IE_space - fixed_number);
    });
    if(left_fix === true) {
        $footer.css('left' , "-16");
    }
}
function IE6FooterFix4(fixed_number , left_fix){
    var $footer = $('div#footer').css({'position':'absolute','top':0,'left':0});
    var IE_space = $(window).height();
    $footer.css('top' , IE_space - fixed_number);
    $(window).scroll(function(){
        $footer.css('top' ,IE_space - fixed_number);
    });
    $(window).resize(function(){
        IE_space = $(window).height();
        $footer.css('top' ,IE_space - fixed_number);
    });
    if(left_fix === true) {
        $footer.css('left' , "-16");
    }
}

function IE6FooterFix2(left_fix) {
    var $footer = $('div#footer');
    if(left_fix === true) {
        $footer.css('left' , "-16");
    }
}

function IE6FooterFix3(left_fix) {
    if(!isIE6()) return ;
    var $footer = $('div#footer').css({'position':'absolute','top':0,'left':0});
    if(left_fix === true) {
        $footer.css('left' , "-16");
    }
    $footer.css('top' , $(document).height() - $footer.height());
    if(left_fix === true) {
        $footer.css('left' , "-16");
    }
}

