/*
ActionScript Extension for FlashSound Javascript API
copyright 2001 Hayden Porter, hayden@aviarts.com
Distributed under the open source Artistic License www.flashsounapi.com/documentation/license.html
v 1.0.4 last update March 14, 2003
*/

// create dummy instance to prevent errors in NN3
if(FlashSound.oldNN){x = new FlashSound(); x = null;}

function fs_convertObjtoPrimative(str){
	str = String(str);
	if(isNaN(str) || str == "") {
		return str; // return as string
	} else {
		return Number(str); // return as number
	}
}

function fs_api_GetVariable(variableName){
	if(!this.isPlayerReady()) return null;
	var objValue = window.document[this.playerID].GetVariable(variableName);
	//check if a number then convert to number
	var retValue = fs_convertObjtoPrimative(objValue);
	return retValue;	
}

function fs_api_SetVariable(variableName,value){
	if(!this.isPlayerReady()) return;
	value = String(value);
	window.document[this.playerID].SetVariable(variableName,value);
}

var _currentframe = 4; //number read only
var _framesloaded = 12; //number read only
var _name = 13; // string read/write
var _soundbuftime = 18; //number read/write global property
var _target = 11; // string read only
var _totalframes = 5; //number read only
var _url = 15; //string read only

// pass property ID number or supported name
function fs_api_TGetProperty(target,propertyName){
	if(!this.isPlayerReady()) {return null;}
	var objValue =  window.document[this.playerID].TGetProperty(target,parseInt(propertyName));
	
	//check if a number then convert to number
	var retValue = fs_convertObjtoPrimative(objValue);
	return retValue;
}

// pass property ID number or supported name
function fs_api_TSetProperty(target,propertyName,value){
	if(!this.isPlayerReady()) {return;}
	window.document[this.playerID].TSetProperty(target,parseInt(propertyName),value)
}

function fs_TCall(target,frame){
	if(!this.isPlayerReady()) {return}
	if(typeof(frame) == "number"){
		window.document[this.playerID].TCallFrame(target,frame - 1);
	}
	if(typeof(frame) == "string"){
		window.document[this.playerID].TCallLabel(target,frame);
	}
}

function fs_evalFSCommand(cmd,args){
	// if comamnd contains complete function string ignore args
	// otherwise build a function call with open and closed parenthesis
	if(cmd.indexOf('(') != -1 && cmd.indexOf(')') != -1){
		var commandstr = String(cmd);
	} else {
		var commandstr = cmd + '(' + args + ')';
	}
	// eval function call
	eval(commandstr);
}

function fs_void(){return;}

function fs_handleFSCommands(state){
	if(state == null) state = true;
	if(!state) {return;}
	if((FlashSound.LiveConnect || FlashSound.XPConnect)){
		window[this.playerID + '_DoFSCommand'] = fs_evalFSCommand;
	}
	if(FlashSound.ActiveX  && FlashSound.configuredForInteraction()){
		document.writeln(
		'<SCR' + 'IPT LANGUAGE="VBScript">'+
		'Sub ' + this.playerID + '_FSCommand (ByVal command, ByVal args)'+
		'call fs_evalFSCommand(command, args)'+
		'end sub'+
		'<\/SCR' + 'IPT>'
		);
	}
}

FlashSound.prototype.GetVariable = fs_api_GetVariable;
FlashSound.prototype.handleFSCommands = fs_handleFSCommands;
FlashSound.prototype.SetVariable = fs_api_SetVariable;
FlashSound.prototype.TCall = fs_TCall;
FlashSound.prototype.TGetProperty = fs_api_TGetProperty;
FlashSound.prototype.getProperty = fs_api_TGetProperty;
FlashSound.prototype.TSetProperty = fs_api_TSetProperty;
FlashSound.prototype.setProperty = fs_api_TSetProperty;