/*
---::: 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("|");
		
		esrtmp=2;
		
		//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 salida;
			
			esrtmp = 1;
			
			salida = s.split("/");
			rtmpUrl = salida[0]+"/"+salida[1]+"/"+salida[2]+"/"+salida[3]+"/";
			
			streamFile = salida[4];
			streamName = salida[4];
			
			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 != "") {
	if ((esrtmp==1) && streamName != "") {
		streamFile = streamName;
		streamURL = rtmpUrl;
		
		//we need to tidy this away so we can start fresh for the next video. (otherwise rtmpUrl[0] == true)
		rtmpUrl = null;
		streamName = "";
	}
	else if ((esrtmp==2) && 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);
}

