﻿$(document).ready(function() {
    $("ul.subnav").each(function() {
        var current = $(this);
        current.attr("box_h", current.height());
    });
    $("ul.subnav").css("height", 0);
    $("ul.subnav").css("display", "inline");

    var p = $("ul.topnav").offset();
    $("ul.subnav").offset({ top: p.top + 30, left: p.left });
    
    $("ul.topnav li").mouseover(function() {
        var p = $("ul.topnav").offset();
        $("ul.subnav").css("z-index", 5);
        var h = parseInt($(this).find("ul.subnav").attr("box_h"));
        h = h + 20;

        $(this).find("div.topMenu").addClass("topMenuHover");

        var open_height = h + "px";
        $(this).find("ul.subnav").stop().animate({ height: open_height }, { queue: true, duration: 900, easing: 'swing' });
        $(this).find("ul.subnav").css("z-index", 10);

        $(this).hover(function() {
        }, function() {
            $(this).find("ul.subnav").stop().animate({ height: '0px' }, { queue: true, duration: 600, easing: 'swing' });
            $(this).find("div.topMenu").removeClass("topMenuHover");
        });

    }).hover(function() {
        $(this).addClass("subhover");
    }, function() {
        $(this).removeClass("subhover");
    });

});
