var peopleOkToSize = true;
var articleFontSizing = 'small';
//Striping for poll results
stripePollResults = function () {
	$(".pollResultRow:odd").addClass("pollResultRowOdd");
}

function resizeArticle(size) {
		if(size == "small") {
			$("#newsArticleSizeContent").removeClass();
			$("#newsArticleSizeContent").addClass("newsArticleSizeContentSmall");
		}
		if(size == "normal") {
			$("#newsArticleSizeContent").removeClass();
			$("#newsArticleSizeContent").addClass("newsArticleSizeContentMedium");
		}
		if(size == "large") {
			$("#newsArticleSizeContent").removeClass();
			$("#newsArticleSizeContent").addClass("newsArticleSizeContentLarge");
		}
		
		articleFontSizing = size;
}
// check if user has voted on poll
initPoll = function(pollID, pollurl) {
	if(readCookie(pollID)) {
		$.ajax({type: "GET", url: pollurl,
		   success: function(pollResults){
				$(".ravensPollContent").html(pollResults);
				stripePollResults();
			}
		});
	}
}
function dropDownDefaultState(id, val) {
	var el = document.getElementById(id);
	for(i=0; i <= el.options.length; i++) {
		if(el.options[i].value == val) {
			el.selectedIndex=i;
			return;
		}
	}	
}
function resetShareButtons() {
	
    var delicLink = "http://del.icio.us/post?url="+shareURL+"&title="+shareTitle;
	$("#deliciousLink").attr("href", delicLink);	
	if(shareURL.indexOf('%2fmedia_library%2fVideos') != -1)
    {
	   $("#deliciousLink").click(function() {
			trackVideoBookmark(shareTitle, 'delicious');							 
		});
    }
    else if (shareURL.indexOf('%2fMedia%2fPhoto_Landing.aspx') != -1)
    {
	   $("#deliciousLink").click(function() {
			trackPhotoBookmark(shareTitle, 'delicious');							 
		});    
    }
    else if (shareURL.indexOf('%2fNews%2fArticles%2f') != -1)
    {
	   $("#deliciousLink").click(function() {
			trackNewsBookmark(shareTitle, 'delicious');							 
		});
    }
	
	var fbLink = "http://www.facebook.com/sharer.php?u="+shareURL+"&t="+shareTitle;
	$("#facebookLink").attr("href", fbLink);
	if(shareURL.indexOf('%2fmedia_library%2fVideos') != -1)
    {
	   $("#facebookLink").click(function() {
			trackVideoBookmark(shareTitle, 'facebook');							 
		});
    }
    else if (shareURL.indexOf('%2fMedia%2fPhoto_Landing.aspx') != -1)
    {
	   $("#facebookLink").click(function() {
			trackPhotoBookmark(shareTitle, 'facebook');							 
		});          
    }	
    else if (shareURL.indexOf('%2fNews%2fArticles%2f') != -1)
    {
	   $("#facebookLink").click(function() {
			trackNewsBookmark(shareTitle, 'facebook');							 
		});
    }    
	
	var diggLink = "http://digg.com/submit?phase=2&url="+shareURL+"&title="+shareTitle;
	$("#diggLink").attr("href", diggLink);
		if(shareURL.indexOf('%2fmedia_library%2fVideos') != -1)
    {
	   $("#diggLink").click(function() {
			trackVideoBookmark(shareTitle, 'digg');							 
		});
    }
    else if (shareURL.indexOf('%2fMedia%2fPhoto_Landing.aspx') != -1)
    {
	   $("#diggLink").click(function() {
			trackPhotoBookmark(shareTitle, 'digg');							 
		});
    }
    else if (shareURL.indexOf('%2fNews%2fArticles%2f') != -1)
    {
	   $("#diggLink").click(function() {
			trackNewsBookmark(shareTitle, 'digg');							 
		});
    }    
	
	var stLink = "http://www.stumbleupon.com/submit?url="+shareURL;
	$("#stumbleLink").attr("href", stLink);
	if(shareURL.indexOf('%2fmedia_library%2fVideos') != -1)
    {
	   $("#stumbleLink").click(function() {
			trackVideoBookmark(shareTitle, 'stumble');							 
		});
    }
    else if (shareURL.indexOf('%2fMedia%2fPhoto_Landing.aspx') != -1)
    {
	   $("#stumbleLink").click(function() {
			trackPhotoBookmark(shareTitle, 'stumble');							 
		});
    }	
    else if (shareURL.indexOf('%2fNews%2fArticles%2f') != -1)
    {
	   $("#stumbleLink").click(function() {
			trackNewsBookmark(shareTitle, 'stumble');							 
		});
    }    
}

function openShareBox(e) {
	resetShareButtons();
	var shareBox = $("#shareBox").css("display");
	if(shareBox == "none") {
		var posShareX = getXCoords(e) - 56;
		var posShareY = getYCoords(e) - 40;
		var shareBoxPos = $("#shareBox");
		shareBoxPos.css("left", posShareX);
		shareBoxPos.css("top", posShareY);
		shareBoxPos.css("display", "block");
	} else {
		$("#shareBox").css("display", "none");
	}
	return false;
}
// gets the mouse X coords
function getXCoords(e)
{
	posx = 0;
	if(!e)
	var e = window.event;
	if(e.pageX)
		posx = e.pageX;
	else if (e.clientX)
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	return posx;
}
/*----------------------*/

