﻿var parentMenu = "";

jQuery.preloadImages = function() {
    for(var i = 0; i<arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

function closeMenu() {
    $(".menuRoot").each(function() {
        if(parentMenu != $(this).attr("id")){
            $(this).children("div:popupMenu").fadeOut("fast");
        }
    });
}

function openMenu(objname, obj) {
    setTimeout(function() { delayOpenMenu(objname, obj) }, 200);
}

function delayOpenMenu(objname, obj) {
    if($(obj).attr("id") == parentMenu) {
        closeMenu();
        $(objname).animate({"height":"show"}, {duration:"fast"});
    }
}

$(document).ready(function(){
    $("a").focus(function() {
        $(this).blur();
    });
    $.preloadImages(
        "http://www.cha-tours.com/WebCommon/Transparent/menu_right_border_trans.png", 
        "http://www.cha-tours.com/WebCommon/Transparent/menu_bottom_right_trans.png", 
        "http://www.cha-tours.com/WebCommon/Transparent/menu_bottom_middle_trans.png",
        "http://www.cha-tours.com/WebCommon/Transparent/menu_bottom_left_trans.png"
    );
    
    $("#tblNavLinks").mouseleave(function() {
        parentMenu = "";
        setTimeout("closeMenu()", 500)
    });
    $(".menuRoot").each(function() {
        $(this).mouseenter(function() {
            parentMenu = $(this).attr("id");
            openMenu("#" + $(this).children("div:popupMenu").attr("id"), this);
        });
    });
});