

// turn this off to not show trace messages
var _debug_ = false;

// attempts to log to the Firebug console; uses window.alert() on fail
// dependencies: (bool) _debug_
var trace = function(msg) {
    if ( _debug_ ) {
        try {
            console.log(msg);
        }
        catch (e) {
            alert(msg);
        }
    }
};


// these events will trigger only when the DOM is fully loaded
//$(document).ready( function() {
jQuery(function() { //this helps IE wait until the page is loaded to trigger the $(document).ready() functionality
    
    // general hide focus for links
    $('a').click( function() {
        $(this).blur();
    });
    
    // header hover menu "quick links"
    if ( !$.browser.msie ) {
        $("img[alt=video]").dropShadow({left: 8, top: 10, opacity: 0.8, blur: 4});
        var dropApplied = false;
        $("ul#topNav li.qlMenu").mouseover( function() {
            if ( !dropApplied ) {
                $("ul#quickLinks").dropShadow({left: 1, top: 1, opacity: 0.6, blur: 2});
                dropApplied = true;
            }
            else {
                $("#quickLinks_dropShadow").show();
            }
        });
        $("ul#topNav li.qlMenu").mouseout( function() {
            $("#quickLinks_dropShadow").hide();
        });
    }
    
    
}); // end $(document).ready()



// keep track of mouse coordinates
var mouse = {
    x: 0, y: 0
};



var hideNavMarker = function(x) {
    document.getElementById("mainNavMarker").style.backgroundPosition = ( "0px 50px" );
};
var showNavMarker = function(x) {
    document.getElementById("mainNavMarker").style.backgroundPosition = ( "80px 0px" );
};
var moveNavMarker = function(x) {
    trace("x: " + x);
    document.getElementById("mainNavMarker").style.backgroundPosition = ( x + "px 0px" );
};




// returns an object with the w & h of the document's client area
var clientArea = function() {
    var rect = {
        w: 0, h: 0
    };
    if ( typeof(window.innerWidth) == 'number' ) {
        // non-IE
        rect.w = window.innerWidth;
        rect.h = window.innerHeight;
    }
    else if ( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight) ) {
        // IE 6+ in 'standards compliant mode'
        rect.w = document.documentElement.clientWidth;
        rect.h = document.documentElement.clientHeight;
    }
    else if ( document.body && (document.body.clientWidth || document.body.clientHeight) ) {
        // IE 4 compatible
        rect.w = document.body.clientWidth;
        rect.h = document.body.clientHeight;
    }
    return rect;
};


var msie = ( document.all ? true : false );
if ( !msie ) document.captureEvents( Event.MOUSEMOVE );
//document.onmousemove = getMouseXY;
function getMouseXY(e) {
    if ( !e ) e = window.event;
    if ( !e ) {
        trace("Error: could not find mouse coordinates.");
        return false;
    }
    if (msie) {
        mouse.x = ( event.clientX + document.body.scrollLeft );
        mouse.y = ( event.clientY + document.body.scrollTop );
    }
    else {
        mouse.x = e.pageX;
        mouse.y = e.pageY;
    }  
    // catch possible negative values in NS4
    if (mouse.x < 0) mouse.x = 0;
    if (mouse.y < 0) mouse.y = 0;
    //trace("Mouse: " + mouse.x.toString() + ", " + mouse.y.toString());
    return true;
};




// legacy, from JASON
function JumpMenu(selObj, restore) {
    var theFullString = selObj.options[selObj.selectedIndex].value;
    if (restore) {
        selObj.selectedIndex = 0;
    }
    var theLength = theFullString.length;
    var endPos = theFullString.indexOf("~");
    var endPos2 = theFullString.lastIndexOf("~");
    var theUrl, theTarget, theParent;
    if (endPos == 0) {
        theUrl = theFullString.substring(1, endPos2);
    } else if (endPos > 0) {
        theUrl = theFullString.substring(0, endPos);
    } else {
        theUrl = theFullString;
    }
    endPos2++;
    if (endPos2 < theLength) {
        theTarget = theFullString.substring(endPos2, theLength);
    } else {
        theTarget = "window:Main";
    }
    if (theTarget == "window:New") {
        window.open(theUrl);
    } else if (theTarget == "window:Main") {
        eval("parent.location='" + theUrl + "'");
    }
}