// gets the mouse X coords
function getYCoords(e)
{
	posy = 0;
	if(!e)
		var e = window.event;
	if(e.pageY)
		posy = e.pageY;
	else if (e.clientY)
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	return posy;
}
/*----------------------*/

function setPhotoInfo(title, date, description, url, tags) {
	shareURL = url;
	shareTitle = title;
	$("#photoLandTitle").html(title);
	$("#photoLandDate").html(date);
	$("#photoLandDesc").html(description);
	$("#photoLandTags").html(tags);
	resetShareButtons()
}

// check the form field elements on focus, if it has "Required" as its vale, clear it.  if it has the color of red, clear it.
function clearReq(){
	var formInputs = document.getElementById("contactForm").getElementsByTagName("input");
	for(var i = 0; i < formInputs.length; i++) {
		if (formInputs[i].value == "Required")
			formInputs[i].value = "";				
	}
}


$(document).ready(function() {
	if (!window.attachEvent) showRssBox();
	/*$(".rssDropMenu").click(function() {
		toggleRSSBox(this);
		return false;
	});
	
	$("#rssBoxCloseButton").click(function() {
		$("#rssListBox").hide();
		return false;
	});*/

	// check page for for id "contactForm", it it exists run function clearReq
	if (document.getElementById('contactForm')) {
		clearReq();
	}
	
	
	// setting default for resizing buttons
	$("#newsArticleSizeContent").addClass("newsArticleSizeContentSmall");
	
	
	// make sure all ribbon columns are the same height
	var subNavs = $(".subNavRibbon");
	subNavs.each(function() {
		setHeight=0;
		var subNavCols = this.getElementsByTagName("UL");
		for(var i = 0;i < subNavCols.length; i++) {
			var eachCol = $(subNavCols[i]).height();
			if(parseInt(eachCol) > setHeight) {
				setHeight = parseInt(eachCol);
			}
		}
		$(subNavCols).height(setHeight);
	});
	
	// even out boxes on news feature landing
		$(".newsFeatureSmallBoxes").each(function(e) {
			setHeight = 0;
			var featBoxes = $(".newsFeatureSmallBoxes:eq("+e+") .defaultBoxTop30");
			for(var i = 0;i < featBoxes.length; i++) {
				var eachCol = $(featBoxes[i]).height();
				if(parseInt(eachCol) > setHeight) {
					setHeight = parseInt(eachCol);
				}
			}
			$(featBoxes).height(setHeight);
		});
	
	if ($("#IsTopicTabActive").attr("value") == "false" || $("#mostsearched_tab").parent().hasClass("active")) {	
	    document.getElementById('tab1').style.display = '';
	} 
	
	$("#mostsearched_tab").click(function() {
		$("#IsTopicTabActive").attr("value", "false");
        document.getElementById('tab1').style.display = '';

		thisParent = $(this).parent();
		if(thisParent.hasClass("active")) {
			return false;
		} else {
			$("#topicBrowseLand").hide();
			$("#newsBrowseTabs .active").removeClass("active");
			thisParent.addClass("active");
			$(".tagCloud").animate({opacity: 'show'}, "slow");
			return false;
		}
	});
	
	$("#topic_tab").click(function() {
		$("#IsTopicTabActive").attr("value", "true");
	    document.getElementById('tab1').style.display = "none";

		thisParent = $(this).parent();
		if(thisParent.hasClass("active")) {
			return false;
		} else {
			$(".tagCloud").hide();
			$("#newsBrowseTabs .active").removeClass("active");
			thisParent.addClass("active");
			$("#topicBrowseLand").animate({opacity: 'show'}, "slow");
			return false;
		}							   
	});
	
	// changing active filter for header search
	$("#searchOption li a").click(function () {
		var newFilterAction = $(this).attr("href");
		$("#siteSearchForm").attr("action",newFilterAction);
		$("#searchOption li").removeClass("activeFilter");
		$(this).parent().addClass("activeFilter");
		return false;
	});
	
	if($("#shareButton")) {
		//resetShareButtons();
	}
	
	$("#shareButton").click(function(e) {
		resetShareButtons();
		var shareBox = $("#shareBox").css("display");
		if(shareBox == "none") {
			var posShareX = e.pageX - 56;
			var posShareY = e.pageY - 40;
			var shareBoxPos = $("#shareBox");
			shareBoxPos.css("left", posShareX);
			shareBoxPos.css("top", posShareY);
			shareBoxPos.css("display", "block");
		} else {
			$("#shareBox").css("display", "none");
		}
		return false;
	});
	
	
	// home article filter striping
	$(".homeFilterItems li:odd").addClass("oddRow");
	
	// striping on feeds page - 2 calls(even and odd)
	$(".feeds:odd").addClass("evenRow");
	$(".feeds:even").addClass("oddRow");
	
	//striping for press room 
	$("#pressRoomList li:odd").addClass("oddRow");
	
	//Striping for default tables
	$(".defaultTable tr:even").addClass("evenRow");
	
	// alternating box color for events calendar module
	$(".eventCalendar td:odd").addClass("oddBox");
	
	// striping for cheer landing lists
	$(".cheerLandBandedLists").each(function(i) {
		$(".cheerLandBandedLists:eq("+i+") li:odd").addClass("oddRow");
	});
	
	// events detail boxes striping
	$(".eventsDetailItem:odd").addClass("evenEventsDetailItem");
	
	//Striping for search results
	$("#searchResults .searchResult:even").addClass("evenSearch");
	
	//Striping for default module lists
	$(".bandedListModule").each(function(i) {
		$(".bandedListModule:eq("+i+") li:odd").addClass("oddModList");
	});

	//las class for wallpaper module
	$(".defaultModBox .wallpaperModItem:last").addClass("lastWallpaperItem");
	
	//Striping for news topic lists
	$(".newsTopicList").each(function(n) {
		$(".newsTopicList:eq("+n+") li:odd").addClass("topicOdd");
	});
	
	// alternating row striping for cheer bio page
	//$("#cheerTable tr:odd").addClass("even");
	$("#cheerTable tr:odd").each(function(e) {
		$(this).addClass("even");
	});
	
	
	// function for tabs on player bio pages
	$(".playerBioTabContent:first").show();
	
	showBioContent = function(id, showDiv) {
		$(".playerBioTabContent").hide();
		$("#playerBioTabs .active").removeClass("active");
		$("#"+id).parent().addClass("active");
		$("#"+showDiv).animate({opacity: 'show'}, "slow");
	}
	
	// people landing "windows"
	$(".peopleLandBox").mouseover(function () {
		if(peopleOkToSize && !$(this).hasClass("opened")) {
			peopleOkToSize = false;
			$(".opened").animate({width: '168px'}, "normal");
			$(".opened").removeClass("opened");
			$(this).animate({width: '395px'}, "normal", function() { peopleOkToSize = true; });
			$(this).addClass("opened");
		}
	}); 
	
	
	// browse news module tabs - 2 functions
	browseNewsTags = function(id) {
		$("#IsTopicTabActive").attr("value", "false");
		$(".moduleNewsTopic").hide();
		$(".moduleTabs .activeTab").removeClass("activeTab");
		$(id).parent().addClass("activeTab");
		$(".moduleTagCloud").animate({opacity: 'show'}, "slow");
	}
	browseNewsTopic = function(id) {
		$("#IsTopicTabActive").attr("value", "true");
		$(".moduleTagCloud").hide();
		$(".moduleTabs .activeTab").removeClass("activeTab");
		$(id).parent().addClass("activeTab");
		$(".moduleNewsTopic").animate({opacity: 'show'}, "slow");
	}
	
	// ravens poll module
	getPollResults = function(pollID, pollResultPage) {
		var pollValue;
		$("input:radio").each( function(f) {
			if($("input:radio:eq("+f+")").attr("checked")) {
				pollValue = $(this).attr("value");
			}
		});
		if(!pollValue) {
			alert("Please select a poll answer");
		} else {
			$.ajax({
				type: "GET",
				url: pollResultPage,
				data: "pollID=" + pollID + "&poll="+pollValue,
				success: function(pollResults){
					createCookie(pollID, pollValue, 365);
					$(".ravensPollContent").animate({opacity: 'hide'}, "fast", function() {
						$(".ravensPollContent").html(pollResults);
						stripePollResults();
						$(".ravensPollContent").animate({opacity: 'show'}, "show");
					});
				}
			});
		}
		return false;
	}
	
	// ravens call module
	$(".subscribeNowStepOne").click(function() { 
		$(".ravensCallStepOne").hide();
		$(".ravensCallStepTwo").animate({opacity: 'show'}, "slow");
		return false;
	})
	
	$(".subscribeNowCancel").click(function() { 
		$(".ravensCallStepTwo").hide();
		$(".ravensCallStepOne").animate({opacity: 'show'}, "slow");
		return false;
	})
	
	cancelRavensCallMod = function() {
		$(".ravensCallStepTwo").hide();
		$(".ravensCallStepOne").animate({opacity: 'show'}, "slow");
		return false;
	}
	
	ravensCallSubmit = function(thankYouUrl) {
			var testBDay;
			var okToSend;
			
			fNameVal = $("#RCFirstName").attr("value");
			lNameVal = $("#RCLastName").attr("value");
			bDayVal = $("#RCBDay").attr("value");
			eMailVal = $("#RCEmail").attr("value");
			
			if(fNameVal == "* First Name") {
				window.alert("Please fill out all required fields");
				return false;
			}
			if(lNameVal == "* Last Name") {
				window.alert("Please fill out all required fields");
				return false;
			}
			if(bDayVal == "* Date of Birth - MM/DD/YYYY") {
				window.alert("Please fill out your birthday with the correct format. e.g: MM/DD/YYYY");
				return false;
			} else {
				testBDay = true;	
			}
			if(eMailVal == "* Email") {
				window.alert("Please fill out all required fields");
				return false;
			}
			
			if(testBDay = true) {
				bDayFilter = /^(\d{2})[\s\.\/-](\d{2})[\s\.\/-](\d{4})$/;
				if(bDayFilter.test(bDayVal)) {
					bDayYear = parseFloat(bDayVal.slice(6,10)) + 14;
					bDayMon = parseFloat(bDayVal.slice(0,2)) - 1;;
					bDayDay = bDayVal.slice(3,5);
					bdayFull = new Date(bDayYear,bDayMon, bDayDay);
					curDate = new Date();
					
					testBDay = Date.parse(bdayFull);
					testCurDate = Date.parse(curDate);
					
					
					if(testBDay < testCurDate) {
						okToSend = true;
					} else {
						okToSend = false;
						window.alert("You Must be at least 14 years of age");
						return false;
					}
					
				} else {
					window.alert("Please fill out your birthday with the correct format. e.g: MM/DD/YYYY");
					okToSend = false;
				}
			}
			
			if(okToSend) {
				var theCallForm = $(".ravensCallStepTwo");
				theCallForm.submit();
				$.ajax({
					type: "GET",
					url: thankYouUrl,
					data: "fname="+fNameVal,
					success: function(ravensCallThankyou){
						$(".ravensCallStepTwo").animate({opacity: 'hide'}, "fast", function() {
							$(".ravensCallStepTwo").html(ravensCallThankyou);
							$(".ravensCallStepTwo").animate({opacity: 'show'}, "show");
						});
					}
				});
			} else {
				return;
			}
	}
	// end ravens call module
	
	
	// content header extra buttons and stuff vertical centering
	var contentHeaderRows = $(".contentHdrExtraRow");
	if(contentHeaderRows.length < 2) {
		$("#contentHdrExtra").css("padding-top", "40px");
	}
	
	
	// getting URL var for default state browse news
	if(window.location.search) {
		var windowLocation = window.location.search;
		windowLocation = windowLocation.split("&");
		windowLocation = /t=\d{1}/.exec(windowLocation);
		if(windowLocation) {
			windowLocationVal = windowLocation[0].slice(2,3);
			if(windowLocationVal == 2) {
				$(".tagCloud").hide();
				$("#newsBrowseTabs .active").removeClass("active");
				topicTabParent = $("#topic_tab").parent();
				topicTabParent.addClass("active");
				$("#topicBrowseLand").show();
			}
		}
	}
	
	// gameday scroller
	
	function scrollGameday(dir) {
		var cssDir= (dir<0) ? 'right':'left';
		var scrollWidth = 845;
		var scrollSpeed = 845;
		var scrollWrapLeft = parseInt($("#gameScroller").css("left"));

		if(okScroll == false) {
			return;
		}
		if(cssDir == "left") {
			if($("#arrowRight").hasClass("disable")) 
				$("#arrowRight").removeClass('disable');
			if(currentPane <= 1) {
				return;
			} else {
				scrollWrapLeft = (scrollWrapLeft + (dir * scrollWidth));
				okScroll = false;
				$("#gameScroller").animate({left: scrollWrapLeft+"px"}, scrollSpeed, function() {
					okScroll = true;
				});
				currentPane = currentPane-dir;
				if(currentPane <= 1) {
					if(!$("#arrowLeft").hasClass("disable")) 
						$("#arrowLeft").addClass('disable');
				}
			}
		}
		if(cssDir == "right") {
			if($("#arrowLeft").hasClass("disable")) 
				$("#arrowLeft").removeClass('disable');
			if(currentPane >= paneCount) {
				if(!$("#arrowRight").hasClass("disable")) 
					$("#arrowRight").addClass('disable');
				return;
		} else {
				scrollWrapLeft = (scrollWrapLeft + (dir * scrollWidth));
				okScroll = false;
				$("#gameScroller").animate({left: scrollWrapLeft+"px"}, scrollSpeed, function() {
					okScroll = true;
				});
				currentPane = currentPane-dir;
				if(currentPane >= paneCount) {
					if(!$("#arrowRight").hasClass("disable")) 
						$("#arrowRight").addClass('disable');
				}
			}
		}
		
		checkCurrentPane(currentPane);
	}
	
	function checkCurrentPane(currentPane) {
		alert('check');
		if(currentPane == 1) {
			if(!$("#arrowLeft").hasClass("disable")) 
				$("#arrowLeft").addClass('disable');
		} else if(currentPane == paneCount) {
			if(!$("#arrowRight").hasClass("disable")) 
				$("#arrowRight").addClass('disable');
		}
	}

	$("#gameScroller").each(function (i) {
		var scrollWidth = 845;
		var newLeftPos = (i * scrollWidth)+"px";
		$("#gameScroller:eq("+i+")").css("left", newLeftPos);
		var items = $('.game');
		$('#gameScroller').css('width', items.length * items[0].offsetWidth + 'px');
		$("#arrowLeft").click(function() {
			scrollGameday(1);
			return false;
		});
		$("#arrowRight").click(function() {
			scrollGameday(-1);
			return false;
		});

	});
	if("#gameScroller") {
		var okScroll = true;
		var currentPane = 1;
		var paneCount = Math.ceil(($(".game").length) / 10);
		if(paneCount <= 1) {
			$(".arrow").className = $(".arrow").className + ' disable';
		} else if (paneCount > 1) {
				$("#arrowLeft").addClass('disable');
		}
		preScroll();
	}
	function preScroll() {
		var games = $('.game');
		for(n=0; n<games.length; n++) {
			if(games[n].className.match('active')) {
				var currFrame = Math.floor(n/10);
				scrollGameday(-currFrame);
			}
		}
	}	
	
	
	// ravenstown scroller
	
	$("#ravenstownScrollHide .rtScrollContent").each(function (i){
		var scrollWidth = 910;
		var newLeftPos = (i * scrollWidth)+"px";
		$("#ravenstownScrollWrap .rtScrollContent:eq("+i+")").css("left", newLeftPos);
	});
	
	if($("#ravenstownScrollHide")) {
		var totalScrollPanes = $("#ravenstownScrollHide a").length;
		totalScrollPanes = parseInt(totalScrollPanes) * 182;
		$("#ravenstownScrollWrap").width(totalScrollPanes+"px");
	}
	
	$("#scrollLeft").click(function() {
		scrollRavensTown(1);
		return false;
	});
	$("#scrollRight").click(function() {
		scrollRavensTown(-1);
		return false;
	});
	
	var rtCurrentPane = 1;
	var rtPaneCount = Math.ceil(($("#ravenstownScrollHide a").length) / 5);
	if(rtPaneCount <= 1) {
		$(".scrollButton").hide();
	} else if (rtPaneCount > 1) {
		$("#scrollLeft").hide();
	}
	
	var okToScroll = true;

	function scrollRavensTown(dir) {
		var cssDir= (dir==-1) ? 'right':'left';
		var scrollWidth = 910;
		var scrollSpeed = 910;
		var scrollWrapLeft = parseInt($("#ravenstownScrollWrap").css("left"));

		if(okToScroll == false) {
			return;
		}
		if(cssDir == "left") {
			$("#scrollRight").show();
			if(rtCurrentPane <= 1) {
				return;
				/*scrollWrapLeft = -1 * (scrollWidth * (rtPaneCount - 1));
				okToScroll = false;
				$("#ravenstownScrollWrap").animate({left: scrollWrapLeft+"px"}, scrollSpeed, function() {
					okToScroll = true;
				});
				rtCurrentPane = rtPaneCount;*/
			} else {
				scrollWrapLeft = (scrollWrapLeft + (dir * scrollWidth));
				okToScroll = false;
				$("#ravenstownScrollWrap").animate({left: scrollWrapLeft+"px"}, scrollSpeed, function() {
					okToScroll = true;
				});
				rtCurrentPane--;
			}
		}
		if(cssDir == "right") {
			$("#scrollLeft").show();
			if(rtCurrentPane >= rtPaneCount) {
				return;
				/*okToScroll = false;
				$("#ravenstownScrollWrap").animate({left: "0px"}, scrollSpeed, function() {
					okToScroll = true;
				});
				rtCurrentPane = 1;*/
			} else {
				scrollWrapLeft = (scrollWrapLeft + (dir * scrollWidth));
				okToScroll = false;
				$("#ravenstownScrollWrap").animate({left: scrollWrapLeft+"px"}, scrollSpeed, function() {
					okToScroll = true;
				});
				rtCurrentPane++;
			}
		}
		
		checkCurrentPane(rtCurrentPane);
	}
	
	function checkCurrentPane(rtCurrentPane) {
		if(rtCurrentPane == 1) {
			$("#scrollLeft").hide();
		} else if(rtCurrentPane == rtPaneCount) {
			$("#scrollRight").hide();
		}
	}
	
	$("#position_req").change(function() {
		activateOtherField(this);
	});
	
	$("#selectAllHomeGames").click(function() {
		var currentState = this.checked;
		if(currentState == true) {
			//$(".meHomeGames input:checkbox").attr("checked", "checked");
			$(".meHomeGames input:checkbox").each(function() { 
				if(this.disabled)
					return;
				else
					$(this).attr("checked", "checked");
			});
		} else {
			$(".meHomeGames input:checkbox").attr("checked", "");
		}
	});
	
	$(".meHomeGames input:checkbox").click(function() {
		var checkAllState = document.getElementById("selectAllHomeGames").checked;
		if(checkAllState == true) {
			$("#selectAllHomeGames").attr("checked","");
		}
	});
	
	
	// new rss box functionality
	$("#rssListBox ul li:last").addClass("lastItem");

   // $(window).bind('resize', function() {
   //     $("#rssListBox").hide();
   // });

});
function toggleRSSBox(el) {
	coords = findPos(el);
	newCoord = parseInt(coords[1], 10) + 15;
	newCoordLeft = parseInt(coords[0], 10) - 147;
	$("#rssListBox").css("left",newCoordLeft);
	$("#rssListBox").css("top",newCoord);
	//$("#rssListBox").css("display","block");
	$("#rssListBox").toggle();
}
/*function hideRSSBox(el) {
	$("#RSSListBox").hide();
}*/
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	return [curleft,curtop];
	}
}



