﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

$(document).ready(function() {
    // ****************
    // main menu support
    var configMenu = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
        interval: 100, // number = milliseconds for onMouseOver polling interval    
        over: menuHoverOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 100, // number = milliseconds delay before onMouseOut    
        out: menuHoverOut // function = onMouseOut callback (REQUIRED)
    };
    $("ul#topnav li .sub").css({ 'opacity': '0' });
    $("ul#topnav li").hoverIntent(configMenu);

    function menuHoverOver() {
        $(this).find(".sub").stop().fadeTo('fast', 1).show();

        // calculate width of all ul's
        (function($) {
            jQuery.fn.calcSubWidth = function() {
                rowWidth = 0;
                // calculate row
                $(this).find("ul").each(function() {
                    rowWidth += $(this).width();
                });
            };
        })(jQuery);

        $(this).calcSubWidth();
        // set Width     
        if (rowWidth > 0) {
            $(this).find(".sub").css({ 'width': rowWidth });
            $(this).find(".suba").css({ 'width': rowWidth - 25 });
        }
    }

    function menuHoverOut() {
        $(this).find(".sub").stop().fadeTo('fast', 0, function() {
            $(this).hide();
        });
    }


    // ****************
    // locale support
    
    // if javascript active, add the change designation
    if ($("#localetext").index("Change") <= 0) {
        $("#localetext").html($("#localetext").html() + " (Change)");
        $("#localename").css({ "cursor": "pointer" });
    }
    
    var configLocale = {
        sensitivity: 2,
        interval: 100,
        over: localeHoverOver,
        timeout: 100,
        out: localeHoverOut
    }
    $("#localecontainer-inner").hoverIntent(configLocale);  

    function localeHoverOver() {
        $(this).find("#localeselect").stop().fadeTo('fast', 1).show();
    }

    function localeHoverOut() {
        $(this).find("#localeselect").stop().fadeTo('fast', 0, function() {
            $(this).hide();
        });
    }

    $(".localeselect-item").hover(
        function() {
            $(this).addClass("localeselect-itemhover");
        },
        function() {
            $(this).removeClass("localeselect-itemhover");
        }
    );
});

function localeSwitch(newCulture) {
    var expiredays = 30;
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = "CultureOverride" + "=" + escape(newCulture) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
    window.location.reload();
}