if (document.getElementById && document.getElementsByTagName && document.createElement) {
	document.write('<link rel="stylesheet" type="text/css" href="/utilities/css/navigation_hide.css" />');
}

function tableruler() {
	if (document.getElementById && document.createTextNode) {
		var tables=document.getElementsByTagName('table');

		for (var i=0;i<tables.length;i++) {
			if(tables[i].className=='ruler') {
				var trs=tables[i].getElementsByTagName('tr');

				for(var j=0;j<trs.length;j++) {
					if(trs[j].parentNode.nodeName=='TBODY' && trs[j].parentNode.nodeName!='TFOOT') {
						trs[j].onmouseover=function(){this.className='ruled';return false}
						trs[j].onmouseout=function(){this.className='';return false}
					}
				}
			}
		}
	}
}

function toggleSub(submenu) {
	if (document.getElementById(submenu)) {
		var submenu_toggle = submenu + '_toggle';
		if (document.getElementById(submenu).style.display == 'none') {
			document.getElementById(submenu).style.display = 'block'
			document.getElementById(submenu_toggle).innerHTML = "[-]";
		} else {
			document.getElementById(submenu).style.display = 'none'
			document.getElementById(submenu_toggle).innerHTML = "[+]";
		}
	}
}

function writeImgTag(code,w,h) {
	var cache = document.add_comment.body.value;
	this.code = code;
	this.w = w;
	this.h = h;
	document.add_comment.body.value = cache + " " + code + " ";
	document.add_comment.body.focus();
}

/**
 * @desc function standings()
 * The function standings() builds a small table of current standings
 *   and outputs it as a table inside the given html object.
 *
 * @param string standingsID
 * @param string division
 */