function checkModuleListBanding() {
	if($.browser.msie) {
		window.setTimeout("bandModules()", 1000);
	}
}
function bandModules() {
	$(".bandedListModule").each(function(i) {
		$(".bandedListModule:eq("+i+") li:odd").addClass("oddModList");
	});
}
// execute javascript from the AJAX responset text
function exeJavascript(responseText) {
  // RegExp from prototype.sonio.net
  var ScriptFragment = "(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)";         
  var matchExp    = new RegExp(ScriptFragment, "img");
  var scripts  = responseText.match(matchExp);
  if(scripts)
	{
		var js = "";
        for(var s = 0; s < scripts.length; s++)
		{
            var matchExp = new RegExp(ScriptFragment, "im");
            js += scripts[s].match(matchExp)[1];
        }
        eval(js);
    }
}


getHomeTabInfo = function(homeTabRequest, url) {
	$.ajax({type: "GET", url: url,
	   success: function(newTabInfo){
		    $(".homeTabContent").hide();
			$(".homeTabContent").html(newTabInfo);
			$(".homeTabContent").animate({opacity: 'show'}, "slow");
			exeJavascript(newTabInfo);
			$(".homeFilterItem:odd").addClass("oddRow");
		}
	});
}
changeHomeTab = function(contentId, tabId, url) {
	tabParent = $("#"+tabId).parent();
	if(!tabParent.hasClass("activeTab")) {
		$(".homeTabContent > *").hide();
		$(".homeTabs .activeTab").removeClass("activeTab");
		tabParent.addClass("activeTab");
		getHomeTabInfo(contentId, url);
		$("#"+contentId).show();
		//stripePollResults();
		//$("#"+contentId).show();
	}
	//$("#"+contentId).animate({opacity: 'show'}, "slow");
	return false;
}


