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;
	}
}

var distance = 450;
var total = 991;
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","/media/nfl_bar/nfl_bar_open.gif");
		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(); };
	}
}
var dropDown;
var dropDownTimer;
var oldDropDown;
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);
}
/*-------------------*/

function getCountData(url)
{
	//alert("getCountData");
	initRequest("GET",url,true,function() { finishCountDown(url); });
}
/*-------------------*/

var countTimer;
function prepCountDown(endDate, endURL)
{
	//alert(endDate + " " + endURL)
	if(countTimer)
		clearTimeout(countTimer);
	if(endDate.indexOf("|") != -1)
	{
		var dateArray = endDate.split("|");
		var days = dateArray[0];
		var hours = dateArray[1];
		var mins = dateArray[2];
		var secs = dateArray[3];
		countDown(days,hours,mins,secs,endURL);
	}
	else
	{
		if(document.getElementById("timer"))
			var el = document.getElementById("timer");
		else if(document.getElementById("gamedayTimer"))
			var el = document.getElementById("gamedayTimer");
		el.innerHTML = endDate;
	}
}
/*-------------------*/

var count = 0;
function countDown(days,hours,mins,secs,endURL)
{
	var daysCont = document.getElementById("days");
	var hoursCont = document.getElementById("hours");
	var minsCont = document.getElementById("mins");
	var secsCont = document.getElementById("secs");
	// write values to page. If the length is less than 1 then we add a leading 0
	if(days.length > 1)
		daysCont.innerHTML = days + "D";
	else
		daysCont.innerHTML = "0" + days + "D";
	if(hours.length > 1)
		hoursCont.innerHTML = hours + "H";
	else
		hoursCont.innerHTML = "0" + hours + "H";
	if(mins.length > 1)
		minsCont.innerHTML = mins + "M";
	else
		minsCont.innerHTML = "0" + mins + "M";
	if(secs.length > 1)
		secsCont.innerHTML = secs + "S";
	else
		secsCont.innerHTML = "0" + secs + "S";
	
	if(secs > 0)
	{
		secs--;
	}
	else if(secs == 0 && mins > 0)
	{
		secs = 59;
		if(mins > 0)
			mins--;
		
	}
	else if(secs == 0 && mins == 0 && hours > 0)
	{
		if(mins == 0 && hours > 0)
		{
			secs = 59;
			mins = 59;
		}
		if(hours > 1)
		{
			hours--;
		}
		else if(hours == 1 && days > 0)
		{
			hours = 23
			days--;
		}
		else
		{
			hours = 0;
		}
	}
	else
	{
		count = 10000;
	}
	count++;
	// either it's been 10 mins so we refresh to check if the date has changed or the timer has hit zero so we get the finished message
	if(count < 10000)
		countTimer = window.setTimeout("countDown('"+days+"','"+hours+"','"+mins+"','"+secs+"','"+endURL+"')",1000);
	else
	{
		initRequest("GET",endURL,true,function() { getCountData(endURL); });
		count = 0;
	}
}
/*-------------------*/

function finishCountDown(endURL)
{
	if(ajax.readyState == 4 && ajax.status == 200)
		prepCountDown(ajax.responseText,endURL);
}
/*-------------------*/

function updateEvent(id)
{
	if(ajax.readyState == 4 && ajax.status == 200)
	{
		var el = document.getElementById(id);
		//setOpacity(el,0)
		el.innerHTML = ajax.responseText;
		fadeIn(id,0,100,25);
		exeJavascript(ajax.responseText);
		pngFix();
	}
}
/*-------------------*/

function open365Ad(id,parentEl)
{
	clearTimeout(swapAdImgTimer);
	clearTimeout(fadeInTimer);
	clearTimeout(fadeOutTimer);
	var rightCol = document.getElementById(parentEl);
	var el = document.getElementById(id);
	if(el.style.position == "absolute")
		return true;
	rightCol.style.paddingTop = "112px";
	rightCol.style.position = "relative";
	//el.style.background = "url(/media/backgrounds/bg_365_ad_open3.jpg) no-repeat 0 0;"
	el.innerHTML = "";
	el.style.position = "absolute";
	el.style.top = "0";
	el.style.height = "180px";
	growAd(id,354);
}
/*-------------------*/