function standings(division) {
	// Build team mascots array.
	var mascots	= new Object;
	mascots['cle']	= 'Indians';
	mascots['det']	= 'Tigers';
	mascots['min']	= 'Twins';
	mascots['cws']	= 'White Sox';
	mascots['kc']	= 'Royals';
	mascots['bos']	= 'Red Sox';
	mascots['nyy']	= 'Yankees';
	mascots['tor']	= 'Blue Jays';
	mascots['bal']	= 'Orioles';
	mascots['tb']	= 'Devil Rays';
	mascots['ana']	= 'Angels';
	mascots['sea']	= 'Mariners';
	mascots['oak']	= "A's";
	mascots['tex']	= 'Rangers';
	mascots['mil']	= 'Brewers';
	mascots['chc']	= 'Cubs';
	mascots['stl']	= 'Cardinals';
	mascots['hou']	= 'Astros';
	mascots['cin']	= 'Reds';
	mascots['pit']	= 'Pirates';
	mascots['nym']	= 'Mets';
	mascots['atl']	= 'Braves';
	mascots['phi']	= 'Phillies';
	mascots['fla']	= 'Marlins';
	mascots['was']	= 'Nationals';
	mascots['ari']	= 'Diamondbacks';
	mascots['sd']	= 'Padres';
	mascots['la']	= 'Dodgers';
	mascots['col']	= 'Rockies';
	mascots['sf']	= 'Giants';

	// Get the object to contain the standings content.
	var standingsBody	= document.getElementById('standings_body');

	// Get the object to contain the standings head.
	var standingsHead	= document.getElementById('standings_head');

	// Get the variable that contains the current standings and the head.
	var standings_rs	= '';
	var standings_head	= '';
	if (division == null || division == 'undefined') {
		division	= 'nlc';
	}
	switch (division) {
		// American League East.
		case 'ale':
			standings_rs	= eval('standings_rs_' + division);
			standings_head	= '<acronym title="American League">AL</acronym> East Standings';
		break;

		// American League Central.
		case 'alc':
			standings_rs	= eval('standings_rs_' + division);
			standings_head	= '<acronym title="American League">AL</acronym> Cetral Standings';
		break;

		// American League West.
		case 'alw':
			standings_rs	= eval('standings_rs_' + division);
			standings_head	= '<acronym title="American League">AL</acronym> West Standings';
		break;

		// National League East.
		case 'nle':
			standings_rs	= eval('standings_rs_' + division);
			standings_head	= '<acronym title="National League">NL</acronym> East Standings';
		break;

		// National League West.
		case 'nlw':
			standings_rs	= eval('standings_rs_' + division);
			standings_head	= '<acronym title="National League">NL</acronym> West Standings';
		break;

		// National League Central.
		case 'nlc':
		default:
			standings_rs	= eval('standings_rs_' + division);
			standings_head	= '<acronym title="National League">NL</acronym> Central Standings';
		break;

	}

	// Build the links.
	var standings	= '<div class="center">';
	if (division == 'alw') {
		standings	+= '<strong><acronym title="American League West">ALW</acronym></strong>\n';
	} else {
		standings	+= '<a href="javascript:standings(\'alw\');"><acronym title="American League West">ALW</acronym></a>\n';
	}
	if (division == 'alc') {
		standings	+= '<strong><acronym title="American League Central">ALC</acronym></strong>\n';
	} else {
		standings	+= '<a href="javascript:standings(\'alc\');"><acronym title="American League Central">ALC</acronym></a>\n';
	}
	if (division == 'ale') {
		standings	+= '<strong><acronym title="American League East">ALE</acronym></strong>\n';
	} else {
		standings	+= '<a href="javascript:standings(\'ale\');"><acronym title="American League East">ALE</acronym></a>\n';
	}
	if (division == 'nlw') {
		standings	+= '<strong><acronym title="National League West">NLW</acronym></strong>\n';
	} else {
		standings	+= '<a href="javascript:standings(\'nlw\');"><acronym title="National League West">NLW</acronym></a>\n';
	}
	if (division == 'nlc') {
		standings	+= '<strong><acronym title="National League Central">NLC</acronym></strong>\n';
	} else {
		standings	+= '<a href="javascript:standings(\'nlc\');"><acronym title="National League Central">NLC</acronym></a>\n';
	}
	if (division == 'nle') {
		standings	+= '<strong><acronym title="National League East">NLE</acronym></strong>\n';
	} else {
		standings	+= '<a href="javascript:standings(\'nle\');"><acronym title="National League East">NLE</acronym></a><br />\n';
	}
	standings	+= '</div>';

	// Start the standings table.
	standings		+= '<table id="standings_table" class="ruler"><thead><tr><th>Team</th><th><acronym title="Wins">W</acronym></th><th><acronym title="Losses">L</acronym></th><th><acronym title="Winning Percentage">Pct.</acronym></th><th><acronym title="Games Back">GB</acronym></th></tr></thead><tbody>';

	// Iterate through each of the teams, displaying their data.
	for (i = 0; i < standings_rs.length; i++) {
		// Bold the Reds.
		if (standings_rs[i].league_sensitive_team_name == 'Cincinnati') {
			standings_rs[i].league_sensitive_team_name	= '<strong>' + standings_rs[i].league_sensitive_team_name + '</strong>';
		}

		// Check URL for last game wrap.
		if (standings_rs[i].wrap != null) {
			var url	= '<a href="http://www.mlb.com' + standings_rs[i].wrap + '" title="Last game: ' + standings_rs[i].lastg + '">' + standings_rs[i].league_sensitive_team_name + '</a>';
		} else {
			var url	= '<span title="Last game: ' + standings_rs[i].lastg + '">' + standings_rs[i].league_sensitive_team_name + '</span>';
		}
		standings	+= '<tr>';
		standings	+= '<td>' + url + '</td>';
		standings	+= '<td>' + standings_rs[i].w + '</td>';
		standings	+= '<td>' + standings_rs[i].l + '</td>';
		standings	+= '<td>' + standings_rs[i].pct + '</td>';
		standings	+= '<td>' + standings_rs[i].gb + '</td>';
		standings	+= '</tr>';
	}

	// Close the table.
	standings	+= '</tbody></table>';

	// Include a link to full standings.
	standings	+= '<a class="bold" href="http://mlb.mlb.com/mlb/standings/index.jsp">Expanded Standings</a>';

	// Set the standings object to the standings table.
	standingsBody.innerHTML	= standings;
	standingsHead.innerHTML	= standings_head;
	tableruler();
}

