/*
---::: This is used to call velocix, and get the "current" streaming URL.
*/
function getURL(thePlaceholder, thePlayerId, theFile, theImage){
	//'VZ_CUSTOMURL|VELOCIX|c653|[BUCKETNAME]/[FILENAME]
	//VZ_CUSTOMURL|VELOCIX|c653|[STREAMNAME]|live
	var isVelocixStream = theFile.indexOf("VZ_CUSTOMURL");

	if(isVelocixStream >= 0){
		var velocixSplit = theFile.split("|");
		//is this live?
		if(velocixSplit[4] == "live"){
			var scriptFileName = velocixSplit[3].replace("-","/");
			loadVelocix('http://flash.velocix.com/'+ scriptFileName +'?format=jscript2', thePlaceholder, thePlayerId, theFile, theImage);
		}else{
			loadVelocix('http://flash.velocix.com/'+ velocixSplit[2] +'/'+ velocixSplit[3] +'?format=jscript2', thePlaceholder, thePlayerId, theFile, theImage);
		}
	}else{
		//wait is this an RTMP url?
		if(theFile.indexOf("rtmp://") >= 0){
			var s = theFile;
			var parts = s.split("/");
			streamFile = parts[parts.length-1];
			rtmpUrl[0] =  parts[parts.length-2];
			scriptLoaded(thePlaceholder, thePlayerId, theFile, theImage);
		}else{
			//no need to call velocix.
			scriptLoaded(thePlaceholder, thePlayerId, theFile, theImage);
		}
	}

}

function loadVelocix(sScriptSrc,thePlaceholder, thePlayerId, theFile, theImage)    
{   
	//we need to call velocix to find out our nearest streaming server.
	jQuery.getScript(sScriptSrc, function(){
		scriptLoaded(thePlaceholder, thePlayerId, theFile, theImage);
	});
}  


function scriptLoaded(thePlaceholder, thePlayerId, theFile, theImage)    
{
	
	var streamFile = "";
	var streamURL = "";

	if (typeof(rtmpUrl) != "undefined" && streamName != "") {
		streamFile = streamName;
		streamURL = rtmpUrl[0];
		//we need to tidy this away so we can start fresh for the next video. (otherwise rtmpUrl[0] == true)
		rtmpUrl = null;
		streamName = "";	
	}else{
		streamFile = theFile;
	}

	// Finally lets go and create the player.
	doCreatePlayer(thePlaceholder, thePlayerId, theFile, theImage, streamFile, streamURL);
}



