﻿//$(document).ready(function() {

//    // Makes the Dropdowns work in IE6
//    function startList() {
//        if (document.all && document.getElementById) {
//            navRoot = document.getElementById("MainNav");
//            for (i = 0; i < navRoot.childNodes.length; i++) {
//                node = navRoot.childNodes[i];
//                if (node.nodeName == "DD") {
//                    node.onmouseover = function() {
//                        this.className += " over";
//                    }
//                    node.onmouseout = function() {
//                        this.className = this.className.replace(" over", "");
//                    }
//                }
//            }
//        }
//    }
//    startList();

//});

// execute your scripts when DOM is ready. this is a good habit
$(function() {
    $('.dropdown dd div').each(function() {
        var minWidth = 12;
        var maxWidth = 25;
        var fontsize = $('<dd id="menu-fontsize">&#8212;</dd>').css({
            'padding': 0,
            'position': 'absolute',
            'top': '-999em',
            'width': 'auto'
        }).appendTo($(this).parents("dd")).width();
        $('#menu-fontsize').remove();


        $(this).children('ul').each(function() {
            var $$ = $(this);
            $$.css({ 'display': 'block', 'visibility': 'hidden' });
            $$.css('width', 'auto');
            $$.children().css('white-space', 'nowrap')

            //console.info($$.width());
            var emWidth = $$.outerWidth() / fontsize; ;
            //console.info(emWidth);

            if (emWidth > maxWidth) emWidth = maxWidth;
            if (emWidth < minWidth) emWidth = minWidth;

            $$.css({ 'width': emWidth + 'em', 'display': '', 'visibility': '' });
            $$.children().css({ 'white-space': 'normal', 'width': '100%' });
        });
    });
    $('.dropdown dd div').hover(function() {
        //$(this).addClass('over');
        //$(this).children('ul').slideDown("slow");
        $(this).children('ul').fadeIn("slow", function() { $(this).parents("dd").addClass('over'); });
    }, function() {
        //$(this).removeClass('over');
        //$(this).children('ul').slideUp("slow");
        $(this).children('ul').fadeOut("slow", function() { $(this).parents("dd").removeClass('over'); });
    });
});