sfHover = function() {
	var sfEls = document.getElementById("siteNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}


nflHover = function() {
	var sfEls = document.getElementById("nflNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" nflhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" nflhover\\b"), "");
		}
	}
}
socialHover = function() {
	var sfEls = document.getElementById("socialBarDropWrap");

	sfEls.onmouseover=function() {
		this.className+=" socialhover";
	}
	sfEls.onmouseout=function() {
		this.className=this.className.replace(new RegExp(" socialhover\\b"), "");
	}
}

if (window.attachEvent) window.attachEvent("onload", socialHover);
if (window.attachEvent) window.attachEvent("onload", sfHover);
if (window.attachEvent) window.attachEvent("onload", nflHover);
if (window.attachEvent) window.attachEvent("onload", showRssBox);

function showRssBox() {
	
	//document.getElementById("rssListBox").style.display="block";
	document.getElementById("rssBoxCloseButton").onclick=function() {
		document.getElementById("rssListBox").style.display="none";
		return false;
	}
}

function stripeRows(contID)
{
	$("#"+contID+" .show").removeClass("oddRow");
	$("#"+contID+" .show:odd").addClass("oddRow");
}


/*----------------------*/
function createCookie(name,value,days)
{
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
		var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
}
/*----------------------*/

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length,c.length);
	}
	return false;
}
/*----------------------*/

