//function loadCellHover() {
//	$$('td.nbaVideoGridCell').each(function(box) {
//	    box.observe('mouseover', function(event) {
//	        this.setStyle("background:#b8cedd;");
//	    	if (this.down('a',1)) {
//	    		this.down('a',1).setStyle("background:url('/.element/img/1.0/video/nbaVideoGridContentHeader.over.gif')");
//	    	}
//	    }.bindAsEventListener(box));
//	    box.observe('mouseout', function(event) {
//	        this.setStyle("background:#ffffff;");
//	    	if (this.down('a',1)) {
//	    		this.down('a',1).setStyle("background:url('/.element/img/1.0/video/nbaVideoGridContentHeader.gif')");
//	    	}
//	    }.bindAsEventListener(box))
//	});
//}
//
//document.observe('dom:loaded',loadCellHover);

//this function determines whether the event is the equivalent of the microsoft
// mouseleave or mouseenter events. 
function isMouseLeaveOrEnter(e, handler) { 
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}

function nbaVideoGridCellOver(e,objThis) {
	if (isMouseLeaveOrEnter(e,objThis)) {
		objThis.style.backgroundColor='#b8cedd';
		if (objThis.getElementsByTagName('a')[1]) {
			objThis.getElementsByTagName('a')[1].style.background="url('http://i.cdn.turner.com/nba/nba/.element/img/1.0/video/nbaVideoGridContentHeader.over.gif')";
		}
	}
}

function nbaVideoGridCellOut(e,objThis) {
	if (isMouseLeaveOrEnter(e,objThis)) {
		objThis.style.backgroundColor='#ffffff';
		if (objThis.getElementsByTagName('a')[1]) {
			objThis.getElementsByTagName('a')[1].style.background="url('http://i.cdn.turner.com/nba/nba/.element/img/1.0/video/nbaVideoGridContentHeader.gif')";
		}
	}
}

/* global event handlers
=========================================================================== */
function nbaMouseDown(e) {
    if (nbaDropdownOpen) nbaDD.mouseDownBody(e);
      //if (nbaOverlayMenuOpen) nbaOverlayMouseDownBody(e); return true;
  	//if (nbaDropdownTeamsIdxOpen) nbaDDTeamsIdx.mouseDownBody(e);
	//if (nbaDropdownPlayersTeamsIdxOpen) nbaDDPlayersTeamsIdx.mouseDownBody(e);
	//if (nbaDropdownPlayersPlayersIdxOpen) nbaDDPlayersPlayersIdx.mouseDownBody(e);
	//if (nbaDropdownVidPlayerIdxOpen) nbaDDVidPlayerIdx.mouseDownBody(e);
}
/* end global event handlers
=========================================================================== */

