/*****************************

SI.com Scoreboard Object
------------------------
* built assuming that:
	- may be used on any page
	- a config file holds game urls for each league
	- json data returned follows a particular structure
		
* Table of Contents

1. Utility functions
	A. ajax object
2. Scoreboard Object
	A. Initialize Properties
	B. Define Methods
		- get24hour(time)	>>> passes in time as "10:10 PM ET" and returns 2010 (as int)
		- sortGamesByTime	>>> array sorting function that sorts games by time
		- retrieveGames		>>> the start of the process to display games on the scoreboard
		- displayGames		>>> writes the data into html elements
		- getmySIteams		>>> reads the mySIcom cookie to set MySI games
		- changeTab			>>> changes tabs and content that goes with tab
		- flipSportPage		>>> for tabs where the content has multiple 'pages', this changes from page to page
	C. Trigger MySI games
3. Initialize Scoreboard Object (called from separate js file)

*******************************/

/*************
1. UTILS
*************/

/*******	A. ajax object	*******/
function ajaxer(url, callbackFunction) {
	var that=this;      
	this.updating = false;
	this.abort = function() {
		if (that.updating) {
			that.updating=false;
			that.AJAX.abort();
			that.AJAX=null;
		}
	}
	this.update = function(passData,postMethod) { 
		if (that.updating) { return false; }
		that.AJAX = null;                          
		if (window.XMLHttpRequest) {              
			that.AJAX=new XMLHttpRequest();              
		} else {                                  
			that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (that.AJAX==null) {                             
			return false;                               
		} else {
			that.AJAX.onreadystatechange = function() {  
			if (that.AJAX.readyState==4) {             
				that.updating=false;                
				that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
				that.AJAX=null;                                         
			}                                                      
		}
		that.updating = new Date();                              
		if (/post/i.test(postMethod)) {
			var uri=urlCall+'?'+that.updating.getTime();
			that.AJAX.open("POST", uri, true);
			that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			that.AJAX.setRequestHeader("Content-Length", passData.length);
			that.AJAX.send(passData);
		} else {
			var uri=urlCall;
			var ifModifiedSince = new Date(0);
			that.AJAX.open("GET", uri, true); 
			if(navigator.appName == "Microsoft Internet Explorer"){ /* if IE, then set the header to see if the file has been modified since some time in the past */
				that.AJAX.setRequestHeader("If-Modified-Since", ifModifiedSince);
			}
			that.AJAX.send(null);                                         
		}              
			return true;                                             
		}                                                                           
	}
	var urlCall = url;        
	this.callback = callbackFunction || function () { };
}
/*******	[END] A. ajax object	*******/

/*************
[END] 1. UTILS
*************/


/*************
2. Scoreboard Object
*************/

var _csbi = null;								/*current scoreboard instance (globally set to be accessed from anywhere on page)*/

function Scoreboard(tab,content,confURI){
	var _flipInterval = 12000;
	var current_page = 0;
	_csbi = this;							/*set the current scoreboard instance*/
	
	/*******	A. Initialize Properties	*******/
	this._configURL = (typeof(confURI) == "string") ? confURI : "/.element/games/json/main_config.json";
	this.current_year = '2010';
	this._configJSON = {};
	this.t = tab;
	this.c = content;
	this.current_tab = "";
	this.activeTabs = new Array();
	this.mysi = {
		active:false,
		teams:{
			NFL:[],
			NBA:[],
			NHL:[],
			MLB:[],
			NCAAF:[],
			NCAAB:[]
		}
	};
		
	var completeScoreboardImgSrc = "http://i.cdn.turner.com/si/.element/img/4.1/sect/global/complete_scoreboard_102x12.gif";
	var mysiImgSrc = "http://i.cdn.turner.com/si/.element/img/4.1/sect/global/edit_teams_51x12.gif";
	var showGolf = false;
	this.golfXMLurl = "http://www.golf.com/golf/static/xml/leaderboard/current_r/leaderboard_top10.xml";
	this.golfXML = "";
	
	this.tabs = {
		MYSI:{type:"MYSI",games:[],game_order:{},tabname:'MySI GAMES',img:{src:mysiImgSrc,alt:'Edit MySI Teams',link:'/mysi/personalization/'}},
		GOLF:{type:"GOLF",games:[],game_order:{},tabname:'GOLF',img:{src:completeScoreboardImgSrc,alt:'Complete Leaderboard',link:'http://www.golf.com/golf/tours_news/leaderboard/'}},
		NFL:{type:"NFL",games:[],game_order:{},tabname:'NFL',img:{src:completeScoreboardImgSrc,alt:'Complete NFL Scoreboard',link:'/football/nfl/scoreboards/today/'}},
		NBA:{type:"NBA",games:[],game_order:{},tabname:'NBA',img:{src:completeScoreboardImgSrc,alt:'Complete NBA Scoreboard',link:'/basketball/nba/scoreboards/today/'}},
		MLB:{type:"MLB",games:[],game_order:{},tabname:'MLB',img:{src:completeScoreboardImgSrc,alt:'Complete MLB Scoreboard',link:'/baseball/mlb/scoreboards/today/'}},
		NHL:{type:"NHL",games:[],game_order:{},tabname:'NHL',img:{src:completeScoreboardImgSrc,alt:'Complete NHL Scoreboard',link:'/hockey/nhl/scoreboards/today/'}},
		NCAAF:{type:"NCAAF",games:[],game_order:{},tabname:'NCAAf',img:{src:completeScoreboardImgSrc,alt:'Top 25 College Football Scoreboard',link:'/football/ncaa/scoreboards/top25/today/'}},
		NCAAB:{type:"NCAAB",games:[],game_order:{},tabname:'NCAAB',img:{src:completeScoreboardImgSrc,alt:'Top 25 College Basketball Scoreboard',link:'/basketball/ncaa/men/scoreboards/top25/today/'}}
	};
	/*******	[END] A. Initialize Properties	*******/
	
	/*******	B. Define Methods	*******/
	this.getXMLdoc = function(text){
		var xmlDoc;
		try {
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(text);
		 }
		catch(e)
		  {
			try{
				parser=new DOMParser();
				xmlDoc=parser.parseFromString(text,"text/xml");
			}
			catch(e) {
				return false;
			}
		  }
		return xmlDoc;
	};
	
	this.get24hour = function(time){
		var hm = time.split(":");						
		var h = (parseInt(hm[0])+12).toString();		
		var m = parseFloat(hm[1]);									/*using parseFloat, parseInt bug renders '08' and '09' as 0*/
		m = (m < 10) ? "0"+m.toString() : m.toString();
		var _24hr = h+m;
		return parseInt(_24hr);
	};
	
	this.sortGamesByTime = function(a,b){
		return _csbi.get24hour(a.time)-_csbi.get24hour(b.time);	
	};
	
	this.sortGamesByStatus = function(a,b){
		return a.statusID-b.statusID;	
	};
	
	this.sortGamesByOrder = function(a,b){
		if(a.order && b.order){	return a.order-b.order;			} 
		else {	return;		}
	};
	
	this.retrieveGames = function(){
		var o = _csbi;
		var game_url = game_data = game_pos = game_url_array = game_file_name = game_id = games = "";
		var sports = o._configJSON.scoreboard.sports.sport;
						
		/*loop through each sport available in main_config*/
		for(var i=0;i<sports.length;i++){
			
			var 	taborder = parseInt(sports[i].position)-1;
			games  = sports[i].game;
			o.tabs[sports[i].type].tabname = sports[i].tabname;
			o.tabs[sports[i].type].active = true;
			o.tabs[sports[i].type].img.link = sports[i].clickthru;
			
						
			o.activeTabs.splice(taborder,0,o.tabs[sports[i].type]);
			if(sports[i].type == "GOLF") showGolf = true;
			/*loop through each game per sport*/
			for(var g=0;g<games.length; g++){
				
				game_url = games[g].url;
				game_pos = games[g].position;
				
				game_url_array = game_url.split('/');	//divy up the url by '/'
				game_file_name = game_url_array[game_url_array.length-1]; //grab the file name
				game_id = game_file_name.split('.')[0]; //drop off the filename's extension, leaving the contest id		
				//console.log(o.tabs[sports[i].type]);
				o.tabs[sports[i].type].game_order[game_id] = parseInt(game_pos);
				game_data = new ajaxer(game_url);
				game_data.update();
				game_data.callback = function(text, status, xml){
					if(status == 200){
						var game_json 	= eval('('+text+')');
						var game_league	= game_json.sport.type;
						var the_game		= game_json.sport.game;
						var visitor		= the_game.visitor.full_name;
						var home			= the_game.home.full_name;
						var v			= the_game.visitor.short_name;
						var h			= the_game.home.short_name;
						
						/*add game to respective league tab*/
						o.tabs[game_league].games.push(the_game);
						
						/*if either team is on the mysi list, then add to mysi tab game array*/
						if(o.mysi.active){
							for(var m=0;m<o.mysi.teams[game_league].length;m++){
								var mysiTeam = o.mysi.teams[game_league][m];
								
								if( v == mysiTeam || visitor.indexOf(mysiTeam) >-1  || h == mysiTeam || home.indexOf(mysiTeam)>-1)
								{
									o.tabs["MYSI"].games.push(the_game);
								}

							}
						}
					} 
				};

			}
		}
				
		/*display games*/
		setTimeout("_csbi.displayGames(_csbi.t,_csbi.c)",2000);
		if(showGolf){
			setTimeout("_csbi.retrieveGolfData(_csbi.golfXMLurl)",1000);
		}
	};
	
	this.retrieveGolfData = function (url) {
		var contentType = "application/x-www-form-urlencoded";

		var xhr = new FlashXMLHttpRequest();
		xhr.onload = function() { 
			_csbi.golfXML = _csbi.getXMLdoc(xhr.responseText);	
			setTimeout("_csbi.displayGolfLB()",1000);
		};
		xhr.open("GET", url);
		xhr.setRequestHeader("Content-Type", contentType);
		xhr.send("");
	};
	this.displayGames = function(t,c){
		/*
		if(this.activeTabs.length == 0){
			$(c).innerHTML = "<div id=\"cnnGameHolder\"><h1 style=\"font-family:Verdana;font-size:11px;\">No Games Scheduled Today</h1></div>";
			return false;
		} 
		*/
		var Tabs = Content = "";
		
		if( this.tabs["MYSI"].games.length > 0 ){ /* if mysi is active */
			if(this.tabs["MYSI"].first){
				this.activeTabs.splice(0,0,this.tabs["MYSI"]); 	/* if user elects, put mysi first */
			} else {
				this.activeTabs.push(this.tabs["MYSI"]);		/* otherwise put mysi last */
			}
		}
		
		this.current_tab = this.activeTabs[0].type;	
		
		/*render tabs and content*/
		Tabs = "<div class=\"cnnRight\"><a href=\"http://sportsillustrated.cnn.com/scoreboards/\" target=\"_top\">More Scores</a></div>";
		Tabs += "<ul>";
		
		for(var current_tab=0;current_tab < this.activeTabs.length; current_tab++){
			var curr = this.activeTabs[current_tab];
			var site = "http://sportsillustrated.cnn.com";
			/*tab image links*/
			var tis 	= curr.img.src;
			var tia 	= curr.img.alt;
			var til 	= (curr.img.link.indexOf("http://") > -1) ? curr.img.link : site+curr.img.link;
			/*organize games per tab before displaying*/
			var gpp = (curr.type == "MYSI" || curr.type == "NCAAF" ||  curr.type == "NCAAB" ) ? 5 : 8; 
			var games = curr.games;
			var game_order  = this.tabs[curr.type].game_order;					/*game order based on scoreboard tool*/
						
			for(var y=0;y<games.length;y++){														
				games[y].statusID = (games[y].status == "F") ? 1 : 0;				/*if game is FINAL statusID = 1, else 0 */
				games[y].order = game_order[games[y].id];
				
				var p = y-1;
				if(p >= 0 && (games[p].id ==games[y].id)){							
					games.splice(y,1);											/*remove duplicate games, if any*/
				}
			}
			
			games.sort(this.sortGamesByTime); 									/*sort the games by time*/
			if(curr.type != "MYSI" && curr.type != "GOLF"){
				games.sort(this.sortGamesByStatus);									/*sort the games by status id*/
				games.sort(this.sortGamesByOrder);									/*sort the games by status id*/
			}
			/*END:organize games per tab before displaying*/
			
			var nog = games.length;												/*# of games in current tab*/
			var nop = Math.ceil(nog/gpp);											/*# of pages in current tab*/
			this.tabs[curr.type].pages = nop;
			
				/*render each tab*/
				Tabs += ( current_tab == 0 ) ? "<li class=\"cnnAlt\" id=\""+curr.type+"tab\">" : "<li id=\""+curr.type+"tab\">" ;
				Tabs += "<a href=\"javascript:_csbi.changeTab('"+curr.type+"');\">";
				Tabs += curr.tabname;
				Tabs += "<img id=\""+curr.type+"link\" onclick=\"javascript:window.parent.location.href='"+til+"'\" src=\""+tis+"\" alt=\""+tia+"\" title=\""+tia+"\"";
				Tabs += ( current_tab == 0 ) ? "/></a>" : "style=\"display:none;\"/></a>" ;
				Tabs += "</a>";
				Tabs += "</li>";
				/*END: render each tab*/
			
				for (var k=0;k<nop;k++){					/*render container per page for current tab*/
					var prevPage = k;
					var currPage = k+1;
					var lastOnPage = currPage*gpp;
					var firstOnPage = prevPage*gpp+1;	
					var lastPage = nop-1;
					var pageId = "cnnGameHolder"+curr.type;
					var firstPageId = pageId+"0";
					var currPageId = pageId+k;
					var prevPageId = pageId+parseInt(k-1);
					var nextPageId = pageId+currPage;
					var lastPageId = pageId+lastPage;
					
					
					Content += "<div id=\"cnnGameHolder"+curr.type+k+"\"";
					Content +=  ( current_tab == 0 && k==0 ) ? ">" : "style=\"display:none\">";
					Content += "<ul id=\"cnnGameScores"+curr.type+"\">";
					
					/*render first li*/
					Content += "<li class=\"cnnFirst\">";
					if(nop > 1 && k==0){ 		/*if first page in series, link to go to last page*/
						Content += "<a href=\"javascript:_csbi.flipSportPage('"+currPageId+"','"+lastPageId+"','"+lastPage+"')\"></a>";
					} else if(nop > 1){		/*otherwise go to previous page*/
						Content += "<a href=\"javascript:_csbi.flipSportPage('"+currPageId+"','"+prevPageId+"','"+prevPage+"')\"></a>";
					}
					Content += "</li>";
					/*END: render first li*/
					
					for(var j=0;j < lastOnPage;j++){								/*render each game*/
											
						var currGame = j+1;
						
						if((currGame >= firstOnPage) && (currGame <= lastOnPage) && games[j] != null){
							var league 	= games[j].sport;
							var date 	= games[j].date;
							var id 		= games[j].id;
							var state	= games[j].state;
							var status	= games[j].status;
							var home		= games[j].home;
							var visitor	= games[j].visitor;
							var time		= games[j].time;
							var url		= games[j].url;
							var clock	= games[j].clock;
							
							// Start with machine date
							var datevalue = new Date();
							var themonth = datevalue.getMonth()+1;
							var monthvalue = (themonth < 10) ? "0" + themonth : themonth;
							var theday = datevalue.getDate();
							var dayvalue = (dayvalue < 10) ? "0" + theday : theday;
							
							// Process date from "Monthname DD" to "MM/DD"
							if (date.indexOf(', ')>0) { date = date.split(', ')[1]; }
							if (date.indexOf(' ')>0) {
								switch (date.split(' ')[0].substr(0,3).toLowerCase()) {
									case 'jan': monthvalue = '01'; break;
									case 'feb': monthvalue = '02'; break;
									case 'mar': monthvalue = '03'; break;
									case 'apr': monthvalue = '04'; break;
									case 'may': monthvalue = '05'; break;
									case 'jun': monthvalue = '06'; break;
									case 'jul': monthvalue = '07'; break;
									case 'aug': monthvalue = '08'; break;
									case 'sep': monthvalue = '09'; break;
									case 'oct': monthvalue = '10'; break;
									case 'nov': monthvalue = '11'; break;
									case 'dec': monthvalue = '12'; break;
								}
								dayvalue = date.split(' ')[1];
								if (dayvalue.length == 1) { dayvalue = "0"+dayvalue; }
							}

							var base = ''; 
							// NFL
							if(league == "NFL") {
								base = "/football/nfl/gameflash/" + this.current_year + "/"+monthvalue+"/"+dayvalue+"/";
								url = "/football/nfl/gameflash/today/";
								// status
								if (status == "F" && state == "IP"){
									url = base + id + "_recap.html";
								} else if(state == "IP") {
									url = base + id + "_boxscore.html";
								} else if (state=="PRE"){
									url = base + id + "_preview.html";
								}
							} else if(league == "NCAAF") {
								base = "/football/ncaa/gameflash/" + this.current_year + "/"+monthvalue+"/"+dayvalue+"/";
								url = "/football/ncaa/gameflash/today/";
								// status
								if (status == "F" && state == "IP"){
									url = base + id + "_recap.html";
								} else if(state == "IP") {
									url = base + id + "_boxscore.html";
								} else if (state=="PRE"){
									url = base + id + "_preview.html";
								}
							} else if(league == "NCAAB") {
								base = "/basketball/ncaa/men/viewcast/" + this.current_year + "/"+monthvalue+"/"+dayvalue+"/";
								url = "/football/ncaa/teams/divia.html";
								// status
								if (status == "F" && state == "IP"){
									url = base + id + "_viewcast_recap.html";
								} else if(state == "IP") {
									url = base + id + "_viewcast_boxscore.html";
								} else if (state=="PRE"){
									url = base + id + "_viewcast_preview_story.html";
								}
							} else if (league == "NHL") {
								base = "/hockey/nhl/viewcast/" + this.current_year + "/"+monthvalue+"/"+dayvalue+"/";
								url = "/hockey/nhl/scoreboards/today/";
								if (status == "F" && state == "IP"){
									url = base + id + "_viewcast_recap.html";
								} else if(state == "IP") {
									url = base + id + "_viewcast.html";
								} else if (state=="PRE"){
									url = base + id + "_viewcast_preview_story.html";
								}
							} else if (league == "NBA") {
								base = "/basketball/nba/gameflash/" + this.current_year + "/"+monthvalue+"/"+dayvalue+"/";
								url = "/basketball/nba/scoreboards/today/";
								if (status == "F" && state == "IP"){
									url = base + id + "_recap.html";
								} else if(state == "IP") {
									url = base + id + "_boxscore.html";
								} else if (state=="PRE"){
									url = base + id + "_preview.html";
								}
							}
							
							Content += "<li class=\"cnnGameScores"+league+"\">";
							Content += "<a href=\"http://sportsillustrated.cnn.com"+url+"\" target=\"_top\">";
							Content += "<div>";
							
							var setMYSIclass = false;
							var mysiteams = this.mysi.teams[league];
							
							/********	
							SHOW TEAMS
							conditions:
								- if team is a mysi team, then add class name "cnnAlt" to span
								- if tab must show 5 games per page, use short name, otherwise if 8 games per page, use abbreviation
							********/
							
							/*visitor*/
							Content += "<strong>";
							Content += "<strong>"+visitor.score+"</strong>";
							
							if(visitor.rank != null) {
								Content += "<em>"+visitor.rank+"&nbsp;</em>";
							} else if (curr.type == "NCAAF" || curr.type == "NCAAB") {
								Content += "<em>&nbsp;</em>";
							}
							
							// GK - new variable in case short name doesn't come up
							var visitor_name;
							if (visitor.short_name) { visitor_name = visitor.short_name; }
							else if (visitor.city_name) { visitor_name = visitor.city_name.substr(0,12); }
				
							if(this.mysi.active){ 
								for(var l=0;l < mysiteams.length;l++){
									if(mysiteams[l] == visitor.short_name || visitor.full_name.indexOf(mysiteams[l])>-1){
										setMYSIclass = true;
										break;
									} 
								}
								if(setMYSIclass){
									Content += ( gpp==5 ) ? "<span class=\"cnnAlt\">"+visitor_name+"</span>" : "<span class=\"cnnAlt\">"+visitor.three_letter_abrv+"</span>";
								} else {
									Content += (gpp == 8 || (curr.type != "MYSI" && gpp != 5) ) ? "<span>"+visitor.three_letter_abrv+"</span>" : "<span>"+visitor_name+"</span>";
								}
							} else {
								Content += (gpp == 8) ? "<span>"+visitor.three_letter_abrv+"</span>" : "<span>"+visitor_name+"</span>";
							}
							Content += "</strong>";
							
							setMYSIclass = false;
							
							/*home*/
							Content += "<strong>";
							Content += "<strong>"+home.score+"</strong>";
							
							if(home.rank != null) {
								Content += "<em>"+home.rank+"&nbsp;</em>";
							} else if (curr.type == "NCAAF" || curr.type == "NCAAB") {
								Content += "<em>&nbsp;</em>";
							}
							
							var home_name;
							if (home.short_name) { home_name = home.short_name; }
							else if (home.city_name) { home_name = home.city_name.substr(0,12); }

							if(this.mysi.active){ 
								for(var l=0;l < mysiteams.length;l++){
									if(mysiteams[l] == home.short_name || home.full_name.indexOf(mysiteams[l])>-1){
										setMYSIclass = true;
										break;
									} 
								}
								if(setMYSIclass){
									Content += ( gpp==5 ) ? "<span class=\"cnnAlt\">"+home_name+"</span>" : "<span class=\"cnnAlt\">"+home.three_letter_abrv+"</span>";
								} else {
									Content += (gpp == 8 || (curr.type != "MYSI" && gpp != 5)) ? "<span>"+home.three_letter_abrv+"</span>" : "<span>"+home_name+"</span>";
								}
							} else {
								Content += (gpp == 8) ? "<span>"+home.three_letter_abrv+"</span>" : "<span>"+home_name+"</span>";
							}
							Content += "</strong>";
							
							/********	
							[END] SHOW TEAMS
							********/
							
							/*status*/
							if (state == "PRE"){								/*if game not started, show time it starts*/
								Content += "<div>"+time+"</div>";
							} else if (state == "IP" && status == "F"){			/*if game is over, say FINAL*/
								Content += "<div>FINAL</div>";
							} else if (state == "IP" && league == "MLB"){		/*if game is in progress and MLB, say "Bot 5th"*/
								Content += "<div>"+this.nthNumber(status)+"</div>";			
							} else if (state == "IP" && league != "MLB"){		/*if game is in progress and not MLB, say "3rd | 2:01"*/
								Content += "<div>"+this.nthNumber(status)+"<span>|</span>"+clock+"</div>";
							} 
							
							Content += "</div>";
							Content += "</a>";
							Content += "</li>";
						}
						
						/*if the page isn't full, then add in place holders*/
						else if((currGame > firstOnPage) && (gpp - currGame) <= lastOnPage ){  
							Content += "<li class=\"cnnEmptyGame\"> </li>";
						}
					}
					/*END: render each game*/
					
				/*render last li	*/
				Content += "<li class=\"cnnLast\">"
				if(nop > 1 && k==lastPage){				/*if last page in series, link to go to first page*/
					Content += "<a href=\"javascript:_csbi.flipSportPage('"+currPageId+"','"+firstPageId+"','0')\"></a>";
				} else if(nop > 1){						/*otherwise, link to go to next page*/
					Content += "<a href=\"javascript:_csbi.flipSportPage('"+currPageId+"','"+nextPageId+"','"+currPage+"')\"></a>";
				}
				Content += "</li>";
				/*END: render last li*/
				
				Content += "</ul>";
				Content += "</div>";
				/*END: render container per page for each tab		*/
				
				}
			
			/*END: render games*/
			
		}
		Tabs += "</ul>";
		/*END: render tabs and content*/
		
		/*innerHTML assignments*/
		document.getElementById(t).innerHTML = Tabs;
		document.getElementById(c).innerHTML = Content;
		
		
		if(this.tabs[this.current_tab].pages > 1){
			this.autochangepage = setInterval("_csbi.autopage()",_flipInterval);
		}
	};
	
	this.displayGolfLB = function(){
		if( typeof(_csbi.golfXML.childNodes) == "undefined"){
			if(document.getElementById("GOLFtab")) document.getElementById("GOLFtab").style.display = "nones";
			return false;
		}
		var tabLink =  this.tabs["GOLF"].img.link;
		var Content;
				
		Content = (this.current_tab != "GOLF") ? "<div id=\"cnnGameHolderGOLF0\" style=\"display:none;\">\n" : "<div id=\"cnnGameHolderGOLF0\">\n" ;
			Content += "<ul id=\"cnnGameScoresGolf\">\n";
				Content += "<li class=\"cnnFirst\"> </li>\n";
				Content += "<li class=\"cnnGameScoresGolf\">\n";
					Content +="<a href=\""+tabLink+"\">\n";
						Content += "<div>\n";
						var root = (this.golfXML.childNodes.length == 2) ? 1 : 0;
						for(var i=0;i<9;i++){
							var playerNode = this.golfXML.childNodes[root].childNodes[1].childNodes[i];
							var fn = playerNode.getAttribute("Fname");
							var ln = playerNode.getAttribute("Lname");
							var rank = (playerNode.getAttribute("CurPos")) ? playerNode.getAttribute("CurPos") : '-';
							var score = (playerNode.getAttribute("TournParRel")) ? playerNode.getAttribute("TournParRel"): '-';
							var thru = (playerNode.getAttribute("Thru")) ? playerNode.getAttribute("Thru") : '-';
							var name = fn+" "+ln.replace(' (a)','');
							Content += "<div class=\"cnnItem"+i+"\">";
								Content += "<strong>"+thru+"</strong>";
								Content += "<div>"+score+"</div>";
								Content += "<em>"+rank+"</em>";
								Content += "<span>"+name+"</span>";
							Content += "</div>\n";
						}
						Content += "</div>\n";
					Content +="</a>\n";
				Content += "</li>\n";
				Content += "<li class=\"cnnLast\"> </li>\n";
		Content += "</div>";
		
		document.getElementById(_csbi.c).innerHTML += Content;
	
	};
	this.getmySIteams = function(){
		var mySIcookie = readCookie( 'mySIcom' );
		var mySIhide = ( readCookie( 'mySIcomScores' ) != null ) ? true : false;
		var value, team, league;

		if ( mySIcookie ){
			this.mysi.active = this.tabs["MYSI"].active = true;
			this.tabs["MYSI"].first = ( mySIhide ) ? false : true;
			
			for(var i=0; i<mySIcookie.length-1;i++){
				value = mySIcookie[i].split('_');
				team = value[0];
				league  = (value[1].indexOf('NCAA') > -1) ? value[1].substring(0,5) : value[1]; /*restricts the league value to either NCAAB or NCAAF*/
				this.mysi.teams[league].push(team);
			}
		} else {
		return false;
		}
	};
	
	this.changeTab = function(new_tab){
		
		if( typeof(this.autochangepage) != "undefined") clearInterval(this.autochangepage);	/* clear the interval */
		
		var pagesInTab = this.tabs[new_tab].pages;
		var oldTabId = this.current_tab+"tab";
		var newTabId = new_tab+"tab";
		
		var oldLinkId = this.current_tab+"link";
		var newLinkId = new_tab+"link";
		
		var contentPrefix = "cnnGameHolder";
		var newContentId = contentPrefix+new_tab+"0";
		
		var content = document.getElementById("cnnGameScoresContent").getElementsByTagName('div');
		for(var i=0;i<content.length;i++){
			if(content[i].id.indexOf("cnnGameHolder") > -1 ) content[i].style.display = "none";
		}
		document.getElementById(newContentId).style.display = '';
	
		document.getElementById(oldTabId).className = "";
		document.getElementById(oldLinkId).style.display = "none";
		
		document.getElementById(newTabId).className = "cnnAlt";
		document.getElementById(newLinkId).style.display = "";
		
		/*set this.current_tab to new_tab*/
		this.current_tab = new_tab;

		if(pagesInTab > 1){ /* if the tab has more than one page */
			current_page = 0;
			this.autochangepage = setInterval("_csbi.autopage()",_flipInterval);
		}	
	};
	
	this.autopage = function() {
		var pre = "cnnGameHolder"+this.current_tab;	
		var pgs = this.tabs[this.current_tab].pages - 1;
		var cp =  current_page;
		var next = (cp < pgs) ? cp+1 : 0;
		var off = pre+cp;
		var on = pre+next;
		_csbi.flipSportPage(off,on,'auto');
		current_page = next;
	}
	
	this.flipSportPage = function(off,on,type){	
		if(type != "auto" && typeof(this.autochangepage) != "undefined"){
			clearInterval(this.autochangepage);		/* clear the interval */
		}
		document.getElementById(off).style.display = "none";
		document.getElementById(on).style.display = "";
	};
	
	this.nthNumber = function(num){
		if (isNaN(num)) return num;
		num = num * 1;
		var low = num % 10;
		switch (low) {
			case 0: case 4: case 5: case 6: case 7: case 8: case 9: return num+'th';
			case 1: return num+'st';
			case 2: return num+'nd';
			case 3: return num+'rd';
		}
	}
	
	/*******	[END] B. Define Methods	*******/
	
	/*******	C. Pull Trigger to Set MySI Games/Teams	*******/
	this.getmySIteams();
	/*******	[END] C. Pull Trigger to Set MySI Games/Teams	*******/
};

/*************
[END] 2. Scoreboard Object
*************/
