var prevDrpDownMenu = null;

function _$(id)
{
    return document.getElementById(id);
}
/**
 * Swaps the specified image source with the new source
 * @param [sType] the owner of the image swap call
 * @return null
 */
function swapImage(sType)
{
    switch (sType)
    {
//         tab container statements
        case "events":
        _$("eventsImg").src = "images/template/event_on.jpg";
        _$("newsImg").src = "images/template/news_off.jpg";
        // hide the events, show the news
        _$("eventsContainer").style.display = "block";
        _$("newsContainer").style.display = "none";
        _$("view_all_events").style.display = "block";
        _$("view_all_news").style.display = "none";
        break;
        
        case "news":
        _$("eventsImg").src = "images/template/event_off.jpg";
        _$("newsImg").src = "images/template/news_on.jpg";
        // hide the events, show the news
        _$("eventsContainer").style.display = "none";
        _$("newsContainer").style.display = "block";
        _$("view_all_events").style.display = "none";
        _$("view_all_news").style.display = "block";
        break;
        
        
//         header case statements
        case "weather":
        _$("weather_link").style.backgroundImage = "url('images/template/weather_on.jpg')";
        _$("site_search_link").style.backgroundImage = "url('images/template/site_search_off.jpg')";
        _$("email_sign_up_link").style.backgroundImage = "url('images/template/email_sign_off.jpg')";
        break;
        
        case "email_sign_up":
        _$("weather_link").style.backgroundImage = "url('images/template/weather_off.jpg')";
        _$("site_search_link").style.backgroundImage = "url('images/template/site_search_off.jpg')";
        _$("email_sign_up_link").style.backgroundImage = "url('images/template/email_sign_on.jpg')";
        break;
        
        case "site_search":
        _$("weather_link").style.backgroundImage = "url('images/template/weather_off.jpg')";
        _$("site_search_link").style.backgroundImage = "url('images/template/site_search_on.jpg')";
        _$("email_sign_up_link").style.backgroundImage = "url('images/template/email_sign_off.jpg')";
        break;
        
        case "all_regions":
        _$("weather_link").style.backgroundImage = "url('images/template/weather_off.jpg')";
        _$("site_search_link").style.backgroundImage = "url('images/template/site_search_off.jpg')";
        _$("email_sign_up_link").style.backgroundImage = "url('images/template/email_sign_off.jpg')";        
        break;
    } // end SWITCH
}

/**
 * Shows the nav drop down menu
 * @param [show] True if the nav menu wil be shown, false otherwise
 * @param [menu] the calling menu element object
 * @return null
 */
function showNavDropDown(show, menuid)
{
    var menuddid = menuid+"-dd"; // menu drpdwn id
    var drpdwnMenu = _$(menuddid);
    if (!drpdwnMenu)
        return;
  
    if (show)
    {
        var disp = drpdwnMenu.style.display;
     
        $(menuddid).hide();
        Effect.BlindDown(menuddid, {duration : 0.2});
    }
    else
    {
        Effect.BlindUp(menuddid, { duration : 0.2 });
    }
}

/**
 * Shows or hides the target text box floating region
 * @param [show] True to display the region, false to hide it
 * @param [linkid] the link that invoked the call
 */
function showTextBox(show, linkid)
{
    if (show)
        swapImage(linkid);
    else
        swapImage("all_regions");
    var searchTextBubble = _$("search_Base");
    var emailTextBubble = _$("email_Base");
    var weatherBubble = _$("weather_Base");
    
    switch(linkid)
    {
        case "email_sign_up":
//         emailTextBubble.alignTo(linkid, "tl-bl");
        showElement(weatherBubble, false);
        showElement(searchTextBubble, false);
        
        showElement(emailTextBubble, show);
        break;
        
        case "site_search":
//         searchTextBubble.alignTo(linkid, "tr-br");
        showElement(emailTextBubble, false);
        showElement(weatherBubble, false);
        
        showElement(searchTextBubble, show);
        break;
        
        case "weather":
//         weatherBubble.alignTo("weather_link", "t-b");
        showElement(emailTextBubble, false);
        showElement(searchTextBubble, false);
        
        showElement(weatherBubble, show);
        break;
    }
}

/**
 * Shows or hides the specified element
 * @param [ele] the element to show or hide
 * @param [show] true if showing the element, false otherwise
 * @param [animate] false if animation is done
 * @return null
 */
