/*
** WSMP WebSiteMediaPlayer v1.x: Layer Media Player
**
*/

// Center PopUP Layer
var NS = (navigator.appName=="Netscape")?true:false;
var dtype = 'video';

function WSMP_Init() {
	document.write('<div id="WSMP_LayerPopUp" class="wsmp_layerpopup" style="display:none; position:absolute; padding:5px; border:1px solid #000000; background-color:#CCCCCC; z-index:1002; text-align:right;">');
	document.write('<a href="javascript:void(0)" onclick="WSMP_Close()"><img src="/wscommon/wsmp/close.gif" width="16" heigth="16" border="0" alt="Fermer - Close" title="Fermer - Close"></a><br><img src="/wscommon/wsmp/pix.gif" width="5" heigth="5" border="0"><br>');
	document.write('<div id="WebSiteMediaPlayer"></div>');
	document.write('</div>');
	document.write('<div id="WSMP_LayerFade" style="display:none; position:absolute; top:0; left:0; width:100%; height:100%; background-color:black; -moz-opacity:0.5; opacity:.50; filter:alpha(opacity=50); z-index:1001;"></div>');
	//window.onresize = WSMP_LayerCenter();
}

//function initPopUP() {
// window.onresize = WSMP_LayerCenter(); 
// moveLayer();
//}

function WSMP_LayerCenter(width, height) {
	if ((width==undefined)  || (width==''))  { width=320;  }
	if ((height==undefined) || (height=='')) { height=240; }
	height -= -21;
	var winw;		
	var winh;
	if (document.body.clientWidth>800){
		winw = (document.body.clientWidth-width)/2;
	}else{
		winw = 0;
	}
	if (document.body.clientHeight>525){
		winh = (document.body.clientHeight-height)/2;
	}else{
		winh = 15;
	}
	document.getElementById("WSMP_LayerFade").style.width  = document.body.clientWidth+'px';
	document.getElementById("WSMP_LayerFade").style.height = document.body.clientHeight+'px';
	document.getElementById("WSMP_LayerPopUp").style.top = winh+'px';
	document.getElementById("WSMP_LayerPopUp").style.left = winw+'px';
}

//

function WSMP_Open() {
	WSMP_LayerCenter();
	document.getElementById('WSMP_LayerPopUp').style.display='block';
	document.getElementById('WSMP_LayerFade').style.display='block';
	WSMP_Load('WSMP_Open_call');
}

function WSMP_Close() {
	document.getElementById('WSMP_LayerPopUp').style.display='none';
	document.getElementById('WSMP_LayerFade').style.display='none'
	sendEvent('stop'); //Stop loading and playing
}


