﻿/* master page */
function prepareMasterPage() {
    prepareTopMenu();
    prepareHovers();
    prepareInputDecoration();
    loadSubmitHover();

    // fix pngs
    DD_belatedPNG.fix('.iefix');
}
function prepareTopMenu() {
    $("#navbar ul li").hover(
        function () { $(this).children("ul").css("display", "none"); }, /* block */
        function () { $(this).children("ul").css("display", "none"); }
    );

    /* set left + top position */
    //    $("#navbar ul").hover(
    //        function () {
    //            var theLeft = $(this).children("li").offset().left;
    //            var width = $(this).find(".side_content_wrapper").width();
    //            $(this).children("li").children("ul").first().css("left", theLeft + width);

    //            var theTop = $(this).children("li").offset().top;
    //            $(this).children("li").children("ul").first().css("top", theTop);
    //        },
    //        function () { }
    //    );

    //    $("#navbar ul li ul li").hover(
    //        function () { $(this).addClass("subMenuHover"); },
    //        function () { $(this).removeClass("subMenuHover"); }
    //    );
}
function prepareInputDecoration() {
    $(".inputBlur").focus(function () { $(this).addClass("inputFocus"); });
    $(".inputBlur").blur(function () { $(this).removeClass("inputFocus"); });
}

/* master page - sidebar */
function prepareSideBar() {
    $("#side_innerContain ul li").hover(
        function () { $(this).children("ul").css("display", "block"); },
        function () { $(this).children("ul").css("display", "none"); }
    );

    /* set left + top position */
    $("#side_innerContain ul").hover(
        function () {
            var theLeft = $(this).children("li").offset().left;
            var width = $(this).find(".side_content_wrapper").width();
            $(this).children("li").children("ul").first().css("left", theLeft + width);

            var theTop = $(this).children("li").offset().top;
            $(this).children("li").children("ul").first().css("top", theTop);
        },
        function () { }
    );

    /* */
    $("#side_innerContain ul").hover(
        function () { $(this).addClass("hover"); },
        function () { $(this).removeClass("hover") }
    );

    $("#side_innerContain ul li ul li").hover(
        function () { $(this).addClass("subMenuHover"); },
        function () { $(this).removeClass("subMenuHover"); }
    );
}


/* std. submit button hover */
function loadSubmitHover() {
    $(".submit_wrapper a").hover
    (
        function () { $(this).parent().addClass("_hover"); },
        function () { $(this).parent().removeClass("_hover"); }
    );
}

function prepareModals() {
    $(".modalInput").overlay({

        // some mask tweaks suitable for modal dialogs
        mask: {
            color: '#454545',
            loadSpeed: 200,
            opacity: 0.9
        },
        closeOnEscape: true,
        closeOnClick: true
    });
}
function loadModal() {
    $('.modalInput').click();
}

function centerImagesVertically() {
    $prodBoxes = $(".prod_image");

    $prodBoxes.each(function (index) {
        var boxHeight = $(this).height();
        var image = $(this).find("img");
        var imageHeight = image.height();

        if (imageHeight != 0 && boxHeight > imageHeight) {
            $(image).css("margin-top", (boxHeight - imageHeight) / 2);
        }

    });
}