function showElement(ele, show, animate)
{
    // get the element prototype
        //errors out
        //element = $(ele.id);
    if (show === false)
    {
        ele.style.display = "none";
       //doesnt do what I think it should
       //element.hide();
        return;
    }
     
    if (show)
    {
        if (!Ext.get(ele).isVisible())
        Ext.get(ele).fadeIn({ 
            duration: 0.5,
            useDisplay : true
        });
//          MenuEffects.Fade(ele.id, true);
//         element.appear();
    }
}

function widget_nav(id)
{
    element = document.getElementById('body');

    nodes = element.getElementsByTagName('div');

    for(i=0; i < nodes.length; i++)
    {
        ele_id = nodes[i].getAttribute('id');
        if (ele_id != '' && ele_id != null)
        {

            document.getElementById(ele_id).className="hidden";

            li =  document.getElementById(ele_id+"_li");
            if (li != '' && li != null)
            {
                li.className = "";
            }
        }
    }

    document.getElementById(id).className="show";
    document.getElementById(id+"_li").className="active";

}

function StartHideTopFloats()
{
    setTimeout("HideTopFloats()", 3000);
}

function HideTopFloats()
{
    // hide all the floating regions
    showTextBox(false, "email_sign_up");
}

/**
 * Represents the menu effects object
 * @return object instance
 */
var MenuEffects = {
    
    // a list of all the subnav IDs (the elements that contain the subnav-sub links
    // the IDs that used MenuEffects.Slide
    subnavIds : [ 
        "travel-tips-sub",
        "online-toolkit-sub",
        "about-dallas-sub",
        "getting-around-sub",
        "dallas-features"
     ],
    
    prevId : null,//"dallas-features",
    featuresShown : true,

    // the slide animation duration
    SLIDE_DURATION : 0.5,
    
    // the fade animation duration
    FADE_DURATION : 0.5,
    
    /**
    * "Slides" the target element down and up
    * @param [eleId] the id of the element
    * @return null
    */
    Slide : function(eleId)
    {
        // make sure the element exists
        if (_$(eleId) == null)
            return;
            
        var opts = { duration : MenuEffects.SLIDE_DURATION };
        var id = eleId; // set working ID
        var prevId = MenuEffects.prevId;
        var isDallasFeatures = (eleId == "dallas-features");
        var featuresShown = MenuEffects.featuresShown;
        
        // hide the previous drop down menu
        if (MenuEffects.prevId != null)
        {                   
            if (!isDallasFeatures && (prevId != 'dallas-features'))
                Effect.BlindUp(MenuEffects.prevId, { duration : 0.3 });
            if (MenuEffects.prevId == id)
            {
                // if shown hide it
                id = MenuEffects.prevId = null;
            }
        }
        
        // if this is a different element
        if (id != null)
        {
            // make sure the features are hidden
            if (!isDallasFeatures)
            {
                Effect.BlindUp('dallas-features', opts);
                MenuEffects.featuresShown = false;
            }
            
            var blindDown = true;
            if (id == 'dallas-features')
                blindDown = false;
                
            if (!blindDown && !featuresShown)
            {
                Effect.BlindUp(prevId, { duration : 0.3 });
                blindDown = true;
                MenuEffects.featuresShown = true;
            }
                    
            // show the target element
            if (blindDown)
                Effect.BlindDown(id, opts);
        }    
        else
        { // if the previous ID has been "closed"
            if (isDallasFeatures && prevId == null)
                featuresShown = true;
                
            // then show the features
            if (!featuresShown)
            {
                Effect.BlindDown('dallas-features', opts);
                MenuEffects.featuresShown = true;
            }
        }
        
        // assign the new prev id
        MenuEffects.prevId = id;
    },
    
    /**
     * Fades the target element
     * @param [id] the id of the target element
     * @param [fadein] true if the element will 
     * fade in, false if it will fade out
     * @remark fades the element from 100% to 0% (and vice-versa)
     * @return null
     */
    Fade : function(id, fadein)
    {
        if (fadein)
            Effect.Fade(id, { duration : MenuEffects.FADE_DURATION, from : 0.0, to : 1.0 });
        else
            Effect.Fade(id, { duration : MenuEffects.FADE_DURATION, from : 1.0, to : 0.0 });
    },
    
    /**
     * Hides all the sub nav sub items
     * @return null
     */
    HideAllSubNavs : function()
    {
        for (var idx = 0 ; idx < MenuEffects.subnavIds.length ; ++idx)
        {
            var id = MenuEffects.subnavIds[idx];
            $(id).hide();
        }
    }
} // end object MenuEffects