function printPage()
{
	window.print();
}

/*----------------------*/

function openWin(url,wName,para)
{
	//alert(typeof(arguments[2]));
	if(typeof(arguments[2]) == "object")
		var values = _parameters(arguments[2]);
	window.open(url,wName,values);
}


function _parameters(attributes)
{
	var values = [];
	for(attribute in attributes)
	{
		values.push(attribute + "=" + attributes[attribute].toString());
	}
	return values.join(",");
}
/*----------------------*/



// empties a text field of it's default value when a user first clicks into the text field
// when the text field loses focus, the default value is written back if no user defined value is entered
function scanInputs()
{
	var combinedFields = new Array();		// going to hold the the NodeLists for both inputs[text] and textareas

	// grab all inputs with a type of text and push the returned NodeList to the array. Repeat for textareas
	var inputs = document.getElementsByTagName("input");
	for(var i = 0; i < inputs.length; i++)
	{
		combinedFields.push(inputs[i]);
	}
	var textAreas = document.getElementsByTagName("textarea");
	for(var i = 0; i < textAreas.length; i++)
	{
		combinedFields.push(textAreas[i]);
	}

	inputValuesArray = new Array();		// holds the associative array [name] = value/innerHTML

	for(var i = 0; i < combinedFields.length; i++)
	{

		// check to see if it's a text field. The first part of the statement is so we don't throw an error when on textareas since they don't have type attr
		if(combinedFields[i].getAttribute("type") && combinedFields[i].getAttribute("type").toLowerCase() == "text" && inputs[i])
		{
			inputValuesArray[inputs[i].getAttribute("name")] = inputs[i].value;
			combinedFields[i].onfocus = function()
			{
				if(this.value == inputValuesArray[this.getAttribute("name")]) {
					this.value = "";
				} else if (this.value = "Other*") {
					this.value ="";	
				}
			}
			combinedFields[i].onblur = function()
			{
				if(this.value == "") {
					if((inputValuesArray[this.getAttribute("name")] == undefined) && (this.id = "otherField")) {
						this.value = "Other*";
					} else {
						this.value = inputValuesArray[this.getAttribute("name")];	
					}
				}
			}
		}
		else if(combinedFields[i].nodeName.toLowerCase() == "textarea")
		{
			inputValuesArray[combinedFields[i].getAttribute("name")] = combinedFields[i].innerHTML;
			combinedFields[i].onfocus = function()
			{
				if(this.innerHTML == inputValuesArray[this.getAttribute("name")]) 
					this.innerHTML = "";
				
			}
			combinedFields[i].onblur = function()
			{
				if(this.innerHTML == "") {
					this.innerHTML = inputValuesArray[this.getAttribute("name")];
				}
			}
		}
	}
}
/*----------------------*/
var globalTileCount = 2;
var tileArray = new Array();
function getNextTileId(url) {
       if(url.length > 0)
       {
           if(tileArray.length > 0)
           {
                   if(tileArray[1][0] == url)
                   {
                           return tileArray[1][1];
                   }
                   else
                   {
                           for(var i = 2; i < tileArray.length; i++)
                           {
                                   if(tileArray[i][0] == url)
                                   {
                                           return tileArray[i][1];
                                   }
                                   else
                                   {
                                           tileArray[i] = new Array();
                                           tileArray[i][0] = url;
                                           tileArray[i][1] = globalTileCount++;
                                           return tileArray[i][1];
                                   }
                           }
                   }
           }
           else
           {
                   tileArray[1] = new Array();
                   tileArray[1][0] = url;
                   tileArray[1][1] = globalTileCount++;
                   tileArray[2] = new Array();
                   return tileArray[1][1];
           }
       } else {
            return globalTileCount++;
       }
}

