﻿//<reference path="../_js/jquery-1.4.2.min-vsdoc.js" />

jQuery(document).ready(function () {
    adjustScreen();

    //Menu hover effect
    jQuery('#menu a').hover(function () { $(this).toggleClass("selected"); });
    jQuery('#menu a').mouseout(function () { $(this).toggleClass(""); });
    
});

jQuery(window).resize(function () { adjustScreen(); });

function adjustScreen() {
    //css fixes for browsers
    if (jQuery.browser.msie && jQuery.browser.version.substring(0, 1) < '8') {
        var leftpos = (jQuery("#submenu_banner").innerWidth() + jQuery("#submenu_banner").offset().left);
        jQuery("#lnkSwitchLanguage").addClass("IE7").css("left", leftpos - 40);

        if (jQuery("#lnkQuotation").length > 0) {
            leftpos = leftpos - jQuery("#lnkQuotation img").width() - 20;
            jQuery("#lnkQuotation").addClass("IE7").css("left", leftpos);
        }
    }
}

function switchCultureSite(en_site, fr_site) {
    var url = window.top.location.href;
    
    var current_culture = (window.top.location.href.toLowerCase().indexOf(ENGLISH_SITE.toLowerCase()) > -1) ? "en-ca" : "fr-ca";

    switch (current_culture) {
        case "en-ca":
            url = fr_site;
            break;
        case "fr-ca":
            url = en_site;
            break;
    }

    window.top.location = url;
    
    return true;
}

 function switchCulture() {
        var days = 15;
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();

        var current_culture = Get_Cookie("culture");
        var new_culture = (current_culture.toLowerCase() == "en-ca") ? "fr-ca" : "en-ca";
        document.cookie = "culture=" + new_culture + ";expires=" + date.toGMTString() + ";path=/"

        var url = window.top.location.href;

/*        if (window.top.location.href.indexOf("/" + current_culture.substring(0, 2)) == -1)
            url = "http://" + window.top.location.host + "/" + new_culture.substring(0, 2);
        else
            url = window.top.location.href.replace("/" + current_culture.substring(0, 2), "/" + new_culture.substring(0, 2));
*/
        window.top.location = url;
    }

        // this function gets the cookie, if it exists
        // don't use this, it's weak and does not handle some cases
        // correctly, this is just to maintain legacy information
        function Get_Cookie(name) {

            var start = document.cookie.indexOf(name + "=");
            var len = start + name.length + 1;
            if ((!start) && (name != document.cookie.substring(0, name.length))) {
                return null;
            }
            if (start == -1) return null;
            var end = document.cookie.indexOf(";", len);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(len, end));
        }
    			
