﻿
$(function () {
    Menu.Build(".Menu");
});

var mouseX = 0;
var mouseY = 0;
$().mousemove(function (e) {

    mouseX = e.pageX;

    mouseY = e.pageY;

});

var Menu = {

    Build: function (menuid) {

        $.each($(menuid), function (index, menudiv) {
            $.each($(menudiv).find("ul li a"), function () {
                if ($(this).html() == "")
                    $(this).remove();
                if (document.location.toString().indexOf($(this).attr("href")) != -1)
                    $(this).addClass("on");
            });




            $(menudiv).find("ul li").hover(function () {

                lastitem = null;
                lastmouseposx = 0;
                lastmouseposy = 0;
                if ($(this).find("a").attr("overimageid") != "") {

                    $(this).find("a img").first().attr("src", $(this).find("a").attr("overimageid"));
                }
                if ($(this).find('.child').html() != "") {
                    lastitem = $(this).find('.child');

                    lastmouseposx = mouseX;
                    lastmouseposy = mouseY;

                    setTimeout("showlastitem()", 300);

                }


            }, function () {
                lastitem = null;
                lastmouseposx = 0;
                lastmouseposy = 0;

                $(this).find('.child').hide();

                if ($(this).find("a").attr("itemimageid") != "")
                    $(this).find("a img").first().attr("src", $(this).find("a").attr("itemimageid"));

            });

        });


    }

};

var lastitem;
var lastmouseposx;
var lastmouseposy;

function showlastitem() {

    if (lastitem!=null && lastmouseposx == mouseX && lastmouseposy == mouseY) {
        lastitem.show();
        //lastitem.slideDown();
    }
}
