/*
################################################################
#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()
if (window.location.href.indexOf("https") == -1) {
	http = "http:";
} else {
	http = "https:";
}

function writePlayer() {
		var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
		+ 'WIDTH="431" HEIGHT="330"'
		+ 'CODEBASE="'+http+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" name="main" id="main">'
		+ '<PARAM NAME="MOVIE" VALUE="preload.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" />'
		+ '<EMBED SRC="preload.swf"'
		+ 'id = "embedMain"'
		+ 'name="main"'
		+ 'scale="noscale"'
		+ 'salign="lt"'
		+ 'width="431"'
		+ 'height="330"'
		+ 'wmode="transparent"'
		+ 'PLAY="true"'
		+ 'LOOP="false"'
		+ 'allowScriptAccess="sameDomain"'
		+ 'QUALITY="high"'
		+ 'TYPE="application/x-shockwave-flash"'
		+ 'PLUGINSPAGE="'+http+'www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
		+ '<\/EMBED>'
		+ '<\/OBJECT>';

	//alert(oeTags);
	document.write(oeTags);

}

var timeoutID = null;
var playerFocus = null;

function buyTrack(dbid){
	alert("buy "+dbid);
}

function buyAllTracks(dbids){
	alert("buy all "+dbids.toString());
}


function openPlayer() {
    if (playerFocus==null || playerFocus.closed) {
        ///fplayer/player.html
	playerFocus = window.open("",'player',"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=431, height=330");
       if(playerFocus.location.toString()=='about:blank' || playerFocus.location.toString().substr(playerFocus.location.toString().length-18,18) != 'player/player.html'){
           playerFocus.location = '/player/player.html';
       }
       if (!playerFocus.opener) playerFocus.opener = self;
    }

    if(playerFocus!=null) {
        playerFocus.focus();
    }

}

function addTrackQS(qs){
    openPlayer();
    if(timeoutID!=null){
        clearInterval(timeoutID);
        timeoutID = null;
    }

    var playerok;

	var main = playerFocus.document.getElementById("main"); 
	var embedMain = playerFocus.document.getElementById("embedMain"); 

    if(main){
        if(main.addTrackQS){
            playerok=main.addTrackQS(qs);
        }else{
            //we will use the embed instead;
            if(embedMain && embedMain.addTrackQS){
                playerok=embedMain.addTrackQS(qs);
            }else{
                playerok=false;
            }
        }
    }else{
        playerok=false;
    }

    if(playerok==false){
        timeoutID = window.setInterval(function(){addTrackQS(qs)},1000);
    }
}
/*
function addTrackQS(qs){
	if(playerFocus==null || playerFocus.closed){
		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)},1000);
	}
}
*/

// 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');
}
