jQuery(document).ready(function() {
    var ie = false;
    jQuery.each(jQuery.browser, function(i, val) {
        if (i == "msie")
            ie = true;
    });
    if (ie)
        jQuery(".MenuChild").css({ width: jQuery("#Vlu_Menu").width() });

    jQuery(".MenuChild").each(function() {
        var left = jQuery(jQuery(this).parent()).position().left;
        if (ie) {
            jQuery(this).show();
            var maxLeft = 0;
            var width = 0;
            jQuery(this).find(".DivItemChildText").each(function() {
                width += jQuery(this).width();
                maxLeft++;
            });
            left = left - width / 2;
            if (left < 0) left = 0;
            jQuery(this).css({ left: left });
            if (width > 0) {
                maxLeft = jQuery(jQuery(this).find(".DivItemChildText")[maxLeft - 1]).position().left + jQuery(jQuery(this).find(".DivItemChildText")[maxLeft - 1]).width();
                if (jQuery("#Vlu_Menu").width() < maxLeft + left)
                    jQuery(this).css({ left: jQuery("#Vlu_Menu").width() - maxLeft - 15 });
            }
            jQuery(this).hide();
        }
        else {
            left = left - jQuery(this).width() / 2;
            if (left < 0) left = 0;
            if (left > jQuery("#Vlu_Menu").width() - jQuery(this).width())
                left = jQuery("#Vlu_Menu").width() - jQuery(this).width();
            jQuery(this).css({ left: left });
        }

    });

    jQuery(".DivItemChildActive").each(function() {
        var parent = jQuery(this).parent();
        parent = jQuery(parent).parent();
        if (jQuery(parent).hasClass("VluMenu_ItemNormal")) {
            jQuery(parent).removeClass("VluMenu_ItemNormal");
            jQuery(parent).addClass("VluMenu_ItemActive");
        }
    });

    jQuery(".VluMenu_ItemActive").each(function() {
        jQuery(this).children(".MenuChild").each(function() {
            jQuery(this).show();
        });
        jQuery(this).children(".DivItem").each(function() {
            jQuery(this).removeClass("DivItem");
            jQuery(this).addClass("DivItemActive");
        });
    });

    jQuery(".DivItemChild").each(function() {
        jQuery(this).hover(
                function() {
                    if (jQuery(this).hasClass("DivItemChild")) {
                        jQuery(this).removeClass("DivItemChild");
                        jQuery(this).addClass("DivItemChildHover");
                    }
                },
                function() {
                    if (jQuery(this).hasClass("DivItemChildHover")) {
                        jQuery(this).removeClass("DivItemChildHover");
                        jQuery(this).addClass("DivItemChild");
                    }
                }
            );
    });

    jQuery(".VluMenu_ItemNormal").each(function() {
        jQuery(this).hover(
                function() {
                    jQuery(this).children(".DivItem").each(function() {
                        jQuery(this).removeClass("DivItem");
                        jQuery(this).addClass("DivItemHover");
                    });
                    jQuery(".VluMenu_ItemActive").children(".MenuChild").hide();
                    jQuery(this).children(".MenuChild").each(function() {
                        jQuery(this).show();
                    });
                },
                function() {
                    jQuery(this).children(".DivItemHover").each(function() {
                        jQuery(this).removeClass("DivItemHover");
                        jQuery(this).addClass("DivItem");
                    });
                    jQuery(".VluMenu_ItemActive").children(".MenuChild").show();
                    jQuery(this).children(".MenuChild").each(function() {
                        jQuery(this).hide();
                    });
                }
            );
    });
});
