var scrs=[];

function getURL(req_url)
	{if(window.XMLHttpRequest)
		{xmlhttp=new XMLHttpRequest();
		xmlhttp.open("GET",req_url,false);
		xmlhttp.send(null);}
	else if(window.ActiveXObject)
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.open("GET",req_url,false);
		xmlhttp.send();}
	return xmlhttp.responseText;}

function resize(x,y)
	{if(parseInt(navigator.appVersion,10)>3){top.resizeTo(x,y);}}

function push_error(context,errorStr)
	{if(document.getElementById(context+"_error"))
	{if(errorStr===null){document.getElementById(context+"_error").innerHTML="";}
	else{document.getElementById(context+"_error").innerHTML=errorStr;}}}

function checkErrors(form_obj)
	{if(!usernameCheck(form_obj.login.value))
		{alert("Please choose another username, your current selection is already in use.");
		return false;}
	if(form_obj.pass0.value!=form_obj.pass1.value)
		{alert("Your passwords do not match.");
		form.obj.pass0.value="";
		form.obj.pass1.value="";
		return false;}
	return true;}

function usernameCheck(usernameStr)
	{if(getURL("join.php?username_check="+usernameStr)==1)
		{push_error('login',"Your chosen username is already in use. Please select another.");
		return false;}
	else
		{push_error("login",null);
		return true;}}

function playerstop()
	{switch(plugin)
	{case'wm':wmplayer.controls.stop();
	break;
	case'qt':document.qtplayer.Stop();
	break;
	case'real':document.realplayer.DoStop();
	break;
	case'java':document.javaplayer.pressStop();
	break;}}

function playerstart()
	{switch(plugin)
	{case'wm':wmplayer.controls.play();
	break;
	case'qt':document.qtplayer.Play();
	break;
	case'real':document.realplayer.DoPlay();
	break;
	case'java':document.javaplayer.pressStart();
	break;}}

function vol(level)
	{switch(plugin)
	{case'wm':realvol=(100/6)*level;wmplayer.settings.volume=(realvol);
	break;
	case'qt':realvol=(255/6)*level;document.qtplayer.SetVolume(realvol);
	break;
	case'real':realvol=(100/6)*level;document.realplayer.SetVolume(realvol);
	break;
	case'java':realvol=(100/6)*level;document.javaplayer.setGain(realvol);
	break;}
	document.getElementById('volume').src='../images_3wk2005/vol_'+level+'.jpg';}

function addscroller(station,divname)
	{i=scrs.length;scrs[i]=[];scrs[i].station=station;
	scrs[i].divname=divname;
	scrs[i].divwidth="300px";
	scrs[i].divcontent='';
	scrs[i].urls=[];document.write('<span id="'+scrs[i].divname+'playing"'+'style="visibility:hidden; position:absolute; top:-100px; left:-9000px"></span>');}

function populate_affiliates(i,data)
	{scrs[i].urls.insound="http://search.insound.com/search/searchmain.jsp?select=artist&from=88936&query="+data.artist;
	scrs[i].urls.amazon="http://3wk.gestalt-inc.com/?searchterm="+data.artist;
        scrs[i].urls.emusic="http://www.emusic.com/search.html?mode=a&QT="+data.artist;
	scrs[i].urls.ampcamp="http://www.ampcamp.com/basic_search_result.php?ref=9+affiliate_banner_id=1keywords="+data.artist;}

function update_table(stationdata)
	{document.getElementById('scroller-artist').innerHTML=stationdata.artist;
	document.getElementById('scroller-song').innerHTML=stationdata.title;
	document.getElementById('scroller-album').innerHTML=stationdata.album;
	document.getElementById('scroller-label').innerHTML=stationdata.label;
	return;}

function goscroll()
	{for(var i=0;i<scrs.length;i++)
	{if(document.getElementById(scrs[i].divname+"playing")){scrs[i].actualwidth=document.getElementById(scrs[i].divname+"playing").offsetWidth;}
	else{scrs[i].actualwidth="300";}}
	setInterval(scrollit,50);updt_scrs();setInterval(updt_scrs,30000);}

function updt_scrs()
	{var stationdata=eval('('+getURL('/notify.json')+')');
	for(var i=0;i<scrs.length;i++)
		{thisdata=stationdata[scrs[i].station];
		if(!(document.getElementById('scroller-artist')==null)){update_table(thisdata);}
	info='now playing: '+thisdata.artist+' / '+thisdata.title+' - '+thisdata.album+' / '+thisdata.label;populate_affiliates(i,thisdata);scrs[i].divcontent='<nobr>'+info+'</nobr>';
	if(!(document.getElementById(scrs[i].divname)===null))
		{document.getElementById(scrs[i].divname).innerHTML=scrs[i].divcontent;
		document.getElementById(scrs[i].divname+"playing").innerHTML=scrs[i].divcontent;scrs[i].actualwidth=document.getElementById(scrs[i].divname+"playing").offsetWidth;}}}

function scrollit()
	{for(var i=0;i<scrs.length;i++)
	{if(parseInt(document.getElementById(scrs[i].divname).style.left,10)>(scrs[i].actualwidth*(-1)+8+5)){document.getElementById(scrs[i].divname).style.left=parseInt(document.getElementById(scrs[i].divname).style.left,10)-2+"px";}
	else{document.getElementById(scrs[i].divname).style.left=parseInt(300,10)+8+"px";}}}

function gonoscroll()
	{updt_scrs();setInterval(updt_scrs,30000);}
