﻿/// <reference path="~/Assets/Javascripts/jquery-1.3.2-vsdoc.js" />
/// <reference path="~/Assets/Javascripts/functions.js" />

$(function () {
    if (typeof Cufon == "function") {
        Cufon.replace
            ('h1[class!=noCufon]')
            ('.mainMenuItem', { hover: true })
            ('h2[class!=noCufon]')
            ('#footer h3')
            ('h3.clients')
            ('.contentBox h3')
            ('p.header')
            ('#tellFriendWrapper h2')
            ('.buttonWide')
            ('.menuPush')
            ('.menuOne li p span')
            ('#casesHeader .text')
            ('#headerDropdowns ul > li')
        /*
        ('.puffContentBox a')
        ('.breadcrumbHomeBody', { hover: true })
        ('.breadcrumbBody', { hover: true })
        ('.breadcrumbLast')
        */
            ('#smallHeaderMenu', { hover: true })
            ('#footerCol5 .stbuttontext', { hover: true })
            ('.links a[class!=noCufon]')
            ('.links p[class!=noCufon]')
            ('.catchPageHeading')
            ('#languageSelector', { hover: true });
    }
    //$("body").show();
    replaceCheckbox();
    setTimeout(function () { setActiveMenuItem($("#mainMenu > .selected")) }, 2000); // temp fix
    // events
    quickSearchHandler();

    $(".puffContentBox, .menuPush.colored").click(function () {
        location.href = $(this).find("a").attr("href");
    });


    $("#mainMenu > li:not(.mainMenuSeparator)").hover(function () {
        setActiveMenuItem($(this));
        //$(this).find(".headerDropDown").slideDown("fast");
    }, function () {
        if (!$(this).is(".selected")) {
            $(this).children(".mainMenuItem").css("background", "");
        }

        $(".mainMenuSeparator").filter(function () {
            return (!$(this).next().is(".selected") && !$(this).prev().is(".selected"));
        }).css("background-color", "");
        //$(this).find(".headerDropDown").slideUp("fast");
    });

    /* Gör denna funktionen i code behind (default.aspx.cs) istället p.g.a. att alla länkar inte skall ha detta attributet. 
    $(".t1 .countryLink").click(function() {
    var newUrl;
    if ($("#rememberCheckbox").is(":checked")) {
    newUrl = $(this).attr("href") + "?remember=false";
    } 
    else {
    newUrl = $(this).attr("href") + "?remember=true";
    }

    $(this).attr("href", newUrl);
    });*/

    tooltip($('.countryLink'));

    chooseLanguage($('ul.languageList'));

    $(document).click(function () {
        $('#languageTemplate').hide();
    });

    $(".partBox").mouseout(function () {
        $('#tooptipTemplate').hide();
    });

    if ($.browser.msie && $.browser.version < 8) {

        /* replace align with style for images begin */
        $("img").filter(function () {
            var a = $(this).attr("align");
            if (a != "") {
                $(this).addClass(a);
            }
        });
        /* replace align with style for images end */

        /* Puff content box vertical center ie7 start */
        $('.puffContentBox').each(function () {
            var obj = $(this);
            var objChild = obj.children();

            var objHeight = obj.height();
            var objChildHeight = objChild.height();
            var childTopAlignement = Math.round((objHeight - objChildHeight) / 2);

            obj.css({ display: 'block' });
            objChild.css({ top: childTopAlignement + 'px', position: 'absolute', display: 'block' });
        });
        /* Puff content box vertical center ie7 end */
    }

    $("img").each(function () {
        var vspace = $(this).attr("vspace");
        if (vspace && vspace > 0) {
            $(this).attr("style", $(this).attr("style") + ";margin-left:" + vspace + "px" + ";margin-right:" + vspace + "px");
            $(this).removeAttr("vspace");
        }

        var hspace = $(this).attr("hspace");
        if (hspace && hspace > 0) {
            $(this).attr("style", $(this).attr("style") + ";margin-top:" + hspace + "px" + ";margin-bottom:" + hspace + "px");
            $(this).removeAttr("hspace");
        }
    });
});

