var floatOpacity = 0;
var floatOpacityDirection = 0.005;
var intDefault = 4;
var arrayCoverOpacity = new Array(11);
var arrayCoverOpacityDirection = new Array(11);
var currentTime;

var gFadeIn;
var gFade;
var gFlashPoint;	
var gTrackTimer;
var gTrackSecondsLeft = 500;

var arrayCoverFadeTime = new Array(0,0,80,10,20,70,0,30,60,50,40,0);

function SwitchStream (input_Stream)
{
var strStream;
	if (input_Stream == "vip")
	{
		strStream = "vip"
	}
	else if (input_Stream == "free")
	{
		strStream = "free"
	}
	if (strStream != "")
	{
		LoadContent('idViewportNowPlaying', '/tools/currentlyplaying/CurrentlyPlaying3.asp?iStream=' + strStream, true);
	}
	else
	{
		LoadContent('idViewportNowPlaying', '/tools/currentlyplaying/CurrentlyPlaying3.asp', true);
	}
}

function DoIt ()
{
	LoadContent('idViewportNowPlaying', '/tools/currentlyplaying/CurrentlyPlaying3.asp', true);
}



var gSecondsElapsed = 0;

function SetStars (inputStars)
{
	for (intStar = 1; intStar <= 5; intStar++)
	{
		if (intStar <= inputStars)
		{
			document.getElementById('idRate' + intStar).src = "/tools/currentlyplaying/images/star-on.png";
		}
		else
		{
			document.getElementById('idRate' + intStar).src = "/tools/currentlyplaying/images/star-off.png";
		}
	}
}
function ResetStars ()
{
	SetStars (0);
}

var gTimeFmt = 'mm:ss';

function FormatTrackTime(seconds)
{
	var s = '';

	if (isNaN(seconds))
	{
		seconds = 0;
	}

	if (!gTimeFmt || gTimeFmt.indexOf('mm:ss') != -1)
	{
		s = '0';

		if (seconds >= 60)
		{
			s = parseInt(seconds/60);
		}

		seconds = seconds % 60;
		s += (seconds > 9) ? ":" : ":0";
	}

	s += seconds;
	return s;
}

function UpdateTrackTime()
{
	var d = (document.all) ? document.all['current_track_time'] : document.getElementById('current_track_time');

	if (d && gTrackSecondsLeft >= 0)
	{
		d.innerHTML = FormatTrackTime(gTrackSecondsLeft);
	}

	if (gTrackSecondsLeft > 0)
	{
		gTrackSecondsLeft--;
	}
	else
	{
		if (gFlashPoint)
		{
			clearInterval(gFlashPoint);
		}
		if (gFadeIn)
		{
			clearInterval(gFadeIn);
		}
		if (gFade)
		{
			clearInterval (gFade);
		}

		LoadContent('idViewportNowPlaying', '/tools/currentlyplaying/CurrentlyPlaying3.asp', true);
	}

	if (!gFlashPoint)
	{
		if (gTrackSecondsLeft <= 15)
		{
			gFlashPoint = window.setInterval("FlashPoint()", 5);
		}
	}
}

function FadeIn()
{
	var d2;
	var intCounter;
	var boolFlag_KillProcess = true;

	gSecondsElapsed++;

	for (intCounter = 1; intCounter <= 10; intCounter++)
	{
		if (gSecondsElapsed > arrayCoverFadeTime[intCounter])
		{
			if (arrayCoverOpacity[intCounter] < 1)
			{
				arrayCoverOpacity[intCounter] = arrayCoverOpacity[intCounter] + arrayCoverOpacityDirection[intCounter];
				boolFlag_KillProcess = false;
			}
			else
			{
				arrayCoverOpacity[intCounter] = 1;
			}

//			d2 = (document.all) ? document.all['idCover' + intCounter] : document.getElementById('idCover' + intCounter);

document.getElementById('idCover' + intCounter).style.opacity = arrayCoverOpacity[intCounter];
document.getElementById('idCover' + intCounter).style.filter = 'alpha(opacity=' + arrayCoverOpacity[intCounter] * 100 + ')';
		}
		else
		{
			boolFlag_KillProcess = false;
		}
	}

	if (floatOpacity < 1)
	{
		floatOpacity = floatOpacity + floatOpacityDirection;

//		var d = (document.all) ? document.all['idFlashPoint'] : document.getElementById('idFlashPoint');

document.getElementById('idFlashPoint').style.opacity = floatOpacity;
document.getElementById('idFlashPoint').style.filter = 'alpha(opacity=' + (floatOpacity * 100) + ')';
		boolFlag_KillProcess = false;

	}

	if (boolFlag_KillProcess == true)
	{
		clearInterval(gFadeIn);
	}
}

