var ready=false;
var popup=null;
var play_url=null;
var play_arg=null;
var installing=false;
var FileURL;
var FreedomInterface=null;
var FreedomInstallVersion="1.0.8.7";
var FreedomInstall="not-installed";
var FreedomSkin=null;
var FreedomWidth=300;
var FreedomHeight=50;
var FreedomStyle=null;
var FreedomHome=null;
var FreedomOptions=null;
//var bHandleEvent=false;
var intervalID=0;

function play(url){play(url,"now");}

function play(url,arg){
	if(!ready && document.applets && document.freedomaudio && document.freedomaudio.isActive())ready=true;
	if(ready){
		if(play_url!=null){url=play_url;arg=play_arg;play_url=null;}
		if(url!=null && typeof(url)!="undefined"){
			var i=url.toLowerCase().indexOf("?fileurl=");
			if(i>=0){url=url.substring(i+9)}
			FileURL=url;
			if(arg==null || typeof(arg)=="undefined" || arg=="now"){document.freedomaudio.playAudio(url);}
			else{document.freedomaudio.playNext(url);}
		}
		focus();
	}
	else{
		if(play_url==null){play_url=url;play_arg=arg;}
		setTimeout("play(play_url,play_arg)",500);
	}
}

function freedom_install(s){
	installing=true;
	var properties='left=20,top=20,width=500,height=350,resizable=no,toolbar=no,status=no,scrollbars=no';
	popup=window.open(s,"install",properties);
	popup.window.focus();
	intervalID=setInterval("isPopupClosed()",1000);
	return true;
}

function isPopupClosed(){
	if(popup==null || popup.closed){
		if(installing){
			window.location.href=window.location.href+"?install="+FreedomInstallVersion;
			installing=false;
		}
		clearInterval(intervalID);
	}
}

function handleEvent(eventType){
//	bHandleEvent=true;
	if(eventType==22){
		if(installing){
			window.location.href=window.location.href+"?install="+FreedomInstallVersion;
			installing=false;
			if(intervalID!=0)
				clearInterval(intervalID);
		}
	}
}

function ckVmStatus(){if(vm.readyState=="4"){clearInterval(intervalID);window.location.reload();}}