function close365Ad(id,parentEl)
{
	clearAdTimers();	
	var rightCol = document.getElementById(parentEl);
	var el = document.getElementById(id);
	rightCol.style.paddingTop = "0";
	rightCol.style.position = "relative";
	el.style.position = "static";
	el.style.top = "0";
	el.style.height = "108px";
	initRequest("GET","/Modules/Dropdown_ad.aspx?q=closed",true,swapAd);
}
/*-------------------*/

var growAdTimer;
function growAd(id,target)
{
	var el = document.getElementById(id);
	if(el.offsetHeight < target)
	{
		el.style.height = (el.offsetHeight + 10) + "px";
	 	growAdTimer= window.setTimeout("growAd('"+id+"',"+target+")",10);
	}
	else
	{
		el.style.height = target + "px";
		initRequest("GET","/Modules/Dropdown_ad.aspx?q=open",true,swapAd);
	}
}
/*-------------------*/
var closeTimer;
function swapAd()
{
	if(ajax.readyState == 4 && ajax.status == 200)
	{
		var el = document.getElementById("falconsStore");
		el.innerHTML = ajax.responseText;
		exeJavascript(ajax.responseText);
		var openedAd = document.getElementById("openedAd");
		// openedAd.onmouseout = function() { closeTimer = window.setTimeout("close365Ad('falconsStore','rightCol')",5000) };
		// openedAd.onmouseover = function() { clearTimeout(closeTimer); };
	}
}
/*-------------------*/

function initSwap()
{
	clearAdTimers();
	var el = document.getElementById("adImageCont");
	var adImage = document.getElementById("adImage");
	adCount++;
	if(adCount >= adImgArray.length)
		adCount = 0;

	fadeOut("adImage",100,20,30,null,swapAdImages);
	
}
/*-------------------*/

function swapAdImages()
{
	var imgEl = document.getElementById("adImage");
	imgEl.src = imgObj[adCount].src;
	fadeIn("adImage",20,100,30);
	swapAdImgTimer = window.setTimeout("initSwap()",3000);
}

function clearAdTimers()
{
	clearTimeout(swapAdImgTimer);
	clearTimeout(fadeInTimer);
	clearTimeout(fadeOutTimer);
}


/*-------------begin sideScroll----------------*/
function SideScroll(values)
{
	this.duration = .5;
	var frames = 30;
	this.tIncrement = Math.round((this.duration*1000)/frames); // time increment

	this.container = document.getElementById(values["container"]);
	this.leftBtn = document.getElementById(values["leftBtn"]);
	this.rightBtn = document.getElementById(values["rightBtn"]);
	this.elementsShown = values["elementsShown"];
	
	var self = this;
	this.leftBtn.onclick = function() { self.direction = "left"; self.initSlide(); return false; };
	this.rightBtn.onclick = function() { self.direction = "right"; self.initSlide(); return false; };
	this.slideTimer;
	this.startPos = this.container.offsetLeft;
	
	this.itemsClass = values.items;
	this.getElementSize();

	this.container.style.width = this.numElements * this.elementSize + "px";
	this.totalDistance = (this.numElements * this.elementSize) - this.startPos;
	this.moveDistance = (this.elementsShown * this.elementSize)  - this.startPos;

	this.distanceMoved = 0;

	this.count = 1;
	this.scrollElements = this.container.getElementsByTagName("a");
	if(!values["startNum"])
		this.elementNum = 0;
	else
		this.elementNum = values["startNum"];
	this.cleanElements();
	//this.container.style.left = (this.elementSize * (-this.elementNum) + this.startPos) + "px";
	
	this.tMultiply = 0; // time multipler
	this.objName = values.objName;
	var count = 0;
	// prescroll the elements
	while(count < this.elementNum)
	{
		//var temp = this.container.removeChild(this.container.firstChild);
		this.container.appendChild(this.container.removeChild(this.container.firstChild));
		count++;
	}
}
/*--------------------------*/

// remove non-element nodes
SideScroll.prototype.cleanElements = function()
{
	// remove non-element nodes
	var childs = this.container.childNodes;
	for(var i = 0; i < childs.length; i++)
	{
		if(childs[i].nodeType != 1)
		{
			this.container.removeChild(childs[i]);
		}
	}
}
/*--------------------------*/

