/*
author: Critical Mass
version: 1.7
modification date: July 16, 2007
*/

//this funcion sets up active hotspot navigation
function navHotspot(){
    var nav;                //navigation list
    var navAllAnchors;      //navigation list anchors
    var navContainer;       //navigation list continer
    
    //detect and assign navigation list if available
    if($('spotlight-nav-home') || $('spotlight-nav-main')){
        nav = $('spotlight-nav-home') ? $('spotlight-nav-home') : $('spotlight-nav-main');        
        
        /*
        retrieve all nav list anchor nodes and call navigation
        hotspot function.
        */
        navAllAnchors = nav.getElementsByTagName('A');
        for (i=0; i < navAllAnchors.length; i++){
            var navContainer = new navHotspotSwap(navAllAnchors[i]);
        }
    }    
}
/*
params: navAnchor - a navigation list anchor
this function adds/removes the text "-over" to the
end of the css list id and sets/unsets the anchor
id to "over"
*/
function navHotspotSwap(navAnchor){
    var navListElement = navAnchor.parentNode;    //The navigation list element
    var regExpression = /-over/g;                 //The regular expression
    navAnchor.onmouseover = function(){
        if (navListElement.id.indexOf('-over') == -1) {
            navListElement.id = navListElement.id + '-over';
            navAnchor.id = 'over';
        }
    }
    navAnchor.onmouseout = function(){
        navListElement.id = navListElement.id.replace(regExpression,'');
        navAnchor.id = '';
    }
}

/*
this function aligns the navigation and sports and culture
backlink in the correct position onload and onresize.
*/
function alignElements(){
    var BOTTOM_OFFSET = 50;                            //bottom offset of elements
    var BACKLINK_OFFSET = 10;                          //sports and culture backlink top offset
    var LEFT_OFFSET = 179;
    var spotlightNav = $('spotlight-nav-main');        //spotlight navigation
    var scBacklink = $('sports-culture-backlink');     //sports and culture backlink        
    var dimmerBG = $('dimmer-bg');                                                       
    var topPosition = 0;                               //top position for the elements
    var newOffsetMaxMid = 1;                           //new offset for calculation correction
               
    if (height >= (MAXHEIGHT)){
        topPosition = MAXHEIGHT - BOTTOM_OFFSET - TOPPADDING - marginTop + newOffsetMaxMid;
    }
    else if (height <= (MINHEIGHT)){
        topPosition = MINHEIGHT - BOTTOM_OFFSET - TOPPADDING - marginTop + FOOTERHEIGHT;
    }
    else{
        topPosition = height - BOTTOM_OFFSET- TOPPADDING - marginTop + newOffsetMaxMid;
    }

    leftPosition = LEFTPADDING - marginLeft - LEFT_OFFSET;
        
    if(spotlightNav){
        spotlightNav.style.top = topPosition + "px";
    }    

    if(scBacklink){         
        scBacklink.style.top = topPosition + BACKLINK_OFFSET + "px";    
    }
    
    if(dimmerBG){
        dimmerBG.style.top =  (topPosition - height + FOOTERHEIGHT) + "px";
        dimmerBG.style.left = leftPosition + "px";
        dimmerBG.style.width = width + "px";
        dimmerBG.style.height = height + "px";
    }
}

/*
if video container exist, get video locations and call
external loadVideo function
*/
function setupVideo(){
    if ($('video-frame')){
        var qtVideoFileUrl = $("video-quicktime").href;    //quicktime video location
        loadVideo("video", qtVideoFileUrl);
    }
}


//onload handlers
onloadHandlers[onloadHandlers.length] = 'alignElements()';
onloadHandlers[onloadHandlers.length] = 'navHotspot()';
onloadHandlers[onloadHandlers.length] = 'setupVideo()';

//onresize handlers
onresizeHandlers[onresizeHandlers.length] = 'alignElements()';