function LoadFreedomAudio(fileurl){

	if(! navigator.javaEnabled()){
		document.write('Java Required');
		window.open("http://www.freedomaudio.com/install/javarequired.html","_blank","");
		alert("Your browser does not support Java.");
	}
	else{
		var agt=navigator.appVersion;
		var i=agt.indexOf("MSIE ");
		if(i != -1){
			ie4=true;
			if(parseInt(agt.substring(i+5,i+6))<5){
				document.writeln('<OBJECT name="vm" CLASSID="clsid:08B0E5C0-4FCB-11CF-AAA5-00401C608500" WIDTH=0 HEIGHT=0 CODEBASE="http://www.freedomaudio.com/install/win/microsoft/msjavx86.exe#version=4,79,2435,0"></OBJECT>');
			}
			else{
				if(! oCC.isComponentInstalled("{08B0E5C0-4FCB-11CF-AAA5-00401C608500}","ComponentID")){
					if(confirm("Your browser requires Java. Would you like to install it now?")==1){
//		document.writeln('<OBJECT name="vm" CLASSID="clsid:08B0E5C0-4FCB-11CF-AAA5-00401C608500" WIDTH=0 HEIGHT=0 CODEBASE="http://www.freedomaudio.com/install/win/microsoft/msjavx86.exe#version=5,00,3805,0"></OBJECT>');
						document.writeln('<OBJECT name="vm" CLASSID="clsid:08B0E5C0-4FCB-11CF-AAA5-00401C608500" WIDTH=0 HEIGHT=0 CODEBASE="http://java.sun.com/products/plugin/1.4/jinstall-1_4-windows-i586.cab#Version=1,4,1,0"></OBJECT>');
						intervalID=setInterval("ckVmStatus()",500);
						document.writeln('<TABLE bgcolor="white"><TR><TD><B>Java Loading... Please Wait!</B></TD></TR></TABLE>');
						return;
					}
				}
			}
		}
		var s="";
//		if(FreedomInstall==null){s+='<OBJECT ID="loader" classid="clsid:9582B68D-B1E1-47aa-8BFE-FF2686F1EDA7" codebase="http://www.freedomaudio.com/install/win/mv/freedominstaller.cab#version=1,0,8,5" STYLE="display:none"></OBJECT>';}
//s+='<OBJECT ID="loader" classid="clsid:9582B68D-B1E1-47aa-8BFE-FF2686F1EDA7" codebase="http://www.freedomaudio.com/install/win/mv/freedominstaller.cab#version=1,0,8,17" STYLE="display:none"></OBJECT>;'
		s+='<APPLET NAME="freedomaudio" CODE="freedomaudio.Player" CODEBASE="." WIDTH="'+FreedomWidth+'" HEIGHT="'+FreedomHeight+'" align="middle">';
		s+='<PARAM NAME="archive" value="freedomaudioloader.jar">';
//		s+='<PARAM NAME="cabbase" value="freedomaudioloader.cab">';
		s+='<PARAM NAME="SCRIPTABLE" VALUE="true">';
		s+='<PARAM NAME="MAYSCRIPT" VALUE="true">';
		var url=location.href;
		var install=url.indexOf("?install=");
		if(install>=0){url=url.substring(0,install);}
//		if(FreedomInstall!=null){
//			if(install<0){s+='<PARAM NAME="install" value="version:'+FreedomInstallVersion+';'+FreedomInstall+'">';}
//			else{s+='<PARAM NAME="install" value="'+FreedomInstall+'">';}
//		}
//		else{
			s+='<PARAM NAME="useslibraryversion" value="1,0,8,7">';
			s+='<PARAM NAME="useslibrary" value="freedomaudio">';
			s+='<PARAM NAME="useslibrarycodebase" value="http://www.freedomaudio.com/install/win/mv/freedominstaller.cab">';
//		}
		if(fileurl!=null && typeof(fileurl) != "undefined" && fileurl!=""){s+='<PARAM NAME="autoload" value="'+fileurl+'">';s+='<PARAM NAME="autostart" value="0">';}
		else{var i=url.toLowerCase().indexOf("?fileurl=");if(i>=0){s+='<PARAM NAME="autoload" value="'+url.substring(i+9)+'">';s+='<PARAM NAME="autostart" value="0">';}}
		if(FreedomInterface!=null){s+='<PARAM NAME="interface" value="'+FreedomInterface+'">';}
		if(FreedomSkin!=null){s+='<PARAM NAME="skin" value="'+FreedomSkin+'">';}
		if(FreedomStyle!=null){s+='<PARAM NAME="style" value="'+FreedomStyle+'">';}
		if(FreedomHome!=null){s+='<PARAM NAME="home" value="'+FreedomHome+'">';}
		if(FreedomOptions!=null){s+='<PARAM NAME="options" value="'+FreedomOptions+'">';}
		s+='<DIV style="background-color:#FFFFFF;padding:20px;border:5px red solid;text-align:center;font-weight:bold">Java Required - <A HREF="javascript:getJava()">Select to Get Java Now!</A></DIV>';
		s+='</APPLET>';
		document.writeln(s);
		if(FreedomWidth=="100%" || FreedomHeight=="100%"){
			intervalID=window.setInterval("maximize()",500);
			window.onresize="maximize()";
		}
//				if(ie4)window.onload=function init1(){setTimeout("init2()",1000);}
	}
}

//function init2(){
//	if(!bHandleEvent){
//		location.href="http://www.freedomaudio.com/install/failed.html";
//	}
//}

function getJava(){
	document.open();
	document.writeln('<OBJECT ID="java2" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_1_02-windows-i586.cab#Version=1,4,0,0" STYLE="display:none"></OBJECT>');
	document.close();
}

function maximize(){
	var w;var h;
	if(document.all){
		if(freedomaudio.readyState != 4){return;}
		w=freedomaudio.clientWidth;
		h=freedomaudio.clientHeight;
	}
	else if(document.layers || document.getElementById){
		if(FreedomWidth=="100%")w=window.innerWidth;
		else w=FreedomWidth;
		if(FreedomHeight=="100%")h=window.innerHeight;
		else h=FreedomHeight;
	}
	clearInterval(intervalID);
	freedomaudio.resize(w,h);
}