SideScroll.prototype.initSlide = function()
{
	var frames = 30 * this.duration;
	this.increment = Math.round(this.moveDistance/frames);
	
	if(this.direction == "left")
	{
		this.slideLeft();
	}
	if(this.direction == "right")
	{
		var count = 0;
		while(count < this.elementsShown)
		{
			var childs = this.container.childNodes;
			this.container.insertBefore(childs[childs.length-1],this.container.firstChild);
			count++;
		}
		this.container.style.left = ((this.elementSize*this.elementsShown-this.startPos)*-1) + "px";
		this.slideRight();
	}
	return false;
}
/*--------------------------*/

SideScroll.prototype.slideLeft = function()
{
	clearTimeout(this.slideTimer);
	//alert(this.distanceMoved + " " + this.moveDistance)
	if(this.distanceMoved < this.moveDistance)
	{
		this.tMultiply++;
		if((this.moveDistance - this.distanceMoved) > this.increment)
			this.container.style.left = (this.container.offsetLeft - this.increment) + "px";
		this.distanceMoved += this.increment;
		var self = this.objName;
		this.slideTimer = window.setTimeout(self+".slideLeft()",(this.tIncrement/this.tMultiply));
	}
	else
	{
		clearTimeout(this.slideTimer);
		this.container.style.left = this.startPos + "px";
		var count = 0;
		while(count < this.elementsShown)
		{
			//var temp = this.container.removeChild(this.container.firstChild);
			this.container.appendChild(this.container.removeChild(this.container.firstChild));
			count++;
		}
		this.tMultiply = 0;
		this.distanceMoved = 0;
	}	
}
/*--------------------------*/

SideScroll.prototype.slideRight = function()
{
	//this.moveElements("right");
	clearTimeout(this.slideTimer);
	if(this.distanceMoved <= this.moveDistance)
	{
		this.tMultiply++;
		if((this.moveDistance - this.distanceMoved) > this.increment)
			this.container.style.left = (this.container.offsetLeft + this.increment) + "px";
		this.distanceMoved += this.increment;
		var self = this.objName;
		this.slideTimer = window.setTimeout(self+".slideRight()",(this.tIncrement/this.tMultiply));
	}
	else
	{
		clearTimeout(this.slideTimer);
		this.container.style.left = this.startPos + "px";		
		this.tMultiply = 0;
		this.distanceMoved = 0;
	}
	
}
/*--------------------------*/

SideScroll.prototype.moveElements = function(dir)
{
	if(dir = "right")
	{
		var childs = this.container.childNodes;
		alert(childs.length);
	}
}
/*--------------------------*/

SideScroll.prototype.getElementSize = function()
{
	var elements = document.getElementsByClassName(this.itemsClass,this.container.id);
	this.numElements = elements.length;
	this.elementSize = elements[0].offsetWidth;
	
	// give the links an onclick event to refresh the event detail section when clicked
	for(var i = 0; i < elements.length; i++)
	{
		var self = this;
		elements[i].onclick = function()
		{
			if(this.getAttribute("rel") != "noAjax")
			{
				setOpacity(document.getElementById("eventHolder"),0);
				window.setTimeout("initRequest('GET','"+this.href+"',"+true+","+"function() { updateEvent('eventHolder',true); })",20);
				self.changeOnState(this);
				return false;
			}
			//return false;
		}
	}
}
/*--------------------------*/
	function scrollStart() {	
		var weekCont = document.getElementById('weeks');
		var startWeek = weekCont.getElementsByTagName('a');
		var start;
		for(i=0;i<startWeek.length;i++) {
			if(startWeek[i].className.match('onWeek')) {
				start = i;
			}
		}
		return start;
	}
	
SideScroll.prototype.changeOnState = function(linkage)
{
	var onWeek = document.getElementsByClassName("onWeek");
	for(var i = 0; i < onWeek.length; i++)
	{
		if(onWeek[i].className.match(/onWeek/))
			onWeek[i].className = onWeek[i].className.replace("onWeek","");
	}
	linkage.className += " onWeek";
}
/*-------------------*/
/***** End: SideScroll Object *****/
/*-----------------beauty randomizer-------------------------*/
function randomize(){
	var container = document.getElementById('homepageBlurb');
	var divs = container.getElementsByTagName('div');
	var random = Math.round(Math.random()*2);
	for(i=0;i<divs.length;i++){
		divs[i].style.display='none';
	}
	switch(random){
	case 0:
		divs[0].style.display='block';
		break;
	case 1:
		divs[1].style.display='block';
		break;
	case 2:
		divs[2].style.display='block';
		break;
	default:
		randomize();
		break;
	}
}