var scoreboard_req;
var score_timeout;

var pauseflag = 0;

// These point to the content viewers
var oScoreboard;
var ScoreIFrame;

scoreboard_state_change =
function ()
{
	if (oScoreboard && ScoreIFrame)
	{
		oScoreboard.innerHTML = ScoreIFrame.document.body.innerHTML;
		handle_score_load();
		alert(ScoreIFrame);
	}
}

// Custom Event Handlers for Drop downs
load_scoreboard =
function (spid)
{
	if (spid)
	{
		var url_prefix = window.location.protocol + "//" + window.location.hostname;
		var url = url_prefix + "/share/scoreboard.dbml?DB_OEM_ID=10100&SPID="+spid;
		ScoreIFrame.src = url;
	}
}


dropdown_load =
function ()
{
	oScoreboard = document.getElementById("scoreboard_content");
	ScoreIFrame = document.getElementById("scoreboard_iframe");

}

function handle_score_load ()
{
	oScoreList = document.getElementById("score_list");
	if(oScoreList)
	{
		oScoresArray = oScoreList.getElementsByTagName("LI");
		if(oScoresArray.length > 0)
		{
			// Display the first result
			oScoresArray[0].style.display = "block";
			scroller_interval = 5000;
			current_score = 0;

			clearTimeout(score_timeout);

			if (oScoresArray.length > 1) 
			{
				score_timeout = setTimeout(change_score, scroller_interval);
			}
		}
	}
	else {
		oScoresArray = null;
	}
}

function change_score()
{
	//Hide current score
	if (oScoresArray && oScoresArray.length > 0)
	{
		oScoresArray[current_score].style.display = "none";
		var next_score = current_score + 1;
		if (next_score >= oScoresArray.length) {
			next_score = 0;
		}
		oScoresArray[next_score].style.display = "block";
		current_score = next_score;
		score_timeout = setTimeout(change_score, scroller_interval);
	}
}


function goback_score()
{
	//Hide current score
	if (oScoresArray && oScoresArray.length > 0)
	{
		oScoresArray[current_score].style.display = "none";
		var prev_score = current_score - 1;
		if (prev_score <= oScoresArray.length) {
			prev_score = 0;
		}
		oScoresArray[prev_score].style.display = "block";
		current_score = prev_score;
		score_timeout = setTimeout(change_score, scroller_interval);
	}
}

function pause_score()
{
	switch(pauseflag){
		case 0:
			clearTimeout(score_timeout);
			pauseflag = 1;
			document.pausebutton.src="/fls/10100/site_graphics/play.jpg";
			break;
		case 1:
			pauseflag = 0;
			document.pausebutton.src="/fls/10100/site_graphics/pause.jpg";
			score_timeout = setTimeout(change_score, 5000);
			break;
	}
		
}
