var swf = "fpObj";
var currentPlayerWidth=fpSize_w.m;
var currentPlayerHeight=fpSize_h.m;
var currentScreenWidth=fpSize_w.m;
var currentScreenHeight=fpSize_h.m-20;
var allowJavaScript = "true";
var allowFullScreen = "true";
var showNavigation = "true";
var showControlbarPosition = "buttom";
var autoStart=true;
var sourceURL;


var playerstatus;


/*Start : define for streaming*/
var stream_type;
var scope;
var content_group;
var current_guid;
var current_bitrate;
var trueworld_token;
var referer;
var channel;
var ext;
var clientip;
var jwplayer;
var file; //mp3 = 1 ,mp4 = 2 ,3gp =3 ,flv = 4
var needinfo;
var guidtype;

/*End : define for streaming*/


function removeTrailingSpaces(arg) {
	while(''+arg.charAt(arg.length-1)==' ') { arg=arg.substring(0,arg.length-1); }
	return(arg);
}

function prepareFlashPlayer(){
	
		sourceURL = stream_url.replace("~streamtype~", stream_type).replace("~scope~", scope).replace("~contentgroup~", content_group).replace("~guid~", current_guid).replace("~bitrate~", current_bitrate).replace("~trueworldtoken~", trueworld_token).replace("~referer~", referer).replace("~channel~", channel).replace("~ext~", ext).replace("~clientip~", clientip).replace("~jwplayer~", jwplayer).replace("~file~", file).replace("~needinfo~", needinfo);
		if(guidtype=="songguid"){
			sourceURL = sourceURL.replace("streamguid", "songguid");
		}
		sourceURL = removeTrailingSpaces(sourceURL);
		log("\n\n----Prepare Player----\n");
		log("sourceURL:["+sourceURL+"]\n\n");
		
	
}

function writeFlashPlayer()
{
	
		log("\n\n----Write Player----\n");
		log("swf:["+swf+"]\n");
		log("ext:["+ext+"]\n");
		log("currentPlayerWidth:["+currentPlayerWidth+"]\n");
		log("currentPlayerHeight:["+currentPlayerHeight+"]\n");
		log("currentScreenWidth:["+currentScreenWidth+"]\n");
		log("currentScreenHeight:["+currentScreenHeight+"]\n");
		log("allowFullScreen:["+allowFullScreen+"]\n");
		log("showNavigation:["+showNavigation+"]\n");
		log("allowJavaScript:["+allowJavaScript+"]\n");
		log("allowFullScreen:["+allowFullScreen+"]\n");
		log("autoStart:["+autoStart+"]\n");
		log("showControlbarPosition:["+showControlbarPosition+"]\n");
		log("needinfo:["+needinfo+"]\n");
		log("sourceURL:["+sourceURL+"]\n\n\n");
		

		
		var so = new SWFObject('flash/mediaplayer3_16.swf',swf,currentPlayerWidth,currentPlayerHeight,'9');
		so.addParam("allowscriptaccess", "always");
		so.addParam('allowfullscreen',allowFullScreen);
		so.addParam('shownavigation',showNavigation);  
		so.addVariable('javascriptid',swf);
		so.addVariable('enablejs',allowJavaScript);
		so.addVariable('usefullscreen',allowFullScreen);
		so.addVariable('width',currentPlayerWidth);
		so.addVariable('height',currentPlayerHeight); 
		so.addVariable('displaywidth',currentScreenWidth);
		so.addVariable('displayheight',currentScreenHeight);
		so.addVariable('autostart',autoStart);
		so.addVariable('file',sourceURL);
		//so.addParam("wmode","transparent");  // ใส่แล้ว FF play ไม่ได้
		so.addVariable('controlbar',showControlbarPosition);
		so.write('showFlashPlayer');
		log(document.getElementById("showFlashPlayer").innerHTML);
	
}

function f_replay(){
	f_play(swf);
	
}

function f_play(swf)
{
    if (playerstatus != 2)
    {
		log("play");
        sendEvent(swf,'playpause','');
		getid(t_playstatus).innerHTML = "Playing...";
		
    }
}

function f_pause(swf)
{
	
    if (playerstatus == 2)
    {
		user_click = "1";
        sendEvent(swf,'playpause','');
		getid(t_playstatus).innerHTML = "Paused";
		
    }

}

function f_stop(swf)
{
    //if (playerstatus == 2)
    //{
		user_click = "1";
        sendEvent(swf,'stop','');
		getid(t_playstatus).innerHTML = "Stop";
   // }
}

function f_playnext(swf)
{
        sendEvent(swf,'next','');
}

function sendEvent(swf,typ,prm) { 
	getid(swf).sendEvent(typ,prm); 
}

function loadInformation(JONMessage)
{
    myMessage=eval('(' + JONMessage + ')');
}
