var barY = -35;
var scrolldir = "down";

function addY()
{
	if (scrolldir == "down")
	{
		if (barY > -35)
		{
			// If the bar is visible on the page, make sure it's visible.
			document.getElementById('nowplaying').style.display='table-cell';
		}
		if (barY < 0)
		{
			// Move the bar down 1 pixel
			barY += 1;
			document.getElementById('nowplaying').style.top = barY+'px';
			
			// Repeat after 15 milliseconds
			setTimeout("addY()", 15);
		}
		else
		{
			// Make the thing disappear after 5 seconds
			scrolldir = 'up';
			setTimeout("subY()", 5000);
		}
	}
}

function subY()
{
	if (scrolldir == "up")
	{
		if (barY > -35)
		{
			// Move the bar 1 pixel
			barY -=1;
			document.getElementById('nowplaying').style.top = barY+'px';
			
			// Repeat after 15 milliseconds
			setTimeout("subY()", 15);
		}
		else
		{
			// If the thing is off the page, just make it go away.
			document.getElementById('nowplaying').style.display = 'none';
		}
	}
}

function triggerNP()
{
	scrolldir = 'down';
	addY();
}

function leaveNP()
{
	scrolldir = 'up';
	subY();
}

function keepNP()
{
	scrolldir = "down";
	if (barY < 0)
	{
		addY();
	}
}

function setCurPlay()
{
	var http = false;
	
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		http = new XMLHttpRequest();
	}
	
	http.open("GET", "nowplaying.php");
	http.onreadystatechange=function() {
		if(http.readyState == 4)
		{
			var res = http.responseText;
			if (res != "")
			{
				curPlay = res;
				if (curPlay != sesPlay)
				{
					document.getElementById('nptext').innerHTML = curPlay + '&nbsp;&nbsp;&nbsp; <span id="killsong" name="killsong"><a href="javascript:killsong()" style="color: red;">Stop!</a></span>';
					sesPlay = curPlay;
					scrolldir = "down";
					addY();
				}
			}
			setTimeout('setCurPlay()', 15000);
		}
	}
	http.send(null);
}

function killsong()
{
	if (confirm("Are you sure you want to try to take this song off the air?"))
	{
		var http = false;
		
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			http = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			http = new XMLHttpRequest();
		}
		
		http.open("GET", "http://studio.klikradio.org/killsong.php");
		http.onreadystatechange=function() {
			if(http.readyState == 4)
			{
				var res = http.responseText;
				if (res != "killed")
				{
					document.getElementById('killsong').innerHTML = 'Sent.';
				}
				else
				{
					document.getElementById('killsong').innerHTML = 'Killed!';
				}
			}
		}
		http.send(null);
	}
}
