/*
################################################################
#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 localTime = new Date()
function writePlayer() {
	var flashVars = 'sConnectionName=blackmarket&sSession='+sSession+'&sXmlConfig='+sitePath+'player/config_blackmarket.xml&sXmlResourceUrl='+ sitePath+'player/init.player.php&bStream=false';
	if (!useRedirect) {
  		if(hasRightVersion) {
   	 		var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    		+ 'WIDTH="310" HEIGHT="500"'
    		+ 'CODEBASE="'+$http+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" id="main">'
    		+ '<PARAM NAME="MOVIE" VALUE="'+sitePath+'player/main.swf">'
   	 		+ '<PARAM NAME="PLAY" VALUE="true">'
   	 		+ '<PARAM NAME="QUALITY" VALUE="high">'
			+ '<param name="salign" value="lt" />'
			+ '<param name="scale" value="noscale" />'
			+ '<param name="wmode" value="transparent">'
			+ '<param name="allowScriptAccess" value="sameDomain" />'
			+ '<param name="FlashVars" value="'+flashVars+ '" />'
    		+ '<EMBED SRC="'+sitePath+'player/main.swf"'
			+ 'id = "embedMain"'
			+ 'name="main"'
			+ 'scale="noscale"'
			+ 'salign="lt"'
			+ 'width="310"'
			+ 'height="500"'
			+ 'wmode="transparent"'
    		+ 'PLAY="true"'
    		+ 'LOOP="false"'
			+ 'allowScriptAccess="sameDomain"'
    		+ 'QUALITY="high"'
			+ 'flashvars="'+flashVars+'"'
    		+ 'TYPE="application/x-shockwave-flash"'
    		+ 'PLUGINSPAGE="'+$http+'www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
    		+ '<\/EMBED>'
    		+ '<\/OBJECT>';
  		} else {
			var oeTags = '<a href="http://www.macromedia.com/go/getflashplayer" target="_blank"><img src="'+sitePath+'images/no-flash-image-player.gif" alt="Please install flash" border="0" /></a>';
		}
		//alert(oeTags);
		document.write(oeTags);
	}
}

var timeoutID = null;
var playerFocus = null;

function addTrackQS(qs){
	if(playerFocus==null || playerFocus.closed){
		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");
		if (!playerFocus.opener) playerFocus.opener = self;
	}
	if(playerFocus!=null) { 
		playerFocus.focus();
	}
	if(timeoutID!=null){
		clearInterval(timeoutID);
		timeoutID = null;
	}
	var playerok;
	//alert("!!"+playerFocus.main);
	if(playerFocus.document.main){
		if(playerFocus.document.main.addTrackQS){
			playerok=playerFocus.document.main.addTrackQS(qs);
		}else{
			//we will use the embed instead;
			if(playerFocus.document.embedMain && playerFocus.document.embedMain.addTrackQS){
				playerok=playerFocus.document.embedMain.addTrackQS(qs);
			}else{
				playerok=false;
			}
		}
		
	}else{
		playerok = false;
	}
	

	if(playerok==false){
		timeoutID = window.setInterval(function(){addTrackQS(qs)},500);
	}
}


// Handle all the FSCommand messages in a Flash movie.
function main_DoFSCommand(command, args) {
	var mainObj = isInternetExplorer ? document.all.main : document.main;
	if ((command == "buyAction") || (command == "FSCommand:buyAction")){
		//code here
	}
	if ((command == "removeAction") || (command == "FSCommand:removeAction")){
		//code here
	}
	if ((command == "addAction") || (command == "FSCommand:addAction")){
		//code here
	}
	if ((command == "infoAction") || (command == "FSCommand:infoAction")){
		//code here
	}
}
	// 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 main_FSCommand(ByVal command, ByVal args)\n');
	document.write('Call main_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
	