﻿$(document).ready(initPage);

function initPage()
{  
    var config = {    
         sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)    
         interval: 75, // number = milliseconds for onMouseOver polling interval    
         over: function() { displayArticle($(this)); }, // function = onMouseOver callback (REQUIRED)    
         timeout: 250, // number = milliseconds delay before onMouseOut    
         out: function() { hideArticle($(this)); } // function = onMouseOut callback (REQUIRED)    
    };
    showHide();
    lhnavShowHide();
}

var _inAnim = false;

/**
 * displays and accordian article
 **/
function displayArticle(e)
{
    if( e.is("div") && !e.hasClass("expanded") && ! _inAnim ) 
    {
        _inAnim = true;
        li = e;
        openli = li.parent().children("div.expanded");
        
        
        // animator to open the item
        li.animator(10, function(item, end) 
        {
            if( item.css("height") == "auto") item.css("height", "33");
            height = parseFloat(item.css("height")) + 20;
            
            item.css("height", height);
            item.addClass("expanded");
            if( height >= 145) 
            {
                height = 145;
                item.css("height", height);
                _inAnim = false;
                return false;
            }
            return true;
        });
        
        // animator to close the item
        openli.animator(10, function(item, end)
        {
            if( item.css("height") == "auto") item.css("height", "145");
            height = parseFloat(item.css("height")) - 20;
            item.css("height", height);
            
            if( height <= 33 ) 
            {
                height = 33;
                item.css("height", height);
                item.removeClass("expanded");
                _inAnim = false;
                return false;
            }
            return true;
        });
    }
}

/**
 * hides and accordian article
 **/
function hideArticle(e){}

function popUp(url,w,h){
    if (typeof w=='undefined' || w==''){w='450'}
    if (typeof h=='undefined' || h==''){h='350'}
    var toolbar = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h;
    var myPopup = window.open(url,"Ambassadors_PopUp",toolbar);
    myPopup.focus();
}

function showHide()
{
    $(".showhidetarget").hide();
    $(".showhidetrigger").toggle(
        function()
        {
            $(this).parent().siblings(".showhidetarget").show();
            if($(this).children(".showhideimage").hasClass("showhideplus"))
            {
                $(this).children(".showhideimage").removeClass("showhideplus");
                $(this).children(".showhideimage").addClass("showhideminus");
            }
            $(this).children(".showhideimage").attr("title", "Hide");
        },
        function()
        {
            $(this).parent().siblings(".showhidetarget").hide();
            if($(this).children(".showhideimage").hasClass("showhideminus"))
            {
                $(this).children(".showhideimage").removeClass("showhideminus");
                $(this).children(".showhideimage").addClass("showhideplus");
            }
            $(this).children(".showhideimage").attr("title", "Show");
        }
    );
}

function lhnavShowHide()
{
    $("#main_nav").children("ul").children("li:not(.highlt-menu)").children("a[href*=teams.aspx],a[href*=leagues.aspx]").toggle
    (
        function()
        {
            $(this).parent("li").children("ul").slideDown('fast');
        },
        function()
        {
            $(this).parent("li").children("ul").slideUp('fast');
        }
    );
    
    $("#main_nav").children("ul").children("li.highlt-menu").children("a[href*=teams.aspx],a[href*=leagues.aspx]").click
    (
        function()
        {
            return false;
        }
    );
}