function FlashPoint()
{
	var d2;
	var intCounter;

	if (gTrackSecondsLeft > 3)
	{
		if (floatOpacity <= 0.2)
		{
			floatOpacityDirection = 0.02;
		}
		else if (floatOpacity >= 1)
		{
			floatOpacityDirection = -0.02;
		}
	}
	else
	{
		if (floatOpacity > 0)
		{
			floatOpacityDirection = -0.02;
		}
		else
		{
			floatOpacity = 0;
			floatOpacityDirection = 0;
		}
	}
	if (gTrackSecondsLeft > 5)
	{
		gSecondsElapsed = 0;
	}
	else
	{
		gSecondsElapsed++;
	}

	floatOpacity = floatOpacity + floatOpacityDirection;

//	var d = (document.all) ? document.all['idFlashPoint'] : document.getElementById('idFlashPoint');

document.getElementById('idFlashPoint').style.opacity = floatOpacity;
document.getElementById('idFlashPoint').style.filter = 'alpha(opacity=' + (floatOpacity * 100) + ')';

	for (intCounter = 1; intCounter <= 10; intCounter++)
	{
		if (gSecondsElapsed > arrayCoverFadeTime[intCounter])
		{
			if (arrayCoverOpacity[intCounter] > 0)
			{
				arrayCoverOpacity[intCounter] = arrayCoverOpacity[intCounter] - arrayCoverOpacityDirection[intCounter];
			}
			else
			{
				arrayCoverOpacity[intCounter] = 0;
			}

//			d2 = (document.all) ? document.all['idCover' + intCounter] : document.getElementById('idCover' + intCounter);

document.getElementById('idCover' + intCounter).style.opacity = arrayCoverOpacity[intCounter];
document.getElementById('idCover' + intCounter).style.filter = 'alpha(opacity=' + arrayCoverOpacity[intCounter] * 100 + ')';
		}
	}
}

function Initialize ()
{
	if (gFlashPoint)
	{
		clearInterval(gFlashPoint);
	}
	if (gFadeIn)
	{
		clearInterval(gFadeIn);
	}
	if (gFade)
	{
		clearInterval (gFade);
	}

	floatOpacity = 0;
	floatOpacityDirection = 0.005;
	intDefault = 4;
//	gTrackSecondsLeft = 20;

	var intCounter;

	for (intCounter = 1; intCounter <= 10; intCounter++)
	{
		arrayCoverOpacity[intCounter] = 0;
		arrayCoverOpacityDirection[intCounter] = 0.005;
	}

/*
if (gTrackTimer)
{
	clearInterval (gTrackTimer);
}
*/

	if (gTrackTimer)
	{
	}
	else
	{
		gTrackTimer = window.setInterval("UpdateTrackTime()", 1000);
	}

	gFadeIn = window.setInterval("FadeIn()", 25);
}

