﻿$(document).ready(function () {

    if ($.browser.msie) {
        var version = parseInt($.browser.version, 10);
        if (version < 8) {
            $("link[rel=stylesheet]").attr({ href: "/css/main_IE7.css" });
        }
    }

    var currentWidth = document.documentElement.clientWidth;
    var currentHeight = document.documentElement.clientHeight;

    SetHeight(currentHeight);

    if (currentWidth > 1280) {

        $(".main").width(currentWidth);

        var extraWidth = ((currentWidth - 1280) / 2) + "px";
        var extraWidthLeftMenu = (((currentWidth - 1280) / 2) + 300) + "px";
        var extraWidthLeftFooter = (((currentWidth - 1280) / 2) + 30) + "px";

        $(".main_head").css("margin-left", extraWidth);
        $(".main_head").css("margin-right", extraWidth);
        $(".main_menu").css("margin-left", extraWidthLeftMenu);
        $(".main_menu").css("margin-right", extraWidth);
        $(".main_foot").css("margin-left", extraWidthLeftFooter);
        $(".main_foot").css("margin-right", extraWidth);

        if ($("#main").length > 0) {
            $(".main_slideshow").css("margin-left", extraWidth);
            $(".main_slideshow").css("margin-right", extraWidth);
            $(".main_content").css("margin-left", extraWidth);
            $(".main_content").css("margin-right", extraWidth);
        }
        else if ($("#index").length > 0) {
            $(".index_slideshow").css("margin-left", extraWidth);
            $(".index_slideshow").css("margin-right", extraWidth);
            $(".index_content").css("margin-left", extraWidth);
            $(".index_content").css("margin-right", extraWidth);
        }
        else if ($("#single").length > 0) {
            $(".index_slideshow").css("margin-left", extraWidth);
            $(".index_slideshow").css("margin-right", extraWidth);
            $(".single_content").css("margin-left", extraWidth);
            $(".single_content").css("margin-right", extraWidth);
        }
        else if ($("#news").length > 0) {
            $(".index_slideshow").css("margin-left", extraWidth);
            $(".index_slideshow").css("margin-right", extraWidth);
            $(".news_content").css("margin-left", extraWidth);
            $(".news_content").css("margin-right", extraWidth);
        }
        else if ($("#search").length > 0) {
            $(".index_slideshow").css("margin-left", extraWidth);
            $(".index_slideshow").css("margin-right", extraWidth);
            $(".search_content").css("margin-left", extraWidth);
            $(".search_content").css("margin-right", extraWidth);
        }
    }

    $("li.line").mouseover(
    function () {
        $(this).find("ul.sub").children("li").fadeIn("slow");
    });

    $("li.subline").mouseover(
    function () {
        $(this).find("ul").children("li").fadeIn("slow");
    });

});

$(window).resize(function () {
    var currentHeight = document.documentElement.clientHeight;
    SetHeight(currentHeight);
});

function SetHeight(currentHeight) {

    if ($("#main").length > 0) {
        optHeight = (currentHeight - (106 + 30 + 35 + 250 + 36));
        if (optHeight > 300) {
            $(".main_content").css("min-height", optHeight + "px");
        }
    }
    else {
        optHeight = (currentHeight - (106 + 30 + 35 + 141 + 36));
        if (optHeight > 300) {
            $(".index_content").css("min-height", optHeight + "px");
            $(".single_content").css("min-height", optHeight + "px");
            $(".news_content").css("min-height", optHeight + "px");
            $(".search_content").css("min-height", optHeight + "px");
        }
    }
}
