/*
################################################################
#Page: player.js
#Purpose: 
#Description: 
#Caveats: 
#Dependancies:
#Create Date: 23rd March 2007
#History:
#Author: Paul Hesketh
#params:
################################################################
*/

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var firstLoad = 1;
var openWindowPlease = 0;

function fnWriteUpdatePlayer()
{
	if(hasRightVersion) {
	var XMLHttpRequestObject = false;
		var sUrl = sitePath+"player/init.player.php";
		if(window.XMLHttpRequest){ XMLHttpRequestObject = new XMLHttpRequest(); } 
		else if (window.ActiveXObject) 	{ XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); }
		if(XMLHttpRequestObject) {
			XMLHttpRequestObject.open("GET", sUrl, true);
			
			XMLHttpRequestObject.send(null);
		}
	Stamp = new Date();
	var sNum=Stamp.getSeconds()+ Stamp.getMinutes();
	var flashVars = 'sConnectionName=blackmarket&nConnectionNum='+sNum;
	var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
		+ 'WIDTH="1" HEIGHT="1"'
		+ 'CODEBASE="'+$http+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" id="updatePlayer">'
		+ '<PARAM NAME="MOVIE" VALUE="'+sitePath+'player/updatePlayer.swf">'
		+ '<PARAM NAME="PLAY" VALUE="true">'
		+ '<PARAM NAME="QUALITY" VALUE="high">'
		+ '<param name="scale" value="noscale" />'
		+ '<PARAM NAME="MENU" VALUE="false">'
		+ '<param name="wmode" value="transparent">'
		+ '<param name="allowScriptAccess" value="sameDomain" />'
		+ '<param name="FlashVars" value="'+flashVars+ '" />'
		+ '<EMBED SRC="'+sitePath+'player/updatePlayer.swf"'
		+ 'name="updatePlayer"'
		+ 'scale="noscale"'
		+ 'width="1"'
		+ 'height="1"'
		+ 'wmode="transparent"'
		+ 'PLAY="true"'
		+ 'LOOP="false"'
		+ 'allowScriptAccess="sameDomain"'
		+ 'QUALITY="high"'
		+ 'MENU="false"'
		+ 'flashvars="'+flashVars+'"'
		+ 'TYPE="application/x-shockwave-flash"'
		+ 'PLUGINSPAGE="'+$http+'www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
		+ '<\/EMBED>'
		+ '<\/OBJECT>';
		document.write(oeTags);
		//alert(oeTags);
		addLoadEvent(function() { 
		 if (!(navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Mac") != -1) && hasRightVersion) {
			//setTimeout(radio_passFakeData, 1000);
			setTimeout(radio_checkFlash, 1000);
		  }
		});
	} else {
	}
}

// Handle all the FSCommand messages in a Flash movie.
function updatePlayer_DoFSCommand(command, args) {
	
	//alert("fscommand here");
	/*
	var updatePlayerObj = isInternetExplorer ? document.all.updatePlayer : document.updatePlayer;
	if ((command == "winStatus") || (command == "FSCommand:winStatus")){
	switch(args){
		case "0": //do nothing
			break;
		case "1": window.open(sitePath+"player/example.php",'player',"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+(355)+", height="+(421));
				break;
		case "2": fnOpenFlashPlayer(1);//found it;
			break;
	 }
	 
	}*/

}

function fnOpenFlashPlayer(sAction){
	if(sAction == 0){
		playerFocus = window.open(sitePath+"player/player.php",'player',"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=303, height=502");
	}
	playerFocus.focus();
}
	// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub updatePlayer_FSCommand(ByVal command, ByVal args)\n');
	document.write('Call updatePlayer_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}


function radio_checkFlash() {
  setTimeout(radio_checkFlash, 1000);
  v =window.document.updatePlayer.GetVariable("jsOpenWindow");
  //window.status = v;
  if(v == 1 || firstLoad == 1) {
  	
    openWindowPlease = 1;	

  }else if(v == 2) {
  	//alert("Don't Open Please");
    openWindowPlease = 2;

  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}