var distance = 500;
var total = 997;
var dropDown;
var dropDownTimer;
var oldDropDown;

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function NFLBar()
{

    this.bar = document.getElementById("nflMenu");
	var a = this.bar.getElementsByTagName("a");
    for(var i = 0; i < a.length; i++)
	{
		a[i].onmouseover = function()
		{
			initDropDown(this,this.id.replace(/sites/i,"Drop"));
		}
		a[i].onmouseout = startTimer;
	}
}

function openBar(linkage)
{

    var el = document.getElementById("nflBarCont");
	var curWidth = el.offsetWidth;
	//var rightPos = total - (el.offsetLeft + el.offsetWidth);

    if(curWidth > (total-distance))
	{
		//el.style.right = ((total - (el.offsetLeft + el.offsetWidth)) + 10) + "px";
		el.style.width = (curWidth - 10) + "px";
		window.setTimeout("openBar()",15);
	}
	else
	{
		//el.style.right = distance + "px";
		el.style.width = (total-distance) + "px";
//		document.getElementById("nflBarImg").setAttribute("src","<%=AppSettings.getInstance().getCacheContext()%>/images/NFLNetwork.png");
		var a = el.getElementsByTagName("a");
		a[0].onclick = function() { closeBar(); this.blur(); };
	}
}

function closeBar()
{
    var el = document.getElementById("nflBarCont");
	var curWidth = el.offsetWidth;
	if(curWidth < total)
	{
		el.style.width = (curWidth + 10) + "px";
		//el.style.right = ((total - (el.offsetLeft + el.offsetWidth)) - 10) + "px";
		window.setTimeout("closeBar()",15);
	}
	else
	{
		//el.style.right = 0;
		el.style.width = total + "px";
//		document.getElementById("nflBarImg").setAttribute("src","/media/nfl_bar/nfl_bar_closed.gif");
		var a = el.getElementsByTagName("a");
		a[0].onclick = function() { openBar(); this.blur(); };

	}
}

function initDropDown(menu,id)
{
	if(dropDownTimer)
	{
		clearTimeout(dropDownTimer);
		//fadeOut(dropDown.id,100,0,10,"hide");
	}
	dropDown = document.getElementById(id);
	if(oldDropDown)
	{
		if(oldDropDown.id == id && dropDown.style.display != "block")
		{
			showDropDown(id);
		}
		else if(oldDropDown.id != id)
		{
//			showDropDown(id);
			hideDropDown();
			showDropDown(id);
		}
		else
		{
//			hideDropDown();
//			showDropDown(id);
		}
	}
	else
	{
		showDropDown(id);
	}
	oldDropDown = dropDown;
}

function showDropDown(id)
{
	//setOpacity(dropDown,50);
	dropDown.style.display = "block";
	//fadeIn(id,0,100,10);
	dropDown.onmouseover = clearTimer;
	dropDown.onmouseout = startTimer;
}

function hideDropDown()
{
	oldDropDown.style.display = "none";
	//fadeOut(oldDropDown.id,100,0,10,"hide");
}

function startTimer()
{
	dropDownTimer = window.setTimeout("hideDropDown()",100);
}

function clearTimer()
{
	clearTimeout(dropDownTimer);
}

addLoadEvent(function()
{
    var nflBar = new NFLBar();
})
