/** FLEX **/
var src = "/player/flex/PolymediaShow";
var id = "box-player";
var width = "693";
var height = "324";

var urlPage = document.location.href;
var xmlconfig = '';
var playlist= urlPage.indexOf("$p=") > 0 ? (new RegExp("\\$p=([A-Za-z0-9\_\-]+)($|&|\\$)").exec(urlPage)[1]): '';	
if(urlPage.indexOf("/video/popout/")>0 && (playlist.indexOf("playlist")==0 || playlist.indexOf("myplaylist")==0)){
	xmlconfig = "/player/flex/playerFlexPopoutConfigPlaylist.xml";
}	
else if(playlist.indexOf("playlist")==0 || playlist.indexOf("myplaylist")==0){
	xmlconfig = "/player/flex/playerFlexConfigPlaylist.xml";
}	
else if (urlPage.indexOf("/video/popout/")>0 && $j.cookie("PlayerAutoSwitch") != 'false'){
	xmlconfig = "/player/flex/playerFlexPopoutConfigAutoplay.xml";
}	
else if (urlPage.indexOf("/video/popout/")>0){
	xmlconfig = "/player/flex/playerFlexPopoutConfig.xml";
}	
else if ($j.cookie("PlayerAutoSwitch") != 'false'){
	xmlconfig = "/player/flex/playerFlexConfigAutoplay.xml";
}
else{
	xmlconfig = "/player/flex/playerFlexConfig.xml";
}	
	
//var xmlconfig = (urlPage.indexOf("/popout")>0) ? "/test/player/flex/playerFlexPopoutConfig.xml" : "/test/player/flex/playerFlexConfig.xml";
var flashvars = "configUrl=local://page/GetFXConfig&playlist=local://page/GetPlaylist&sequenceUri=local://page/GetAdvSequence&idE=PolymediaShow&us=mediavideo";

//xml di configurazione flex
var fxConfig  = null;

function GetFXConfig() {
	//alert("getConfig: " + fxConfig);
	return fxConfig;
}

function CreateFXPlayer() {
	if (videotime!='00:00:00.000'){
			flashvars += '&startpos=' + videotime;
	}
	
	
	if($j.cookie("PlayerAutoSwitch")==null || $j.cookie("PlayerAutoSwitch")== 'true'){
			flashvars += '&autoplay=true';
	}
	else{
			flashvars += '&autoplay=false';	
	}
		
	if($j.cookie("PlayerMute")==null || $j.cookie("PlayerMute")== 'false'){
			flashvars += '&isMuteParam=false';
	}
	else{
			flashvars += '&isMuteParam=true';	
	}
	
	$j.ajax({
		type: "GET",
		url: xmlconfig,
		dataType: "text",
		success: function(data) {
			fxConfig = data;
			CreateFXPlayerObject();
		}
	});
	

}

function CreateFXPlayerObject() {
    
	if (typeof(playerSessionUUID)!="undefined") {
		flashvars += "&usession=" + playerSessionUUID;
	}
	document.getElementById(id).innerHTML = AC_FL_RunContent(
			"src", src,
			"flashVars", flashvars,
			"allowFullScreen", "true",
			"width", width,
			"height", height,
			"align", "middle",
			"wmode", "opaque",
			"id", "PolymediaShow",
			"quality", "high",
			"bgcolor", "#869ca7",
			"name", "PolymediaShow",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
}

function GetFlashPlayer() {
	var hasProductInstall = DetectFlashVer(6, 0, 65);

	if ( hasProductInstall ) {
		// MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
		// This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
		// DO NOT MODIFY THE FOLLOWING FOUR LINES
		// Location visited after installation is complete if installation is required
		var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
		var MMredirectURL = encodeURI(window.location);
		document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		var MMdoctitle = document.title;

		document.getElementById(id).innerHTML = AC_FL_RunContent(
			"src", "/player/flex/playerProductInstall",
			"flashVars", "MMredirectURL="+MMredirectURL+"&MMplayerType="+MMPlayerType+"&MMdoctitle="+MMdoctitle+"",
			"width", width,
			"height", height,
			"align", "middle",
			"wmode", "opaque",
			"id", "PolymediaShow",
			"quality", "high",
			"bgcolor", "#869ca7",
			"name", "PolymediaShow",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
		);
	} else {
		var alternateContent = 'This content requires the Adobe Flash Player. '
		+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
		document.getElementById(id).innerHTML.write(alternateContent);  // insert non-flash content
	}
}