function GetXMLHTTPRequest ()
{
	var objXMLHTTPRequest = false;

	if (window.XMLHttpRequest)
	{
		objXMLHTTPRequest = new XMLHttpRequest ();
	}
	else
	{
		if (window.ActiveXObject)
		{
			try
			{
				objXMLHTTPRequest = new ActiveXObject("Msml2.XMLHTTP");
			}
			catch (err)
			{
				try
				{
					objXMLHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (err2)
				{
					objXMLHTTPRequest = false;
				}
			}
		}
	}

	return objXMLHTTPRequest;
}



function LoadContent (input_ID, input_URL, input_Initialize)
{
	var objXMLHTTPRequest = new GetXMLHTTPRequest();
	var currentTime = new Date();

	if (objXMLHTTPRequest)
	{
		if (input_URL.indexOf("?") == -1)
		{
			input_URL = input_URL + '?iCacheKiller=' + currentTime.getTime();
		}
		else
		{
			input_URL = input_URL + '&iCacheKiller=' + currentTime.getTime();
		}

		objXMLHTTPRequest.open("GET", input_URL);

		if (input_Initialize == true)
		{
			objXMLHTTPRequest.onreadystatechange = function ()
			{
				if (objXMLHTTPRequest.readyState == 4 && objXMLHTTPRequest.status == 200)
				{
//					document.getElementById(input_ID).innerHTML = objXMLHTTPRequest.responseText;

					var objNode = objXMLHTTPRequest.responseXML.getElementsByTagName("crap-body")[0];
					var strContent = objNode.childNodes[0].nodeValue;
					document.getElementById(input_ID).innerHTML = strContent;
					var objNode = objXMLHTTPRequest.responseXML.getElementsByTagName("seconds")[0];
					var strContent = objNode.childNodes[0].nodeValue;
					gTrackSecondsLeft = strContent;

					delete objXMLHTTPRequest;
					Initialize();
					objXMLHTTPRequest = null;
				}
			}
		}
		else
		{
			objXMLHTTPRequest.onreadystatechange = function ()
			{
				if (objXMLHTTPRequest.readyState == 4 && objXMLHTTPRequest.status == 200)
				{
					document.getElementById(input_ID).innerHTML = objXMLHTTPRequest.responseText;

					delete objXMLHTTPRequest;

					objXMLHTTPRequest = null;
				}
			}
		}

		objXMLHTTPRequest.send(null);
	}
}








var floatFadeInfo = 0;
var boolOkay = true;
var idNext = "";
var idToBottom = "";
var urlNext = "";
var intX;
var intY;

function MoreInfo (input_ID, input_URL)
{
	if (boolOkay == true)
	{
		idNext = "";
		urlNext = "";
		idToBottom = input_ID;
		if (gFade)
		{
			clearInterval(gFade);
		}
if (input_ID == 'idCover1')
{
intX = 40;
intY = -5;
}
else
{
		intX = parseInt(document.getElementById(input_ID).style.left) - 440;
		intY = parseInt(document.getElementById(input_ID).style.top) - 10;
}


		document.getElementById(input_ID).style.zIndex = 100;
		document.getElementById('idPop').style.left = intX + 'px';
		document.getElementById('idPop').style.top = intY + 'px';
		document.getElementById('idPop').style.zIndex = 50;
		document.getElementById('idPop').style.display = 'block';
		document.getElementById('idPop').style.opacity = 0;
document.getElementById('idPop').style.filter = 'alpha(opacity=0)';

		if (input_URL != "")
		{
			document.getElementById('idPop').innerHTML = '<div style="position: relative; top: 0px; left; 0px; width: 500px; height: 300px; margin: 0px; border: 0px; padding: 0px; background-image: url(\'http://www.phonogenics.com/tools/currentlyplaying/images/loading.gif\'); background-position: 50% 50%; background-repeat: no-repeat;"></div>';
			LoadContent ('idPop', input_URL, false);
		}
		else
		{
			document.getElementById('idPop').innerHTML = '<p><strong>Track:</strong> ...<br><strong>Artist:</strong> ...<br><strong>Album:</strong> ...</p><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Mauris fringilla posuere dolor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p><p>Nam nisl sapien, eleifend sagittis, ornare et, posuere sed, leo. Morbi justo ligula, laoreet ac, semper ac, luctus in, turpis. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean ultrices. Nam sed lacus. Vivamus ultrices sagittis libero. Nunc suscipit leo sed justo. Nullam mi. Praesent accumsan.</p><p style="text-align: right;">click image for more info.</p>';
		}
		floatFadeInfo = 0;
		boolOkay = false;
		gFade = setInterval ("FadeInfoIn()", 20);
	}
	else
	{
		idNext = input_ID;
		urlNext = input_URL;
	}
}









function FadeInfoIn()
{
	if (floatFadeInfo < 0.9)
	{
		floatFadeInfo = floatFadeInfo + 0.05;
		document.getElementById('idPop').style.opacity = floatFadeInfo;
document.getElementById('idPop').style.filter = 'alpha(opacity=' + floatFadeInfo * 100 + ')';
	}
	else
	{
		if (gFade)
		{
			clearInterval(gFade);
		}
	}
}

function FadeInfoOut()
{
	if (floatFadeInfo > 0)
	{
		floatFadeInfo = floatFadeInfo - 0.05;
		document.getElementById('idPop').style.opacity = floatFadeInfo;
document.getElementById('idPop').style.filter = 'alpha(opacity=' + floatFadeInfo * 100 + ')';

	}
	else
	{
		if (gFade)
		{
			clearInterval(gFade);
			document.getElementById(idToBottom).style.zIndex = 1;
			idToBottom = "";
			document.getElementById('idPop').style.zIndex = 0;
			document.getElementById('idPop').style.display = 'none';
			document.getElementById('idPop').innerHTML = '<div style="position: relative; top: 0px; left; 0px; width: 500px; height: 300px; background-image: url(\'http://www.phonogenics.com/tools/currentlyplaying/images/loading.gif\'); background-position: 50% 50%; background-repeat: no-repeat;"></div>';
			boolOkay = true;
		}

		if (idNext != "")
		{
			MoreInfo (idNext, urlNext);
		}
	}
}

function LessInfo (input_ID)
{
//	document.getElementById(input_ID).style.zIndex = 0;
	idNext = "";
	urlNext = "";

	if (gFade)
	{
		clearInterval(gFade);
	}

	gFade = setInterval ("FadeInfoOut()", 10);
}	