/*----------------------*/

function validateForm(form)
{
	var errCount = 0;
	var ageField = document.getElementById("redirect");
	if(ageField)
		var ageCheck = checkAge(form,ageField);
	
	for(var i = 0; i < form.elements.length; i++)
	{
		var error = false

		// if the field name ends with _req & there is still a asterisk as the last charactr of the value throw an error
		if(form.elements[i].name.match(/_req$/) && form.elements[i].value.match(/\*$/))
			error = true;

		// validate select-one fields
		if(form.elements[i].type == "select-one")
		{
			//alert(form.elements[i].selectedIndex)
			if(form.elements[i].name.match(/_req$/) && (form.elements[i].options[form.elements[i].selectedIndex].value.match(/\*$/) || form.elements[i].options[form.elements[i].selectedIndex].text.match(/\*$/)))
				error = true;
		}
		
		// if the element was a text field
		if (form.elements[i].type == "text")
		{
			// if it is required and the value is blank OR is still "Required"
			if (form.elements[i].name.match(/_req$/) && form.elements[i].value == "" || form.elements[i].value == "Required")
			{
				form.elements[i].onfocus = function() {
					if(this.value == "Required") {
						this.value="";
						this.style.color = "inherit";
					}
				};
				// set the text to say required and color it red
				form.elements[i].value = "Required";
				form.elements[i].style.color = "red";
				error = true;
			}
		}
		// if it is an error
		if(error)
		{
			// set font element color red
			form.elements[i].style.color = "red";
			// if it is ie
			if (navigator.appName == "Explorer")
			{
				//set the background color to yellow
				form.elements[i].style.backgroundColor = "yellow";
			}
			
			// error count +1
			errCount++;
		}
		else
		{
			// if there was no error set element foreground and background colors to their original state
			form.elements[i].style.color = "#858585";
			form.elements[i].style.backgroundColor = "#ffffff";		
		}
	}
	
	if(errCount != 0)
		return false;
	else if(ageCheck == "too young")
	{
		ageField.value = 1;
		//alert("too young")
		return true;
	}
	else
	{
		return true;
	}
}
/*----------------------*/

