var _display = false, _checkTimer = null, _menuTimer = null, _menuOpened = false, _activeMenuID;

$(document).ready(function() {
    //Wrap Flash content
    var so = new SWFObject("/Flash_SDK/" + objFlash.file, "MV", objFlash.width, objFlash.height, "8", "");
    so.addParam("wmode", "transparent");
    so.addParam("Flashvars", objFlash.params);
    so.write("flash-cont");

    $(".menu-wrap .sub-ul").bind("mouseleave", function () {
        _display = false;
        $(this).hide("slow");
    }).bind("mouseenter", function () {
        _display = true;
    });

    $(".isr").bind("mouseover", function () {
        $(".isr_sub").show("slow");
    }).bind("mouseleave", function () {
        $(".isr_sub").hide("slow");
    });

    $(".int").bind("mouseover", function () {
        $(".int_sub").show("slow");
    }).bind("mouseleave", function () {
        $(".int_sub").hide("slow");
    });




    $(".menu-wrap .sub-ul li").hover(
            function () {
                $(this).find("ul").show("slow");
            }, function () {
                $(this).find("ul").hide("slow");
            }).find("*[class ^= 'col-']").hover(
                function () {
                    $(this).attr("class", $(this).attr("class") + "-hover");
                },
                function () {
                    var currClass = $(this).attr("class");
                    $(this).attr("class", $(this).attr("class").replace("-hover", ""));
                }
           );

});


//Function that could be invoked from within SWF Object,
//while the mouse moved over the menu items:

function openmenu() {
    //Mouse moved over the menu item "Artist":
    processmenu("menu_1");
}

function openmenuprojects() {
    //Mouse moved over the menu item "Projects":
    processmenu("menu_2");
}

function openmenuexibitions() {
    //Mouse moved over the menu item "Exhibitions":
    processmenu("menu_3");
}
function openmenucontemporary() {
    //Mouse moved over the menu item "Artist":
    processmenu("menu_4");
}

function openmenuprojectscontemporary() {
    //Mouse moved over the menu item "Projects":
    processmenu("menu_5");
}

function openmenuexibitionscontemporary() {
    //Mouse moved over the menu item "Exhibitions":
    processmenu("menu_6");
}

function processmenu(MenuID) {
    if (_activeMenuID)
        check();
    _activeMenuID = MenuID;
    _menuOpened = true;
    clearTimeout(_checkTimer);
    clearTimeout(_menuTimer);
    _menuTimer = setTimeout(function() {
        if (_menuOpened)
            $("#" + _activeMenuID + " .sub-ul").show("slow");
    }, 400);

}

function closemenu() {
    _menuOpened = false;
    clearTimeout(_checkTimer);
    clearTimeout(_menuTimer);
    _checkTimer = setTimeout("check()", 50);
}

function check() {
    if (_display == false)
        $("#" + _activeMenuID + " .sub-ul").hide("slow");

}

//function check() {
//    var jUL = $("#menu_1 .sub-ul");
//    var display = false;
//    jUL.find("ul.sub-menu").each(function() {
//        if ($(this).css("display") != "none")
//            display = true;
//    });

//    if (!display)
//        jUL.hide("slow");
//}