function WSMP_Load(type, file, width, height) {

	var args = (type == 'WSMP_Open_call') ? WSMP_Open.arguments : WSMP_Load.arguments;
	var tolayerid = 'WebSiteMediaPlayer';
	type  = args[0]; // video|sound|image|html
	file  = args[1];
	width = args[2]; 
	height= args[3];
	var preview_image = '';
	var playlist_display = 0;
	var playlist_height  = 0;
	var ext = file.slice(file.indexOf(".")).toLowerCase();
	if (ext == '.mp3') { type='sound'; }
	if ((ext == '.xml') && (type != 'image')) { playlist_display = 1; }

	for (i = 4; i < args.length; i++) {
		if ( args[i] == 'preview') { preview_image=args[i+1]; }
		if ((args[i] == 'preview') && (args[i+1] == 'logowf')) { preview_image='/wscommon/wsmp/nopreview.gif'; }
		if ( args[i] == 'tolayerid') { tolayerid=args[i+1]; }
		if ( args[i] == 'playlisthidde') { playlist_display=0; }
		if ( args[i] == 'playlistshow') { playlist_display=1; }
	}

	if ((type==undefined) || (type==''))  { type='video'; }
	if (type=='mp3')       { type='sound'; }
	if ((typeof width=='undefined')  || (width=='')) { width=320;  }
	if ((height==undefined) || (height=='')){ height=240; }
	if (type=='sound') { width=300; height=0; }
	height += 20; // bar
	if (playlist_display == 1) { playlist_height = (height/2);  height += playlist_height}

	if ((type=='video') || (type=='sound') || (type=='html')) {
		document.getElementById("WSMP_LayerPopUp").style.width  = width+'px';
		document.getElementById("WSMP_LayerPopUp").style.height = height+'px';
	}

	if ((type == 'video') || (type=='sound')) {
		if ((ext == '.flv') || (ext == '.mp3') || (ext == '.mp4') || (ext == '.xml')) {
			var so = new SWFObject('/wscommon/wsmp/mediaplayer.swf','wsmp',width,height,'7');
			so.addParam("allowfullscreen","true");
			so.addParam('allowscriptaccess','always');
			so.addParam("usekeys","true");
			so.addVariable("enablejs","true");
			//so.addVariable("showeq","true");
			so.addVariable("javascriptid","wsmp")
			so.addVariable("file",file);
			if (preview_image != '') {
				so.addVariable("image", preview_image);
			}
			so.addVariable("autostart","false");
			//if(id != '') { 
			//	so.addVariable("id",id); 
			//} else {
			//	so.addVariable("type","flv");
			//}
			so.addVariable("streamscript","lighttpd"); 
			if (playlist_display == 1) {
				so.addVariable("displayheight",height-playlist_height);
			}
			so.addVariable('linktarget','_blank');
			so.write(tolayerid);

		} else {
			// Window Media Player
			//http://www.mioplanet.com/rsc/embed_mediaplayer.htm
			//http://www.killersites.com/mvnforum/mvnforum/viewthread?thread=3602
			//document.write(
			document.getElementById(tolayerid).innerHTML = 
			'<object width="'+width+'" height="'+height+'" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject">'
			+'<param name="fileName" value="'+file+'">'
			+'<param name="showControls" value="true">'
			+'<param name="autoStart" value="true">'
			+'<param name="animationStart" value="true">'
			+'<param name="showStatusBar" value="true">'
			+'<embed type="application/x-mplayer2" src="'+file+'" name="MediaPlayer" width="'+width+'" height="'+height+'"></embed>'
			+'</object>';
		}
	}
	if ((type == 'image') || (type == 'images')) {
		var extImgArray = new Array(".jpg", ".png", ".gif");
		var ext = file.slice(file.indexOf(".")).toLowerCase();
		for (var i = 0; i < extImgArray.length; i++) {
	    		if (extImgArray[i] == ext) { type = 'imageonly'; }
		}
		if (type == 'imageonly') {
			document.getElementById("WebSiteMediaPlayer").innerHTML = '<img src="" id="WSMP_img">';
			document.getElementById("WSMP_img").src=file;
			document.getElementById("WSMP_img").width=width;
			document.getElementById("WSMP_img").height=height;
			function resizeafterloading(){
				var w = document.getElementById("WSMP_img").width;
				var h = document.getElementById("WSMP_img").height;
				document.getElementById("WSMP_LayerPopUp").style.width  = w;
				document.getElementById("WSMP_LayerPopUp").style.height = h+21;
				WSMP_LayerCenter(w, h);
			}
			if(NS) {
				document.getElementById("WSMP_img").onload = resizeafterloading();
			} else {
				document.getElementById("WSMP_img").onLoad = resizeafterloading();
			}
		} else {
			var so = new SWFObject('/wscommon/wsmp/imagerotator.swf','wsmp',width,height,'7');
			so.addParam("allowfullscreen","true");
			so.addParam("allowscriptaccess","always");
			so.addVariable('file',file);
			so.addVariable('shownavigation','true');
			so.addVariable('transition','random');
			so.addVariable('linktarget','_blank');
			so.addVariable('showicons','true');
			so.write(tolayerid);
			WSMP_LayerCenter(width, height);
		}
	}
	if (type == 'html') {
		WSMP_Jah(file, 'WebSiteMediaPlayer');
	}

};

/**
 * W Flash Media Player internal cal function
 */
// some variables to save
var currentPosition;
var currentVolume;
var currentItem;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { thisMovie("wsmp").sendEvent(typ,prm); };
function getUpdate(typ,pr1,pr2,pid) {
	if (typ == "time")       { currentPosition = pr1; }
	else if(typ == "volume") { currentVolume = pr1; }
	else if(typ == "item")   { currentItem = pr1; }
	var id = document.getElementById(typ);
	id.innerHTML = typ+ ": "+Math.round(pr1);
	pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
	if(pid != "null") {
		document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
	}
};

// These functions are caught by the feeder object of the player.
function loadFile(obj) { thisMovie("wsmp").loadFile(obj); };
function addItem(obj,idx) { thisMovie("wsmp").addItem(obj,idx); }
function removeItem(idx) { thisMovie("wsmp").removeItem(idx); }
function getItemData(idx) { };

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};


/**
 * Ajax function
 */
function WSMP_Jah(url,target) {
	// native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = function() { WSMP_JahDone(target); };
		req.open("GET", url, true);
		req.send(null);
		// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = function() { WSMP_JahDone(target); };
			req.open("GET", url, true);
			req.send();
		}
	}
}    

function WSMP_JahDone(target) {
	// only if req is "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			results = req.responseText;
			document.getElementById(target).innerHTML = results;
	        } else {
			document.getElementById(target).innerHTML="jah error:\n" +
			req.statusText;
		}
	}
}


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

// End SWFObject v1.5:

WSMP_Init();