function checkAge(form,ageField)
{
	/* the minumum age you want to allow in */
	var min_age = 14;

	/* change "age_form" to whatever your form has for a name="..." */
	var year = parseInt(document.forms["contactForm"]["birthYear_req"].value);
	var month = parseInt(document.forms["contactForm"]["birthMonth_req"].value) - 1;
	var day = parseInt(document.forms["contactForm"]["birthDay_req"].value);

	var theirDate = new Date((year + min_age), month, day);
	var today = new Date;

	if ( (today.getTime() - theirDate.getTime()) < 0) {
		//alert("You are too young to enter this site!");
		return "too young";
	}
	else {
		return true;
	}
}
/*----------------------*/

function scrollScreen() {
	window.scrollBy(0,1);
}
/* preload tag browsing button bg */
tagBG= new Image(); 
tagBG.src="/media/backgrounds/browse_news_topic_letter.gif";



function activateOtherField(el) {
	var oldName = $("#other").attr("name");
	if(el.options[el.selectedIndex].value == "otherField" || el.options[el.selectedIndex].value == "Other") {
		$("#other").attr("name", "other_req");
		$("#other").css("visibility", "visible");
		$("#otherEndCap").css("visibility", "visible");
	} else {
		$("#other").attr("name", "other");
		$("#other").css("visibility", "hidden");
		$("#otherEndCap").css("visibility", "hidden");
	}
}

