var ajax_boxscore_poller = (function(){
 	var _self = {
		game_id : "",
		boxscore_url : "",
		siteCode: "",
		get_game_id : function() {
			var querystring = window.location.search.substring(1); 
  			var kv_pairs = querystring.split("&"); 
  			for (var i=0;i<kv_pairs.length;i++) { 
    			var kv = kv_pairs[i].split("="); 
    			if (kv[0] == "gid") { 
      				_self.game_id = kv[1]; 
    			} 
				if ((kv[0] == "sid") || (kv[0] == "did")) {
					if (kv[1]) {
						_self.siteCode = kv[1];
					} else {
						_self.siteCode = "milb";
					}
				}
  			} 
		},
		get_boxscore_url : function() {
			var league = _self.game_id.substring(14,17);
			var year = _self.game_id.substring(0,4);
			var month = _self.game_id.substring(5,7);
			var day = _self.game_id.substring(8,10);
			var gid = _self.game_id;
			_self.boxscore_url = "/gdcross/components/game/"+league+"/year_"+year+"/month_"+month+"/day_"+day+"/gid_"+gid+"/boxscore.xml";
		},
 
 		update_boxscore : function() {
			$.sajax
  			.text('/shared/components/linescore/milb_boxscore.tpl')
  			.xml(_self.boxscore_url, function (data, status, tpl) {
				var html = "";
				$('#boxscore').empty();
				if ($(data).find("boxscore")) {
					$(data).find("boxscore").each(function() {
						var b = $(this);
						html = $.template(tpl,b,true);
					});
				} else {
					$("#boxscore").html("There is no data currently available for this game.");
				}	
    			$('#boxscore').append(html);
  			});
		}
 	}; //end self
  	return _self;
})();

$(document).ready(function() {
	ajax_boxscore_poller.get_game_id();
	ajax_boxscore_poller.get_boxscore_url();
	
	var gameDataPoller = new bam.util.PeriodicalExecuter(ajax_boxscore_poller.update_boxscore,15000,false);
	ajax_boxscore_poller.update_boxscore();
});










































