
	var AdminResponse = "";
	var UserResponse = "";
	var ListResponse = "";
	var user_id = "";
	var purged = "";
	var avatar_dimensions = "";
	var playlist_items = "";
	var currScreen = "";
	var midWindow = 0;	
	var tipContainer = "";
	var maximum = 188; 
	var nFile = [];
	var nScreen = [];
	var nAvatar = [];
	var userId = [];
	
	function stayHome(){	

		var iL = 0;
		var iT = 0;
		var currX = event.clientX;
		var currY = event.clientY;
		if (document.documentElement && document.documentElement.scrollLeft || document.documentElement && document.documentElement.scrollTop)
			{
			 iL = document.documentElement.scrollLeft;	
			 iT = document.documentElement.scrollTop;
			}
		if (currX > midWindow-30)
			{
			 var msgWidth = tipContainer.clientWidth;
			 tipContainer.style.left = (currX-msgWidth-15+iL)+'px';
			}
		else	{
			 tipContainer.style.left = (currX+15+iL)+'px';
			}
		tipContainer.style.top = (currY+iT)+'px';
	}

	function hideMessage(){

		tipContainer.style.display = 'none';
		while (tipContainer.lastChild)
			{tipContainer.removeChild(tipContainer.lastChild)}
	}

	function showMessage(toolTip,currItem){

		var tipTxt = toolTip.split("|");
		tipContainer.style.display = 'inline';
		for (i=0; i<tipTxt.length; i++)
			{
			 tipContainer.appendChild(document.createTextNode(tipTxt[i]))
			 tipContainer.appendChild(document.createElement('br'))
			}
		currItem.onmouseout=hideMessage;
	}

	function getMidWindow(){

		if (document.documentElement && document.documentElement.scrollLeft || document.documentElement && document.documentElement.scrollTop)
			{
			 midWindow = document.documentElement.clientWidth/2;
			}
		else 	{
			 midWindow = document.body.clientWidth/2;
			}
	}

	function initToolTip(){

		var nBody = document.getElementsByTagName('body')[0];
		var tipBox = document.createElement('div');
		tipBox.style.position = "absolute";
		tipBox.style.top = "0px";
		tipBox.style.left = "0px";
		tipBox.style.border = "1px solid black";
		tipBox.style.backgroundColor = "#ffff00";
		tipBox.style.paddingRight = "5px";
		tipBox.style.paddingLeft ="5px";
		tipBox.style.paddingTop = "3px";
		tipBox.style.paddingBottom = "3px";
		tipBox.style.fontFamily = "tahoma";
		tipBox.style.fontSize = "13pt";
		tipBox.style.lineHeight = "102%";
		tipBox.id = "isFloat1";
		nBody.appendChild(tipBox);
		tipContainer = document.getElementById('isFloat1');
		tipContainer.style.display = 'none';
		document.onmousemove = stayHome;
		getMidWindow();
	}

	function playSong(currIndex){

		var currSong = "Media/" + user_id + "/" + nFile[currIndex].firstChild.data + ".mp3";
		document.Player.filename = currSong;
	}

	function parseList(){

		var nMsg = ListResponse.getElementsByTagName('message')[0].firstChild.data;
		if (nMsg != "Okay")
			{
			 alert(nMsg);
			 return;
			}
		nFile = ListResponse.getElementsByTagName('title');
		if (nFile.length == 0)
			{
			 alert(currScreen + '\ndoes not have any active tunes');
			 return;
			}
		var nDate = ListResponse.getElementsByTagName('date');
		var dataStr = "<span class='playText'>-- " + currScreen + " Suggests --" + "</span><br>";
		for (i=0; i<nFile.length; i++)
			{
			 dataStr += "<span class='playText'>" + nFile[i].firstChild.data + ",&nbsp;&nbsp;Available until:&nbsp" + nDate[i].firstChild.data + "&nbsp;&nbsp;<input type='button' value='Play' onclick='playSong("+i+")' class='playBtn'><span><br>";
			}
		document.getElementById('playlist').style.display =  "";
		document.getElementById('playlist').innerHTML =  dataStr; 
	}

	function getPlayList(nID,useScreen){

		hideMessage();
		var ListRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();   
		ListRequest.onreadystatechange = function()
			{
		 	 if (ListRequest.readyState == 4)
				{
		 	 	 if (ListRequest.status == 200)
					{
			 	 	 ListResponse = ListRequest.responseXML;
					 purged = nID;
					 parseList();
					}
		 	 	 else 	{
				 	 alert('Error get_playlist.php File '+ ListRequest.statusText);
					}
				}
			}
		currScreen = useScreen;
		user_id = nID;
		var forceGET = "?n="+ parseInt(Math.random()*999999999);
		var infoStr = forceGET + "&id="+nID+"&max="+playlist_items+"&purged="+purged;
		ListRequest.open("GET", "get_playlist.php"+infoStr, true);
		ListRequest.send(null); 
	}
	
	function buildAvatars(){

		if (nAvatar.length == 0){return}
		var nContainer = document.getElementById('avatars');
		nContainer.style.display = "";
		nContainer.style.width = ((avatar_dimensions[0] * 5) + 50) + "px";
		for (i=0; i<nAvatar.length; i++)
			{
			 var nImg = document.createElement('img');
			 nImg.src = "Media/avatars/" + nAvatar[i];
			 nImg.id = "idx"+i;
			 nImg.alt = "";
			 nImg.style.width =  avatar_dimensions[0] + "px";
			 nImg.style.height = avatar_dimensions[1] + "px";
			 nImg.style.border = "2px solid #0000ff";
			 nImg.style.margin = "3px";
			 nImg.style.cursor = "pointer";
			 nImg.style.backgroundColor = "#ffffe0";
			 nImg.onclick = function()
				{
				 var index = this.id.replace(/^idx/,"");
				 getPlayList(userId[index],nScreen[index]);
				}
			 nImg.onmouseover = function()
				{
				 var index = this.id.replace(/^idx/,"");
				 showMessage(nScreen[index],this);
				}
			 nContainer.appendChild(nImg);
			}

	}

	function parseUsers(){

		var nMsg = UserResponse.getElementsByTagName('message')[0].firstChild.data;
		if (nMsg != "Okay")
			{
			 alert(nMsg);
			 return;
			}
		var temp = UserResponse.getElementsByTagName('avatar');
		for (i=0; i<temp.length; i++)
			{
			 nAvatar[i] = temp[i].firstChild.data;
			}
		temp = UserResponse.getElementsByTagName('screen_name');
		for (i=0; i<temp.length; i++)
			{
			 nScreen[i] = temp[i].firstChild.data;
			}
		temp = UserResponse.getElementsByTagName('id');
		for (i=0; i<temp.length; i++)
			{
			 userId[i] = temp[i].firstChild.data;
			}
		buildAvatars();
	}

	function obtainUsers(){

		var UserRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();   
		UserRequest.onreadystatechange = function()
			{
		 	 if (UserRequest.readyState == 4)
				{
		 	 	 if (UserRequest.status == 200)
					{
			 	 	 UserResponse = UserRequest.responseXML;
			 	 	 parseUsers();
					}
		 	 	 else 	{
				 	 alert('Error get_users.php File '+ UserRequest.statusText);
					}
				}
			}
		var forceGET = "?n="+ parseInt(Math.random()*999999999);
		UserRequest.open("GET", "get_users.php"+forceGET, true);
		UserRequest.send(null); 
	}
	
	function parseSettings(){

		avatar_dimensions = AdminResponse.getElementsByTagName('avatar_dimensions')[0].firstChild.data.split(",");
		playlist_items = AdminResponse.getElementsByTagName('max_in_playlist')[0].firstChild.data;
		obtainUsers();
	}

	function obtainSettings(){

		var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();   
		AdminRequest.onreadystatechange = function()
			{
		 	 if (AdminRequest.readyState == 4)
				{
		 	 	 if (AdminRequest.status == 200)
					{
			 	 	 AdminResponse = AdminRequest.responseXML;
			 	 	 parseSettings();
					}
		 	 	 else 	{
				 	 alert('Error Admin.xml File '+ AdminRequest.statusText);
					}
				}
			}
		var forceGET = "?n="+ parseInt(Math.random()*999999999);
		AdminRequest.open("GET", "Admin.xml"+forceGET, true);
		AdminRequest.send(null); 
	}
	
	function init(){

		var container = document.getElementById('nContainer');
		var sub = document.getElementById('nSub');
		var pos = document.forms['volume']['nPos'];
		var vol = document.forms['volume']['nVol'];
		var temp = 0;
		var midVolume = -1100;
		var range = 900;
		var volume = 0;
		container.style.width = Math.floor(maximum*1.1)+'px';
		sub.style.paddingLeft = parseInt(container.style.width)*10+'px';
		sub.style.paddingRight = parseInt(container.style.width)*10+'px';
		container.onscroll = function()
			{
			 temp = Math.round(container.scrollLeft/20.89);
			 if (temp < 0)
				{
				 temp = 0;
				}
			 pos.value = (((temp/maximum)*100).toFixed(0)/100);
			 vol.value = Math.round(midVolume + (range * pos.value));
 			 document.Player.Volume = vol.value;
			}
		container.scrollLeft = 1980;
		initToolTip();
		obtainSettings();
	}

	onload=init;
	onresize=getMidWindow;