function clearDefaultFields(form)
{ 
	var combinedFields = new Array();		// going to hold the the NodeLists for both inputs[text] and textareas

	// grab all inputs with a type of text and push the returned NodeList to the array. Repeat for textareas
	var inputs = document.getElementsByTagName("input");
	for(var i = 0; i < inputs.length; i++)
	{
		combinedFields.push(inputs[i]);
	}
	var textAreas = document.getElementsByTagName("textarea");
	for(var i = 0; i < textAreas.length; i++)
	{
		combinedFields.push(textAreas[i]);
	}
	
	for(i=0; i<combinedFields.length; i++)
	{
		
		var matchMe = /(Address 2|Other*|FedEx Number|Additional Requests|Description of duties)/;
		var ifMatched = matchMe.exec(combinedFields[i].value);
		if(ifMatched)
		combinedFields[i].value="";
		/*el = combinedFields[i];
		switch(el.value)
		{
			case "Address 2": 
			case "Other*":
			case "FedEx Number": 
			case "Additional Requests":
				alert(el.value);
				el.value = "";
				break;
		}*/
	}
}
function validateFormMedia(form)
{
	var errCount = 0;
	$(".radioSet").each(function(i) {
		var okToPass = false;
		for(r=0; r <= $(".radioSet:eq("+i+") input:radio").length; r++) {
			var currentValue = $(".radioSet:eq("+i+") input:radio:eq("+r+")").attr("checked");
			if(currentValue == true)
			okToPass = true;
		}
		for(r=0; r <= $(".radioSet:eq("+i+") input:checkbox").length; r++) {
			var currentValue = $(".radioSet:eq("+i+") input:checkbox:eq("+r+")").attr("checked");
			if(currentValue == true)
			okToPass = true;
		}
		if(!okToPass) {
			errCount++;
			$(".radioSet:eq("+i+") .radioSetTitle").css("color", "red");
		}
		else {
			$(".radioSet:eq("+i+") .radioSetTitle").css("color", "#858585");	
		}
	});
	
	for(var i = 0; i < form.elements.length; i++)
	{
		var error = false
		var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		// all fields with a _req at the end of their name are required fields
		// also check for the * at the end of the field
		
		if(form.elements[i].name.match(/_req$/) && form.elements[i].value.match(/\*$/))
			error = true;
		if(form.elements[i].name == 'contactEmail_req' || form.elements[i].name == 'email_req' || form.elements[i].name == 'staff_email_req') {
			if(emailFilter.test(form.elements[i].value)) {
				error = false;
			} else {
				error = true;
			}
		}
		
		if(form.elements[i].type == "select-one")
		{
			//alert(form.elements[i].selectedIndex)
			
			//if(form.elements[i].selectedIndex == 0)
			if(form.elements[i].name.match(/_req$/) && (form.elements[i].options[form.elements[i].selectedIndex].value.match(/\*$/) || form.elements[i].options[form.elements[i].selectedIndex].text.match(/\*$/)))
				error = true;
		}
		if(error)
		{
			form.elements[i].style.color = "red";
			if(form.elements[i].type == "select-one")
			$(form.elements[i]).addClass("errorDropdown");
			//form.elements[i].parentNode.style.backgroundColor = "yellow";
			errCount++;
		}
		else
		{
			form.elements[i].style.color = "#858585";
			if(form.elements[i].type == "select-one")
			$(form.elements[i]).removeClass("errorDropdown");
			//form.elements[i].parentNode.style.backgroundColor = "#ffffff";
			
		}
	}
	
	if(errCount != 0) {
		$("#errorMessage").html("Please complete all highlighted fields.");
		return false;
	}
	else
	{
		$("#errorMessage").html("");
		clearDefaultFields(form);
		return true;		
	}
}

/* BEGIN: Search Tracking
/*-----------------------------*/
function searchTracking() {
	var url = window.location.toString();
	var urlArray = url.split('?q=');
	var cat;
	var search = urlArray[1];
	if(urlArray[0].match('Site') || urlArray[0].match('Articles')) {
		cat = 1;
	} else if(urlArray[0].match('Images')) {
		cat = 2;
	} else if(urlArray[0].match('Videos')) {
		cat = 3;
	} else if(urlArray[0].match('Audios')) {
		cat = 4;
	} 
	var tracking = '/System/Search/Save%20Search%20Term.aspx?q='+search+'&cat='+cat;
	$.ajax({
		type: "GET",
		url: tracking,
		dataType: "script"
	});
}

/* BEGIN: Gameday
/*---------------------------*/
function changeGamedayTab(contentId, tabId, url) {
	tabParent = $("#"+tabId).parent();
	if(!tabParent.hasClass("activeTab")) {
		$.ajax({type: "GET", url: url,
		   success: function(newGameDayTab){
				$(".gameday_tabContent > *").hide();
				$(".gamedayTabs .activeTab").removeClass("activeTab");
				tabParent.addClass("activeTab");
				$("#"+contentId).html(newGameDayTab);
				$("#"+contentId).show();
			}
		});
		
	}
	return false;
}
function autoRefresh(chkbox) {	// Pass in id of chkbox that will regulate the refresh
	var toggle = document.getElementById(chkbox);
	var refreshInterval;
	toggle.onclick = function() {
		if(toggle.checked) {
			refreshInterval = setInterval('location.reload()', 300000); 
		} else {
			clearInterval(refreshInterval);
		}
	}
	if(toggle.checked) {
		refreshInterval = setInterval('location.reload()', 300000); 
	}
}

/* BEGIN: Checkbox monitoring
/*-----------------------------*/
var checkTally = 0;
function monitorChecks() {
	var checkArr = [];
	var inputArr = document.getElementsByTagName('input');
	for(var i=0; i<inputArr.length; i++) {
		if(inputArr[i].type == 'checkbox') checkArr.push(inputArr[i]);
	}
	for(var m=0; m<checkArr.length; m++) {
		if(checkArr[m].checked) checkTally ++;
		checkArr[m].onclick = function() {
			if(this.checked) {
				checkTally++;
			} else if(checkTally != 0) {
				checkTally --;
			}
			tally = document.getElementById('total').innerHTML = checkTally;
		}
	}
	var tally = document.getElementById('total').innerHTML = checkTally
}	