/* styled dropdowns
=========================================================================== */
//nba dropdown menu on Video/Games index page (JavaScript object literal)
var nbaDropdownOpen = false;
var nbaDD = {
	curId: "", // id of currently-open dropdown
	ignoreMouseDownBody: false,
	menus: [],

	rowHeight: 43,
	combinedBorderWidth: 20,
	scrollbarWidth: 18,

	minMenuWidth: 105,
	maxMenuWidth: 400,
	defaultMenuWidth: 205,
	defaultRowWidth: 150,
	combinedRowLRPad: 18,
	scrollbarRPad: 12,


	buildDisabledDropdown: function(menuId, buttonWidth, buttonClass, hiddenListSuffix) {
		// default parameters
		if (!buttonWidth) buttonWidth = 140;
		if (!buttonClass) buttonClass = 'nbaDDWireLtg';

		var wrapId = menuId + "_wrap";
		var listId = menuId + "_list" + (hiddenListSuffix ? '_' + hiddenListSuffix : '');

		if ($(wrapId) && $(listId)) {

			// hide the <select>
			$(listId).style.display = "none";

			// Get the displayed value for the first select option
			var listItems = $(listId).options;
			var buttonText = listItems[0].innerHTML;

			var buttonTextLPad = 10;
			var buttonTextRPad = 34;
			var buttonTextWidth = buttonWidth - (buttonTextLPad + buttonTextRPad);

			var leftBgStyle = '';
			var rightBgStyle = '';
			switch (buttonClass) {
				case 'nbaBlue':
					rightBgStyle = 'background:url(http://i.cdn.turner.com/nba/nba/.element/img/1.0/midseason/nbaMSReportDropDown.jpg) 100% 0 no-repeat;';
					break;
			}

			// build content for the button
			var strContent = "\n\n\n\n";
			strContent += '	<div class="nbaDDContainer" style="width:208px;">'+"\n";

			strContent += '		<div class="'+buttonClass+'">'+"\n";
			strContent += '			<div class="nbaDDBtn" onmousedown="return nbaDD.mouseDownBtn(event, \''+menuId+'\');" onclick="return nbaDD.open(\''+menuId+'\')" style="'+rightBgStyle+'">'+"\n";
			strContent += '				<table width="'+buttonWidth+'" border="0" cellspacing="0" cellpadding="0">'+"\n";
			strContent += '					<tr>'+"\n";
			strContent += '						<td width="'+buttonTextLPad+'"></td>'+"\n";
			strContent += '						<td width="'+buttonTextWidth+'">'+"\n";
			strContent += '							<div class="nbaDDValueContainer">'+"\n";
			strContent += '								<div id="'+menuId+'_Val" class="nbaDDValue" style="width:'+buttonTextWidth+'px;color:#c5c5c5;">'+buttonText+'</div>'+"\n";
			strContent += '						</td>'+"\n";
			strContent += '						<td width="'+buttonTextRPad+'">&nbsp;</td>'+"\n";
			strContent += '					</tr>'+"\n";
			strContent += '				</table>'+"\n";
			strContent += '			</div><!--/nbaDDBtn -->'+"\n\n";
			strContent += '		</div><!--/'+buttonClass+' -->'+"\n\n";

			strContent += '	</div><!--/nbaDDContainer -->'+"\n";
			strContent += "\n\n";

			// draw the new content
			$(wrapId).innerHTML = strContent;

			// reset the list
			$(listId).selectedIndex = 0;

		}//else id of select not found [ abort ]
	},

	buildDropdown: function(menuId, buttonWidth, menuWidth, numVisibleRows, buttonClass, hiddenListSuffix) {
		// default parameters
		if (!buttonWidth) buttonWidth = 140;
		if (!menuWidth) menuWidth = this.defaultMenuWidth;
		if (!numVisibleRows) numVisibleRows = 10;
		if (!buttonClass) buttonClass = 'nbaDDWireLtg';

		if (menuWidth < this.minMenuWidth) menuWidth = this.minMenuWidth;
		if (menuWidth > this.maxMenuWidth) menuWidth = this.maxMenuWidth;

		var wrapId = menuId + "_wrap";
		var listId = menuId + "_list" + (hiddenListSuffix ? '_' + hiddenListSuffix : '');

		this.menus[menuId] = new Array();
		this.menus[menuId].listId = listId;
		this.menus[menuId].updateFirstRow = false;

		if ($(wrapId) && $(listId)) {
			// hide the <select>
			$(listId).style.display = "none";

			var displayedValue = new Array();
			var internalValue = new Array();
			var disabledRow = new Array();

			var listItems = $(listId).options;
			for (var i=0;i<listItems.length;i++) {
				displayedValue[i] = listItems[i].innerHTML;
				internalValue[i] = listItems[i].value;
				disabledRow[i] = listItems[i].disabled;
			}
			var selectedRow = $(listId).selectedIndex;

			// If no row was explicitly selected
			if (selectedRow == 0) {
				// See if the first row matches one of the later rows
				for (i=1;i<displayedValue.length;i++) {
					if (displayedValue[i] == displayedValue[0]) {
						selectedRow = i;
						this.menus[menuId].updateFirstRow = true;
						break;
					}
				}
			}
			var buttonText = displayedValue[selectedRow];
			var numRows = displayedValue.length;

			var buttonTextLPad = 10;
			var buttonTextRPad = 34;
			var buttonTextWidth = buttonWidth - (buttonTextLPad + buttonTextRPad);

			// minus left and right borders
			var fullRowWidth = menuWidth - this.combinedBorderWidth;

			// without scrollbar
			var visibleRowsHeight = numRows * this.rowHeight;
			var rowWidth = fullRowWidth;

			// with scrollbar
			if (numRows > numVisibleRows) {
				visibleRowsHeight = numVisibleRows * this.rowHeight;
				//rowWidth -= 10;
			}
			var leftBgStyle = '';
			var rightBgStyle = '';
			var adjFooter = '';

			switch (buttonClass) {
				case 'nbaBlue':
					rightBgStyle = 'background:url(http://i.cdn.turner.com/nba/nba/.element/img/1.0/midseason/nbaMSReportDropDown.jpg) 100% 0 no-repeat;';
					//create expandable footer with centered blue "dots"
					adjFooter  = "<div class='nbaDDBoxFooter'>";
					adjFooter  += "<div style='position:relative;float:left;width:9px;'>&nbsp;</div>";
					var adjustedMenuWidth = rowWidth;
					if (navigator.appName=="Microsoft Internet Explorer") {
						adjustedMenuWidth = rowWidth + 2;
						visibleRowsHeight +=12;
					} 
					adjFooter  += "<div style='width:" + adjustedMenuWidth + "px;'>";
					adjFooter  += "";
					adjFooter  += "</div><!---->"+"\n";
					break;
			}

			// build content for the menu
			var strContent = "\n\n\n\n";
			strContent += '	<div class="nbaDDContainer" style="width:208px;">'+"\n";

			strContent += '		<div class="nbaDDBoxContainer">'+"\n";
			strContent += '		<div class="nbaDDBox" id="'+menuId+'" style="width:'+menuWidth+'px;left:-9px;" onmousedown="return nbaDD.mouseDown(event, \''+menuId+'\');">'+"\n";
			strContent += '			<div class="nbaDDBoxHeader"><div class="nbaDDBoxHeaderTL"></div><div class="nbaDDBoxHeaderTR"></div></div>'+"\n";
			strContent += '			<div class="nbaDDBoxContent">'+"\n";

			strContent += '				<div class="nbaDDContent" style="width:208px;">'+"\n";
			strContent += '					<div class="nbaPad6Top"></div>'+"\n";
			strContent += '					<div class="nbaDDList" style="height:'+visibleRowsHeight+'px; width:208px;padding-top:3px;padding-bottom:8px;">'+"\n";
			strContent += '						<ul>'+"\n";

			for (var i=0;i<displayedValue.length;i++) {
				strContent += '<div class="nbaGraySeparator">';
				if ((i==0) && (this.menus[menuId].updateFirstRow)) {
					strContent += '						<li id="'+menuId+'_hdnVal"><a style="padding-left:0px;" href="javascript:nbaDD.select('+i+',\''+this.encodeAttr(displayedValue[i])+'\',\''+this.encodeAttr(internalValue[i])+'\');">'+displayedValue[i]+'</a></li>'+"\n";
				}
				else if (disabledRow[i]) {
					strContent += '						<li class="nbaDDSeparator"><span>'+displayedValue[i]+'</span></li>'+"\n";
				}
				else {
					strContent += '						<li><a style="padding-left:0px;" href="javascript:nbaDD.select('+i+',\''+this.encodeAttr(displayedValue[i])+'\',\''+this.encodeAttr(internalValue[i])+'\');">'+displayedValue[i]+'</a></li>'+"\n";
				}
				strContent += '</div>';
			}
			strContent += '						</ul>'+"\n";
			strContent += '					</div>'+"\n";
			strContent += '					<div class="nbaPad8Top"></div>'+"\n";
			strContent += '				</div><!-- /nbaDDContent -->'+"\n";

			strContent += '			</div><!-- /nbaDDBoxContent -->'+"\n";
			if (adjFooter.length >0) {
				strContent += adjFooter;
			} else {
			    strContent += '			<div class="nbaDDBoxFooter"><div class="nbaDDBoxFooterBL"></div><div class="nbaDDBoxFooterBR"></div></div>'+"\n";
			}
			strContent += '		</div><!--/nbaDDBox-->'+"\n";
			strContent += '		</div><!--/nbaDDBoxContainer-->'+"\n";

			strContent += '		<div class="'+buttonClass+'">'+"\n";
			strContent += '			<div class="nbaDDBtn" onmousedown="return nbaDD.mouseDownBtn(event, \''+menuId+'\');" onclick="return nbaDD.open(\''+menuId+'\')" style="'+rightBgStyle+'">'+"\n";
			strContent += '				<table width="'+buttonWidth+'" border="0" cellspacing="0" cellpadding="0">'+"\n";
			strContent += '					<tr>'+"\n";
			strContent += '						<td width="'+buttonTextLPad+'"></td>'+"\n";
			strContent += '						<td width="'+buttonTextWidth+'">'+"\n";
			strContent += '							<div class="nbaDDValueContainer">'+"\n";
			strContent += '								<div id="'+menuId+'_Val" class="nbaDDValue" style="width:'+buttonTextWidth+'px;">'+buttonText+'</div>'+"\n";
			strContent += '						</td>'+"\n";
			strContent += '						<td width="'+buttonTextRPad+'">&nbsp;</td>'+"\n";
			strContent += '					</tr>'+"\n";
			strContent += '				</table>'+"\n";
			strContent += '			</div><!--/nbaDDBtn -->'+"\n\n";
			strContent += '		</div><!--/'+buttonClass+' -->'+"\n\n";

			strContent += '	</div><!--/nbaDDContainer -->'+"\n";
			strContent += "\n\n";

			// draw the new content
			$(wrapId).innerHTML = strContent;

			// capture mousedown
			document.body.onmousedown = nbaMouseDown;
		}//else id of select not found [ abort ]
	},

	buildOverlay: function(menuId, menuWidth, numVisibleRows, dx, dy) {
		// default parameters
		if (!menuWidth) menuWidth = this.defaultMenuWidth;
		if (!numVisibleRows) numVisibleRows = 10;

		if (menuWidth < this.minMenuWidth) menuWidth = this.minMenuWidth;
		if (menuWidth > this.maxMenuWidth) menuWidth = this.maxMenuWidth;

		var leftPos = -20;
		var topPos = 1;
		if (dx) leftPos += dx;
		if (dy) topPos += dy;

		var wrapId = menuId + "_wrap";
		var listId = menuId + "_list";
		var titleId = menuId + "_title";

		if ($(wrapId) && $(titleId) && $(listId)) {
			// hide the list
			$(listId).style.display = "none";

			var title = $(titleId).innerHTML;

			// Get the displayed value for each select option
			var listItems = $(listId).getElementsByTagName('li');
			var displayedList = new Array();
			for (var i=0;i<listItems.length;i++) {
				displayedList[i] = listItems[i].innerHTML;
			}

			var numRows = displayedList.length;

			var menuTitleRPad = 60;
			var menuTitleWidth = menuWidth - menuTitleRPad;

			// minus left and right borders
			var fullRowWidth = menuWidth - this.combinedBorderWidth;

			// without scrollbar
			var visibleRowsHeight = numRows * this.rowHeight;
			var rowWidth = menuWidth - this.combinedBorderWidth;

			// with scrollbar
			if (numRows > numVisibleRows) {
				visibleRowsHeight = numVisibleRows * this.rowHeight;
				rowWidth -= 10;
			}


			// build content for the menu
			var strContent = "\n\n\n\n";
			strContent += ' <div class="nbaDDOvrBoxContainer">'+"\n";
			strContent += '		<div class="clear"><img src="http://i.cdn.turner.com/nba/images/1.gif" width="1" height="1" border="0" alt=""></div>'+"\n";
			strContent += '		<div class="nbaDDOvrBox" id="'+menuId+'" style="width:'+menuWidth+'px;left:'+leftPos+'px; top:'+topPos+'px;" onmousedown="return nbaDD.mouseDown(event, \''+menuId+'\');">'+"\n";
			strContent += '			<div class="nbaDDBoxHeader"><div class="nbaDDBoxHeaderTL"></div><div class="nbaDDBoxHeaderTR"></div></div>'+"\n";
			strContent += '			<div class="nbaDDBoxContent">'+"\n";
			strContent += '				<div class="nbaDDOvrCloseContainer"><div class="nbaDDOvrClose" onclick="nbaDD.close(); return true;"><img src="http://i.cdn.turner.com/nba/nba/.element/img/2.0/global/dropdowns/overlay_close.png" width="12" height="12" alt="" border="0"></div></div>'+"\n";
			strContent += '				<div class="nbaDDContent" style="width:208px;">'+"\n";
			strContent += '					<div class="nbaDDOvrTitle" style="width:'+menuTitleWidth+'px;overflow:hidden;">'+title+'</div>'+"\n";
			strContent += '					<div class="nbaDDList" style="height:'+visibleRowsHeight+'px;width:208px;">'+"\n";
			strContent += '						<ul>'+"\n";

			for (var i=0;i<displayedList.length;i++) {
				strContent += '					<li>'+displayedList[i]+'</li>'+"\n";
			}
			strContent += '						</ul>'+"\n";
			strContent += '					</div><!-- /nbaDDList -->'+"\n";
			strContent += '					<div class="nbaPad12Top"></div>'+"\n";
			strContent += '				</div><!-- /nbaDDContent -->'+"\n";
			strContent += '			</div><!-- /nbaDDBoxContent -->'+"\n";
			strContent += '			<div class="nbaDDBoxFooter"><div class="nbaDDBoxFooterBL"></div><div class="nbaDDBoxFooterBR"></div></div>'+"\n";
			strContent += '		</div><!--/nbaDDOvrBox-->'+"\n";
			strContent += ' </div><!--/nbaDDOvrBoxContainer-->'+"\n";
			strContent += "\n\n";
			// draw the new content
			$(wrapId).innerHTML = strContent;

			// capture mousedown
			document.body.onmousedown = nbaMouseDown;

		}//else id of select not found [ abort ]
	},


	select: function(index, displayedValue, internalValue) {
		if ($(this.curId)) {
			var menuId = this.curId;

			// close the dropdown
			this.close();

			// change the displayed dropdown value (button text)
			if ($(menuId + '_Val')) {
				$(menuId + '_Val').innerHTML = displayedValue;
			}

			// set the first row of the menu to the current value
			if ((this.menus[menuId].updateFirstRow) && $(menuId + '_hdnVal')) {
				$(menuId+'_hdnVal').innerHTML = '<a href="javascript:nbaDD.select(' + index + ',\'' + this.encodeAttr(displayedValue) + '\',\'' + this.encodeAttr(internalValue) + '\')">' + displayedValue + '</a>';
			}

			var listId = this.menus[menuId].listId;
			if ($(listId)) {
				// if the value has changed
				if ($(listId).selectedIndex != index) {
					// set the index of the selected option for the invisible <select>
					$(listId).selectedIndex = index;

					// If an onchange event handler exists
					if ($(listId).onchange) {
						$(listId).onchange();
					}
				}
			}

			// if a callback function exists
			try {
				var onChoose = eval(menuId + '_OnChoose');
				if (onChoose) {
					onChoose();
				}
			}
			catch(err) {
			}
		}
	},

	open: function(id) {
		if($(id)) {
			// Was the same menu clicked again?
			var sameMenu = (this.curId == id);

			// If a menu is already open
			this.close();

			// If a different menu was clicked
			if (!sameMenu) {
				$(id).style.display = "block";
				this.curId = id;
				nbaDropdownOpen = true;
			}
		}
	},

	close: function() {
		if ($(this.curId)) {
			$(this.curId).style.display = "none";
			this.curId = '';
			nbaDropdownOpen = false;
		}
	},

	encodeAttr: function(str) {
		str=str.replace(/\\/g,'\\\\');
		str=str.replace(/\'/g,'\\\'');
		str=str.replace(/\"/g,'&quot;');
		str=str.replace(/\0/g,'\\0');
		return str;
	},

	mouseDown: function(e, id) {
		this.ignoreMouseDownBody = true;
		return true;
	},

	mouseDownBtn: function(e, id) {
		// True if the same dropdown button was clicked again.
		this.ignoreMouseDownBody = (id && (this.curId == id));
		return true;
	},

	mouseDownBody: function(e) {
		if (!this.ignoreMouseDownBody) {
			this.close();
		}
		this.ignoreMouseDownBody = false;
		return true;
	}
}

/* end styled dropdowns
=========================================================================== */

/* Start of "next" and "previous" teams functionality*/
var nbaLeagueTeams = [
	{shortName: "hawks", URL: "/2009/reportcard/midseason/hawks/index.html"},
	{shortName: "celtics", URL: "/2009/reportcard/midseason/celtics/index.html"},
	{shortName: "bobcats", URL: "/2009/reportcard/midseason/bobcats/index.html"},
	{shortName: "bulls", URL: "/2009/reportcard/midseason/bulls/index.html"},
	{shortName: "cavaliers", URL: "/2009/reportcard/midseason/cavaliers/index.html"},
	{shortName: "mavericks", URL: "/2009/reportcard/midseason/mavericks/index.html"},
	{shortName: "nuggets", URL: "/2009/reportcard/midseason/nuggets/index.html"},
	{shortName: "pistons", URL: "/2009/reportcard/midseason/pistons/index.html"},
	{shortName: "warriors", URL: "/2009/reportcard/midseason/warriors/index.html"},
	{shortName: "rockets", URL: "/2009/reportcard/midseason/rockets/index.html"},
	{shortName: "pacers", URL: "/2009/reportcard/midseason/pacers/index.html"},
	{shortName: "clippers", URL: "/2009/reportcard/midseason/clippers/index.html"},
	{shortName: "lakers", URL: "/2009/reportcard/midseason/lakers/index.html"},
	{shortName: "grizzlies", URL: "/2009/reportcard/midseason/grizzlies/index.html"},
	{shortName: "heat", URL: "/2009/reportcard/midseason/heat/index.html"},
	{shortName: "bucks", URL: "/2009/reportcard/midseason/bucks/index.html"},
	{shortName: "timberwolves", URL: "/2009/reportcard/midseason/timberwolves/index.html"},
	{shortName: "nets", URL: "/2009/reportcard/midseason/nets/index.html"},
	{shortName: "hornets", URL: "/2009/reportcard/midseason/hornets/index.html"},
	{shortName: "knicks", URL: "/2009/reportcard/midseason/knicks/index.html"},
	{shortName: "thunder", URL: "/2009/reportcard/midseason/thunder/index.html"},
	{shortName: "magic", URL: "/2009/reportcard/midseason/magic/index.html"},
	{shortName: "sixers", URL: "/2009/reportcard/midseason/sixers/index.html"},
	{shortName: "suns", URL: "/2009/reportcard/midseason/suns/index.html"},
	{shortName: "blazers", URL: "/2009/reportcard/midseason/blazers/index.html"},
	{shortName: "kings", URL: "/2009/reportcard/midseason/kings/index.html"},
	{shortName: "spurs", URL: "/2009/reportcard/midseason/spurs/index.html"},
	{shortName: "raptors", URL: "/2009/reportcard/midseason/raptors/index.html"},
	{shortName: "jazz", URL: "/2009/reportcard/midseason/jazz/index.html"},
	{shortName: "wizards", URL: "/2009/reportcard/midseason/wizards/index.html"}
];

function getNBATeamIndex(shortName) {    
                var index=0;
                var teamObj = nbaLeagueTeams.each(function(team) {
                                
                                if (team.shortName == shortName)
                                               throw $break;
                                               index++;
                });
                return index;
}

function getNextLink(shortName){
		var matchIndex = getNBATeamIndex(shortName);
		var nextPageIndex = matchIndex + 1;
		if (matchIndex == 29) {
			nextPageIndex = 0;
		}
		window.location.href = nbaLeagueTeams[nextPageIndex].URL;
		
}

function getPreviousLink(shortName){
		var matchIndex = getNBATeamIndex(shortName);
		var prevPageIndex = matchIndex - 1;
		if (matchIndex == 0) {
			prevPageIndex = 29;
		}
		window.location.href = nbaLeagueTeams[prevPageIndex].URL;
}

//get current year's index files 
var str = window.location.href; 
var pattern = new RegExp("20[0-9][0-9]");
var y= pattern.exec(str);
var teamObj = nbaLeagueTeams.each(function(team) {
     team.URL = '/' + y + '/reportcard/midseason/' + team.shortName + '/index.html';
});
/* End of "next" and "previous" teams functionality*/
