﻿var menuHasFocus = false;
$(function() {
    if ($("#headlines").children().length > 1) {
        $("#headlines").children().css("display", "none");
        $("#headlines p:first").fadeIn(1000);

        function removeFirst() {
            $("#headlines p:first").fadeOut(1000, function() {
                $("#headlines").append($("#headlines p:first"));
                $("#headlines p:first").fadeIn(1000);
            });
        }

        setInterval(removeFirst, 5000);
    }
    
    
    $("#navlist li").mouseenter(function(e){
        var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
        var clientCoords = "( " + e.clientX + ", " + e.clientY + " )";
        var leftPos = $(this).position().left;
        var width = $(this).width();
        
        var menuId = $(this).attr('id');
        var targetHtml = document.getElementById("attachment_" + menuId).innerHTML;
        if(targetHtml != "")
        {
            document.getElementById("dropDownMenuBody").innerHTML = targetHtml;
            
            $(".dropDownMenu").css({ 'position' : 'absolute', 'left' : leftPos, 'top' : 110    });
            $(".dropDownMenu").stop(true,true).slideDown("slow");
        }
        else
        {
            $(".dropDownMenu").stop(true,true).slideUp("slow");
        }
    });
    

    $(".dropDownMenu").mouseenter(function(e){
        menuHasFocus = true;
    });
    $(".dropDownMenu").mouseleave(function(e){
        menuHasFocus = false;
    });
    
    
    $(".dropDownMenuBody").mouseenter(function(e){
        menuHasFocus = true;
    });
    
    $(".dropDownMenuBody ul li").mouseenter(function(e){
        menuHasFocus = true;
    });

    $("#navcontainer").mouseenter(function(e){
        menuHasFocus = true;
    });
    
    $("#navcontainer").mouseleave(function(e){
        menuHasFocus = false;
    });
});

var checkTimer = null;
function checkMenuFocusLost()
{
    if(menuHasFocus == false)
    {
        $(".dropDownMenu").slideUp("slow");
    }
    
    checkTimer = setTimeout("checkMenuFocusLost()",200);
}

checkTimer = setTimeout("checkMenuFocusLost()",200);
