/**
 * @fileoverview the following file contains function which allow to manage the flash player
 * and browser object
 */


/**
 * @class This class allow to stores information
 * @param {int} memberId comweb member identifier which is the owner of media displaying in the flash browser
 * @param {int} CW_Action_Media_Type (CW_Action_Media.Media_TYPE_[VIDEO|IMAGE|MUSIC]) media type identifier of medias which are displayed in the flash browser
 * @param {String} divId HtmlDivElement identifier (id attribute)
 * @param {int} page current xml content page of the flash browser
 * @param {int} nbElement number of element which are displayed in a page
 * @constructor
 */
function  browserMemberMediaParam(memberId,CW_Action_Media_Type,divId,page,nbElement){
	this.memberId = memberId;
	this.CW_Action_Media_Type = CW_Action_Media_Type;
	this.divId = divId;
	this.page = page ;
	this.nbElement = nbElement;
}

/**
 * @class This static class allow to define the flash player and browser behaviors
 *  <ul>
 * 		<li>define the client side behavior when a media (video, photo, music) is selected</li>
 * 		<li>define the client behavior when user click on the standalone button <img src="img/flash/button_standalone.JPG"/> (javascript called method is "standAlone")</li>
 * 	</ul>
 * To access to the satic method use: <b>PlayerFlash.method(...)</b>
 * @constructor
 */
function PlayerFlash(){}


PlayerFlash.prototype ={
	//stores th sw player and browser cache value
	/**
	 * stores the embed player and browser flash cache value
	 * <br/> this values must be redefine when the user have a new page with browser and player, because it's allow to etablished between the flash objects
	 * <br/> the "setBrowserAndPlayer" insert the browser and the player in the client page, and so must redefine the cache value
	 * @type int
	 */
	currentCacheSwfObject:0,
	/**
	 * stores the flash player object in order to can execute flash method on it, flash player methods are:
	 * <ul>
	 *		<li>flashPlayMediaNum (mediaID,nodeNum,browserId)</li>
	 * 		<li>flashChangeSize(pSize)</li>
	 * 		<li></li>
	 * </ul>
	 * @type object
	 */
    flash_player: null,
    /**
	 * stores the flash browser object in order to can execute flash method on it, flash browser methods are:
	 * <ul>
	 *		<li>flashHighLightMedia(mediaID, nodeNum)</li>
	 * </ul>
	 * @type object
	 */
	 flash_browser: null,
	 /**
	  * stores the standalone popup
	  * opened when the user click on the standalone button of the flash player (first menu button) <img src="img/flash/button_standalone.JPG"/>
	  * close when the user close the window or when the user want to open an other  standalone popup
	  * @type Window
	  *
	  */
	standalonePopup:null,
	/**
	 * Stores the current comweb media identifier which is playing
	 * <br/> this identifier must be valued when the flash player play a new media so when the flashPlayMediaNum (mediaID,nodeNum,browserId) method is called
	 * @see #flashPlayMediaNum
	 * @type int
	 */
	 flashMediaId: 0,
	/**
	 * Stores the current xml node number which is corresponding to the playing media (media values come from xml playlist)
	 * <br/> this number must be valued when the flash player play a new media so when the flashPlayMediaNum (mediaID,nodeNum,browserId) method is called
	 * @see #flashPlayMediaNum
	 * @type int
	 */
	 flashMediaNode: 0,
	 /**
	  *Stores the current media type identifier which is playing (CW_Action_Media.Media_TYPE_[VIDEO|IMAGE|MUSIC]),
	  * <br/> this identifier must be valued when a new media information is displayed, so when the flashPlayMediaDisplay(comwebBean,requestResume) is called,
	  * <br/> as we know the comwebBean parameter is a ComwebBean_media object so in order to retrieve the media type identifier do ComwebBean_media.getMediaType()
	  * @see ComwebBean_media#getMediaType
	  * @type int
	  */
	 flashMediaTypeId:0,
	 /**
	  *Stores the xmlplaylist servlet parameters which have provides the xml media content
	  * <br/> this values is stored becaus we need it when the user called the standalone popup,
	  * we must build the initial request which deliver the actual content and just change the page if the actual page is changed
	  * <br/> the initial xml request content is builded in setBrowser method
	  * @type String
	  */
	 flashlistingParamValues: "",

	/**
	 * Stores relatives information of flash browser which is on a member page, must always be null
	 * except if the user is on a member page so if the setBrowserMemberMedia method is called
	 * @type browserMemberMediaParam
	 */
	 browserMemberMediaParamStore:null,
	/**
	 * Stores standalone window parameters
	 * @type String
	 */
	 standaloneWindowParam : "toolbar=no,status=no,resizable=no,scrollbars=0,width=400,height=430,fullscreen=no,menubar=no,resize=no,status=no",

	comwebBeanMedia:null,

	isPlaylistBrowser : false,

	comeFromPermanentLink : false,

	 /**
	 * This function is called by flash objects (via actionscript) when those objects want to play a new media (video,music,image)
	 * So can be called by the flash browser object when the user click on a media
	 * <br/> And allow to display playing media information, or if we are not in a player page, for example when the user click on flash browser member page which have no player,
	 * in this example this function redirect the user on the player page which will illustarte the member media
	 * @param {int} mediaID comweb media identifier of the current played media, provides by the xml playlist content with the "id" attribute of the "media" node
	 * @param {int} nodeNum current xml node number which is corresponding to the playing media (media values come from xml playlist)
	 * @see #flashPlayLoadMediaDisplay
	 * @return {void}
	 */
	flashPlayMedia:function (mediaID, nodeNum){
		if (this.flash_player == null){
			if (this.isPlaylistBrowser){
				var fonc = "goToMediaPlay('"+this.flashlistingParamValues+"',"+mediaID+");";
				window.setTimeout(fonc, 1000);
			}else if (this.browserMemberMediaParamStore!=null){
				//the browserMemberMediaParamStore is not null,the setBrowserMemberMedia was called,
				//so we are in a member page wich displayed only the flash browser which contain the member media
				//and the user click on a media
				//Also we must redirect this user on the player page which displayed the member media
				//in order to realise this we must buil the correct request and launch the player page with goToMediaPlay function
				var nbElement = this.browserMemberMediaParamStore.nbElement;
				var page = 1;
				nodeNum = nodeNum +1 ;
				if ((nodeNum%nbElement)==0){
					page = parseInt(nodeNum/nbElement);
				}else{
					page = parseInt(nodeNum/nbElement) + 1;
				}
				CW_logger.log(CW_logger.LEVEL_INFORMATION,"playerFlash: browserMemberMediaParamStore:  mediaID:" + mediaID + " page:" + page + " mediaType:" + this.browserMemberMediaParamStore.CW_Action_Media_Type );

				var mediaTypeId= CW_Action_Media.Media_TYPE_VIDEO;
				if (document.getElementById("browser_member_photo").style.display == "block"){
					mediaTypeId= CW_Action_Media.Media_TYPE_IMAGE;
				}else if (document.getElementById("browser_member_music").style.display == "block"){
					mediaTypeId= CW_Action_Media.Media_TYPE_MUSIC;
				}
				var listingParams = "listing.page="+page+"&listing.nbre.elements="+nbElement+"&media.type="+mediaTypeId+"&user.uid="+this.browserMemberMediaParamStore.memberId+"&site.uid=" +CW_config.serviceId;
				//var fonc = "document.getElementById('browser').innerHTML = '';"
				var fonc = "goToMediaPlay('"+listingParams+"',"+mediaID+");";
				this.browserMemberMediaParamStore = null;
				window.setTimeout(fonc, 1000);
			}
		}else{

			this.flashPlayLoadMediaDisplay(mediaID,nodeNum);
			//indicates to the flash player that it must play the given media
			this.flash_player.flashPlayMediaNum (mediaID, nodeNum);
		}
	},
	/**
	 * This function must be called when a new media is playing
	 * <br/> And allow to :
	 * <ul>
	 * 		<li> given values for "flashMediaId" and "flashMediaNode" class attributes</li>
	 * 		<li> clear the current media information before to set the new one </li>
	 * 		<li> launch the ajax request width  flashPlayMediaDisplay in order to display the new media information</li>
	 * </ul>
	 * @param {int} mediaID comweb media identifier of the current played media, provides by the xml playlist content with the "id" attribute of the "media" node
	 * @param {int} nodeNum current xml node number which is corresponding to the playing media (media values come from xml playlist)
	 * @see #flashPlayClearMediaDisplay
	 * @see #flashPlayMediaDisplay
	 * @return {void}
	 */
	flashPlayLoadMediaDisplay:function(mediaID,nodeNum){
		if (mediaID != this.flashMediaId){
			this.flashMediaId = mediaID;
		 	this.flashMediaNode = nodeNum;
			this.flashPlayClearMediaDisplay();
			CW_Action_Stat.incrementMediaVisualisation("PlayerFlash.flashPlayMediaDisplay",mediaID);
		}
	},
	/**
	 * This function allow to clear the current media information
	 * @return {void}
	 */
	flashPlayClearMediaDisplay:function(){
		document.getElementById("mediaTitleContainer").innerHTML = "";
		document.getElementById("mediaPlayerVoteContainer").innerHTML = "";
		document.getElementById("mediaPlayActionsContainer").innerHTML = "";
		document.getElementById("mediaPlayInfosContainer").innerHTML = "";
		document.getElementById("mediaPlayUserContainer").innerHTML = "";
		document.getElementById("mediaPlayBlogContainer").innerHTML = "";
		document.getElementById("tagMediaContainer").innerHTML = "";
		document.getElementById("commentsListingContainer").innerHTML = "";
	},
	/**
	 * This function allow to display current media information (title, description, tags ...),
	 * and call flashPlayMediaDisplayEvent with comwebBeanMedia , you can override this method in order
	 * to refresh some htmlelement in the html document
	 * @return {void}
	 */
	flashPlayMediaDisplay:function(comwebBean,requestResume){
		var comwebBeanMedia = comwebBean.getSpecificChildren("media")[0];
		try{
			if (this.comeFromPermanentLink){
				if (!comwebBeanMedia.isPublic()){
					if ( parseInt(comwebBeanMedia.getValues("visibilty")) != 2){
						loadMainPage();
						return;
					}
				}
				this.comeFromPermanentLink = false;
			}

			this.flashMediaTypeId = comwebBeanMedia.getMediaType();
			this.comwebBeanMedia = comwebBeanMedia;
			var categoryId = comwebBeanMedia.getCategoryId();
			loadBrick_media_mediaPlay_title(comwebBeanMedia,"mediaTitleContainer");
			loadBrick_media_mediaPlay_vote(comwebBeanMedia,"mediaPlayerVoteContainer");
			loadBrick_media_mediaPlay_actions(comwebBeanMedia,"mediaPlayActionsContainer");
			//var hashtable = new HashTable();
			//hashtable.put("description",comwebBeanMedia.getDescription());
			//CW_Action_Site.displaySingleCategory("displayMediaPlayerCategoryCallback",categoryId,hashtable);
			loadBrick_media_mediaPlay_infos2(categoryId,"mediaPlayInfosContainer",comwebBeanMedia.getDescription(),this.flashMediaTypeId );

			callBrick_user_userElement("mediaPlayUserContainer",comwebBeanMedia.getOwnerUserUid(),comwebBeanMedia.getCreationDate());
			loadBrick_media_mediaPlay_blog(comwebBeanMedia,"mediaPlayBlogContainer");
			loadBrick_media_mediaPlay_commentsListing(comwebBeanMedia,"commentsListingContainer");
			loadBrick_media_mediaPlay_tags(comwebBeanMedia,"tagMediaContainer");
		}catch(e){
			CW_logger.log(CW_logger.LEVEL_ERROR,"flashPlayMediaDisplay :" + e );
		}
		this.flashPlayMediaDisplayEvent(comwebBeanMedia,requestResume);
	},
	/**
	 *
	 */
	flashPlayMediaDisplayEvent:function(comwebBeanMedia,requestResume){

	},


	/**
	 * This function is called by flash browser object when it want to highlight a preview media for the first time, the browser automatically inform
	 * the player to play this media but don't execute the flashPlayMedia method.
	 * So we must load the media infomation and indicates to the browser that it can highlight this preview
	 * @param {int} mediaID comweb media identifier of the current played media, provides by the xml playlist content with the "id" attribute of the "media" node
	 * @param {int} nodeNum current xml node number which is corresponding to the playing media (media values come from xml playlist)
	 * @return {void}
	 */
	flashHighLightMedia:function(mediaID, nodeNum){
		this.flashPlayLoadMediaDisplay(mediaID,nodeNum);
		this.flash_browser.flashHighLightMedia(mediaID, nodeNum);
	},
	/**
	 * Allow to set the flash_player class attribute from the given identifier
	 * @return {void}
	 */
	 setFlashPlayerObject:function(swfID) {
	   if (this.flash_player == null){
	   	   if (navigator.appName.indexOf("Microsoft") > -1) {
		      this.flash_player = window[swfID];
		   } else {
		      this.flash_player = document[swfID];
		   }
	   }
	},
	/**
	 * Allow to set the flash_browser class attribute from the given identifier
	 * @return {void}
	 */
	setFlashBrowserObject:function(swfID) {
		if (this.flash_browser == null){
		   if (navigator.appName.indexOf("Microsoft") > -1) {
		      this.flash_browser = window[swfID];
		   } else {
		      this.flash_browser = document[swfID];
		   }
		}
	},

	/**
	 * @param {String} listingParamValues parameters which must be given to the xmlplaylist servlet in order to retrieve the wanted media listing (ex: "listing.page=1&action=media.all&listing.nbre.elements=15&listing.order=0&listing.since=0&media.type=1"), note that "listing.page" parameter is required in order that flash objects can know what is the actual page, and so can called the nex or previous page
	 * @param {boolean} isStandalone indicates if the builded flash player is in the standalone mode
	 * @param {boolean} isFullScreen indicates if the builded flash player is in the fullscreen mode
	 * @param {int} mediaId indicates the comweb media identifier of the wanted listing which must be played at first
	 */
	setBrowserAndPlayer:function(listingParamValues,isStandalone,isFullScreen,mediaId){
		this.currentCacheSwfObject = (new Date()).getTime();
		if (isStandalone!=true){isStandalone = false;}
		if (isFullScreen!=true){isFullScreen = false;}
		var mediatype = CW_Action_Media.Media_TYPE_VIDEO;
		try{
			var regexp = new RegExp("media.type=[0-9]+","g");
			var mediatype = regexp.exec(new String (listingParamValues));
			mediatype = (new String(mediatype)).substring(11);
		}catch(e){}

		this.setPlayer(this.currentCacheSwfObject,isStandalone,isFullScreen,"moviePlayer","player",mediatype);
		this.setBrowser(this.currentCacheSwfObject,listingParamValues,mediaId,isStandalone,"listbrowser","browser");
		this.browserMemberMediaParamStore = null;

	},

	/**
	 * The following function allow to write the embed flash code using swfobject, in this function the most important
	 * behavior is to configure flash player, the flash player is builded by swfobject like this:
	 * <br/> var so = new SWFObject(swf file path, ID of your object, width, height, Required player version for your Flash content [8 for our case], Hex value of the background color );
	 * <br/> then we must configure it with flash variables  (so.addVariable("variableName", "variableValue");), flash player variables are  :
	 * <ul TYPE="disc" style="font-size: 10pt;">
	 *		<li><u>so.addVariable("autoPlay", "[true|false]");</u>:indicates if the first media of the xml playlist content must be directly played </li>
	 * 		<li><u>so.addVariable("modeContinu", "[true|false]");</u>:true: continuous mod is activate, the flash player play all media in countinous; false: the continuous mod is desactivate the flash player play the current media and stop after</li>
	 * 		<li>
	 * 			<table width="100%">
	 * 				<tr>
	 * 					<td style="width: 103px;height: 103px;"><img src="img/flash/button_sizeNormal.JPG"/></td>
	 * 					<td>
	 * 				  		<ul TYPE="disc">
	 * 							<li><u>so.addVariable("normalVideoSizeX", "400");</u>:width of the played media when "Normal size" is selected, warning this width determine the flash player width</li>
	 *							<li><u>so.addVariable("normalVideoSizeY", "300");</u>:height of the played media when "Normal size" is selected, warning this width determine the flash player height</li>
	 * 				 		</ul>
	 * 					</td>
	 * 			</table>
	 * 		</li>
	 * 		<li>
	 * 			<table width="100%">
	 * 				<tr>
	 * 					<td style="width: 103px;height: 103px;"><img src="img/flash/button_sizeSmall.JPG"/></td>
	 * 					<td>
	 * 				  		<ul TYPE="disc">
	 * 				  			<li><u>so.addVariable("miniVideoSizeX", "200");</u>:width of the played media when "Small size" is selected</li>
	 * 				 			<li><u>so.addVariable("miniVideoSizeY", "150");</u>:height of the played media when "Small size" is selected</li>
	 * 				 		</ul>
	 * 					</td>
	 * 			</table>
	 * 		</li>
	 * 		<li><u>so.addVariable("FSVideoSizeX", "400");</u>:width of the input video file
	 *		<li><u>so.addVariable("FSVideoSizeY", "300");</u>:height of the input video file
	 * 		<li><u>so.addVariable("displaySoundBtn", "[true|false]");</u>:indicates if the sound button <img src="img/flash/button_sound.JPG"/>  is displayed or not
	 *		<li><u>so.addVariable("initialSoundLevel", "[nb from 0 to 100]");</u>:values of the level sound in percentage, warning when you change this value you must delete the flash cache (right click on flash object -> Parameters -> set cache size at 0 -> OK )
	 * 		<li>
	 * 			<table width="100%" style="font-size: 10pt;">
	 * 				<tr>
	 * 					<td width="152">
	 * 						<p>In order to have the following result set equalizer variables</p>
	 * 						<img src="img/flash/equalizer.jpg"/>
	 * 					</td>
	 * 					<td>
	 * 				  		<ul TYPE="disc">
	 * 							<li><u>so.addVariable("equalizerNumCols", "8");</u>:number of columns (maximum 8)</li>
	 * 							<li><u>so.addVariable ("equalizerNumPerCol", "20");</u>:number of levels in a column</li>
	 * 							<li><u>so.addVariable("equalizerSpace", "2");</u>:space between colums</li>
	 * 							<li><u>so.addVariable("equalizerColor0", "0xFF0000");</u>:initial color for column 0</li>
	 * 							<li><u>so.addVariable("equalizerColor1", "0xFF0000");</u>:initial color for column 1</li>
	 * 							<li><u>so.addVariable("equalizerColor2", "0xFF0000");</u>:initial color for column 2</li>
	 * 							<li><u>so.addVariable("equalizerColor3", "0xFF0000");</u>:initial color for column 3</li>
	 * 							<li><u>so.addVariable("equalizerColor4", "0xFF0000");</u>:initial color for column 4</li>
	 * 							<li><u>so.addVariable("equalizerColor5", "0xFF0000");</u>:initial color for column 5</li>
	 * 							<li><u>so.addVariable("equalizerColor6", "0xFF0000");</u>:initial color for column 6</li>
	 * 							<li><u>so.addVariable("equalizerColor7", "0xFF0000");</u>:initial color for column 7</li>
	 * 				 		</ul>
	 * 					</td>
	 * 				</tr>
	 * 			</table>
	 * 		</li>
	 *		<li><u>so.addVariable("isFullScreenPlayer","[true|false]");</u>:indicates id the current flash player is a fullscreen player
	 *		<li><u>so.addVariable("isStandAlonePlayer","[true|false]");</u>:indicates id the current flash player is a standalone player
	 *		<li><u>so.addVariable("useBrowser","[true|false]");</u>:indicates if the flash player is associated with a flash browser, set it at false only for fullscreen mod because xml content come from the player which ask this mod and not from the flash browser
	 *		<li><u>so.addVariable("baseLC", "sa" + currentCache);</u>:value of the communication between the player and the browser
	 * 		<li>
	 * 			<table width="100%">
	 * 				<tr>
	 * 					<td style="width: 103px;height: 103px;"><img src="img/flash/button_sizeNormal.JPG"/></td>
	 * 					<td>
	 * 				  		<ul TYPE="disc">
	 * 							<li><u>so.addVariable("mmc", "label text value");</u>:label text of continuous mod</li>
	 *							<li><u>so.addVariable("mpt", "label text value");</u>:label text of "Small size" mod</li>
	 *							<li><u>so.addVariable("mtn", "label text value");</u>:label text of "Normal size" mod</li>
	 * 				 		</ul>
	 * 					</td>
	 * 			</table>
	 * 		</li>
	 *		<li><u>so.addVariable("showVersion", "[true|false]");</u>:indicates if the flash player version must be displayed in the main which is appear with a right click on flash object
	 *		<li><u>so.addVariable("fullScreenUrl", "fullScreen.html");</u>:file which is called in a new popup when user click on fullscreen button <img src="img/flash/button_fullscreen.JPG"/>
	 *		<li><u>so.addVariable ("homeURL", CW_config.webappUri);</u>:url which is called with a standalone player and when the user click on the service logo <img src="img/flash/button_homeUrlStandalone.JPG"/>
	 * </ul>
	 * finally we must write the player in the correct div with the following code: so.write(playerDivId);
	 * <br/>
	 * <br/>More information on swfobject: <a href="http://www.adobe.com/devnet/flash/articles/swfobject.html">JavaScript Flash Player Detection and Embedding with SWFObject</a> (click on "How SWFObject Works" in left table of contents)
	 *
	 * @param {String} currentCache value of the current cache, si value allow to set the communication chanel name between the player and browser (they must have the same value)
	 * @param {boolean} isStandalone indicates if the player is in standalone mod
	 * @param {boolean} isFullScreen indicates if the player is in fullscreen mod
	 * @param {String} playerName the id attribute of your flash object. the attribute name will also take this value because it is the attribute which benefits from the swliveconnect
	 * @param {String} playerDivId htmlDivElement identifier (id) wich determine the div where the player must be writted
	 * @param {int} mediaType (values are CW_Action_Media.Media_TYPE_[VIDEO|IMAGE|MUSIC]) allow to have a different configuration from the media type
	 * @return {void}
	 */
	 setPlayer:function(currentCache,isStandalone,isFullScreen,playerName,playerDivId,mediaType){
		this.currentCacheSwfObject = currentCache;
		var so;
		if (mediaType == null || mediaType == "" || mediaType == "undefined"){
			mediaType = CW_Action_Media.Media_TYPE_VIDEO;
		}
		if (isFullScreen){
			so = new SWFObject(CW_Action_Player.PlayerPath, playerName, "100%", "100%", "8", "#c0c0c0");
			so.addVariable("normalVideoSizeX", "400"); //width of the played media when "Normal size" is selected, warning this width determine the flash player width
			so.addVariable("normalVideoSizeY", "300"); //height of the played media when "Normal size" is selected, warning this width determine the flash player height

		}else if (isStandalone == true || isStandalone == "true"){
			so = new SWFObject(CW_Action_Player.PlayerPath, playerName, "400", "340", "8", "#c0c0c0");
			so.addVariable("normalVideoSizeX", "400"); //width of the played media when "Normal size" is selected, warning this width determine the flash player width
			so.addVariable("normalVideoSizeY", "300"); //height of the played media when "Normal size" is selected, warning this width determine the flash player height
		}else{
			so = new SWFObject(CW_Action_Player.PlayerPath, playerName, "400", "340", "8", "#c0c0c0");
			so.addVariable("normalVideoSizeX", "400"); //width of the played media when "Normal size" is selected, warning this width determine the flash player width
			so.addVariable("normalVideoSizeY", "300"); //height of the played media when "Normal size" is selected, warning this width determine the flash player height

		}

		so.addParam("menu", "true");
		so.addParam("align", "top");
		so.addParam("allowScriptAccess", "sameDomain");
		so.addParam("scale", "showAll");
		so.addParam("wmode", "opaque");

		so.addVariable("bufferTime", "4");
		so.addVariable("preloadMedia", "4");

		so.addVariable("autoPlay", "true"); //indicates if the first media od the xml playlist content must be directly played
		so.addVariable ("modeContinu", "false"); //true: continuous mos is activate, the flash player play all media in countinous; false: the continuous mod is desactivate the flash player play the current media and stop after

		if (mediaType ==  CW_Action_Media.Media_TYPE_IMAGE){
			so.addVariable ("showWatermarkOnce", "true");
		}

		so.addVariable("miniVideoSizeX", "200"); //width of the played media when "Small size" is selected
		so.addVariable("miniVideoSizeY", "150"); //height of the played media when "Small size" is selected


		so.addVariable("FSVideoSizeX", "400");//width of the video file
		so.addVariable("FSVideoSizeY", "300");//height of the video file

		so.addVariable("displaySoundBtn", "true"); //indicates if the sound button is displayed or not
		so.addVariable("displayShareBtn", "true");
		so.addVariable("displayDetailsBtn", "true");

		so.addVariable("initialSoundLevel", "10"); // values of the level sound in percentage, warning when you change this value you must delete the flash cache (right click on flash object -> Parameters -> set cache size at 0 -> OK )
		so.addVariable("isFullScreenPlayer", isFullScreen); //indicates id the current flash player is a fullscreen player
		so.addVariable("isStandAlonePlayer", isStandalone); //indicates id the current flash player is a standalone player
		so.addVariable("useBrowser", !isFullScreen); //indicates if the flash player is associated with a flash browser, set it at false only for fullscreen mod because xml content come from the player which ask this mod and not from the flash browser
		so.addVariable("baseLC", "sa" + currentCache); //value of the communication between the player and the browser

		/** Equalizer parameter **/
		/*so.addVariable("equalizerColor0", "0xFF0000");
	    so.addVariable("equalizerColor1", "0xFF0000");
	    so.addVariable("equalizerColor2", "0xFF0000");
	    so.addVariable("equalizerColor3", "0xFF0000");
	    so.addVariable("equalizerColor4", "0xFF0000");
	    so.addVariable("equalizerColor5", "0xFF0000");
	    so.addVariable("equalizerColor6", "0xFF0000");
	    so.addVariable("equalizerColor7", "0xFF0000");
	    so.addVariable("equalizerNumCols", "8"); // nombre de colonnes, max 8!
	    so.addVariable ("equalizerNumPerCol", "20"); // nombre de bandes par colonne
	    so.addVariable("equalizerSpace", "2"); // espace entre les colonnes*/


		/** Menu Lang parameter **/
		so.addVariable("mmc", CW_internationalization.getValue("general.player.continue")); //label text of continuous mod
		so.addVariable("mpt", CW_internationalization.getValue("general.player.size.small")); //label text of "Small size" mod
		so.addVariable("mtn", CW_internationalization.getValue("general.player.size.normal")); //label text of "Normal size" mod


		so.addVariable("showVersion", "true"); //indicates if the flash player version mus be displayed in the main which is appear with a right click on flash object
		so.addVariable("fullScreenUrl", "fullScreen.html"); // file which is called in a new popup when user click on fullscreen button


		so.addVariable ("homeURL", CW_config.webappUri); //url which is called with a standalone player and when the user click on the service logo
		//write the swf file in the div which have "player" name
		so.write(playerDivId);
		this.flashMediaId = 0;
		this.browserMemberMediaParamStore = null;
		this.flash_player = null;
		this.setFlashPlayerObject(playerName);
	},
	/**
	 * The following function allow to write the embed flash code using swfobject, before write id and configure it, this method must
	 * build the request which provides the xml content, this request like:
	 * <br/> [servlet path]?[listingParamValues]&flashPage=[page of the flash browser, begin at 0].xml, note that the flash browser page
	 * is processed from the listing.page parameters which is in the given listing parameters
	 * <br/>
	 * in fact if we have listing.page=3, browser page will be 2 (because comweb page begin at 1 whereas flash browser page begin at 0), so the user
	 * will see in the browser the medias of the page 3 and if he browses behind, the flash browser will invoke the page 2
	 * <br/>
	 * then we must configure it with flash variables  (so.addVariable("variableName", "variableValue");), flash player variables are  :
	 * <ul TYPE="disc" style="font-size: 10pt;">
	 *		<li><u>so.addVariable("showVersion", "[true|false]");</u>:indicates if the flash browser version must be displayed in the main which is appear with a right click on flash object
	 *		<li><u>so.addVariable("baseLC", "sa" + currentCache);</u>:value of the communication between the player and the browser
	 *		<li><u>sBrowser.addVariable("xmlMediaList","[requested url to obtain the xml content]");</u>:
	 * 		<li><u>sBrowser.addVariable("xmlFileStartNum", [page of the flash browser, begin at 0]);</u>
	 * </ul>
	 * <br/>More information on swfobject: <a href="http://www.adobe.com/devnet/flash/articles/swfobject.html">JavaScript Flash Player Detection and Embedding with SWFObject</a> (click on "How SWFObject Works" in left table of contents)
	 * @param {String} currentCache value of the current cache, si value allow to set the communication chanel name between the player and browser (they must have the same value)
	 * @param {String} listingParamValues parameters which must be given to the xmlplaylist servlet in order to retrieve the wanted media listing (ex: "listing.page=1&action=media.all&listing.nbre.elements=15&listing.order=0&listing.since=0&media.type=1"), note that "listing.page" parameter is required in order that flash objects can know what is the actual page, and so can called the nex or previous page
	 * @param {int} mediaId indicates the comweb media identifier of the wanted listing which must be played at first (given to the xmlplaylist servlet as parameter )
	 * @param {boolean} isStandalone indicates if the browser is in standalone mod, not used
	 * @param {String} browserName the id attribute of your flash object. the attribute name will also take this value because it is the attribute which benefits from the swliveconnect
	 * @param {String} browserDivId htmlDivElement identifier (id) wich determine the div where the browser must be writted
	 * @param {boolean} isAloneBrowser indicates if the browser use or not a player
	 * @return {void}
	 */
	setBrowser:function(currentCache,listingParamValues,mediaId,isStandalone,browserName,browserDivId,isAloneBrowser){
		this.currentCacheSwfObject = currentCache;
		this.flashlistingParamValues = listingParamValues;
		var sBrowser = null;
		if (isStandalone == true || isStandalone == "true"){
			sBrowser = new SWFObject("swf/playerBrowser/browser_small.swf", browserName , "400", "90", "8", "#ffffff");
		}else if (browserName == "membermediabrowser"){
			sBrowser = new SWFObject(CW_Action_Player.BrowserHPath, browserName , "400", "90", "8", "#ffffff");
		}else{
			sBrowser = new SWFObject("swf/playerBrowser/browser_small.swf", browserName , "400", "90", "8", "#ffffff");
		}
		//build the query listingParamValues values
		var queryListingParamValues = (new String(listingParamValues)).replace("listing.page=","listing_page=").toQueryParams();
		//get the page (the listing page begin at 1 whereas the flash xml page begin at 0):
		var page = (parseInt(queryListingParamValues.listing_page)) -1 ;
		/*
			build the url to contact the XmlPlaylistServlet match by videoslist which is in the urlPathVideosListXML var
			 - the flashvarxmlpage servlet parameter indicates that the url is build by a listing process
			 (this parameter must be at the end of the url with no value because the flash process will add te following
			 String [numPage].xml to the given url so the url will be in fact "[....]&flashvarxmlpage=[numPage].xml" with
			 numPage which own to [0,n]
		*/
		listingParamValues = "site.uid=" + CW_config.serviceId + "&" + (new String(listingParamValues)).replace("site.uid","s");
		listingParamValues = listingParamValues.replace("user.myspace=true","user.myspace=2");
		var urlPathVideosListXML = CW_Action_Player.SERVLET_URI + "?mainaction=playlist.media&playlist.begin=" + mediaId +"&" + listingParamValues + "&flashPage=";
		CW_logger.log(CW_logger.LEVEL_INFORMATION,"browser flash listingParamValues:" + listingParamValues);
		CW_logger.log(CW_logger.LEVEL_INFORMATION,"browser flash path:" + urlPathVideosListXML);
		CW_logger.log(CW_logger.LEVEL_INFORMATION,"browser flash page:" + page);

		sBrowser.addParam("menu", "true");
		sBrowser.addParam("align", "top");
		sBrowser.addParam("allowScriptAccess", "best");
		sBrowser.addParam("scale", "noscale");
		sBrowser.addParam("wmode", "opaque");
		sBrowser.addVariable("showVersion", "true");
		sBrowser.addVariable("baseLC", "sa" + currentCache);
		sBrowser.addVariable("xmlMediaList",escape(urlPathVideosListXML));
		sBrowser.addVariable("xmlFileStartNum", page);

		if (isAloneBrowser == true || isAloneBrowser=="true"){
			sBrowser.addVariable("usePlayer", "false");
		}
		//write the swf file in the div which have "browser" name
		sBrowser.write(browserDivId);
		this.flash_browser = null;
		this.setFlashBrowserObject(browserName);
	},
	/**
	 * The following method allow to set a flash browser which will display the media of a given member
	 * this browser will be insert in a htmlDivElement which has "membervideobrowser" as identifier and the page
	 * which contains this htmlDivElement (so this browser) mustn't contain a flash player
	 * @param {int} memberId comweb member identifier which determine the owner of the displayed media
	 * @param {int} CW_Action_Media_Type media type identifier which must be displayed (values are CW_Action_Media.Media_TYPE_[VIDEO|IMAGE|MUSIC])
	 * @param {String} divId htmlDivElement identifier (id)
	 */
	setBrowserMemberMedia:function (memberId,CW_Action_Media_Type,divId){
		this.flash_player = null;
		var page = 1;
		var nbElement = 10;
		var currentCache = (new Date()).getTime();
		this.browserMemberMediaParamStore = new browserMemberMediaParam(memberId,CW_Action_Media_Type,divId,page,nbElement);
		var listingParam= "user.myspace=1&listing.page="+page+"&listing.nbre.elements="+nbElement+"&media.type="+CW_Action_Media_Type+"&user.uid="+memberId+"&site.uid=" +CW_config.serviceId;

		var browserDiv = "browser_member_video";
		if (CW_Action_Media_Type ==CW_Action_Media.Media_TYPE_IMAGE){
			browserDiv = "browser_member_photo";
		}else if (CW_Action_Media_Type ==CW_Action_Media.Media_TYPE_MUSIC){
			browserDiv = "browser_member_music";
		}

		this.setBrowser((new Date()).getTime(),listingParam ,0,false,"membermediabrowser",divId,true);
	},

	setBrowserPlaylistMedia:function (groupUid,UserUid,divId){
		this.flash_player = null;
		var listingParams = "group.uid="+groupUid+"&group.type=0&user.uid="+UserUid+"&listing.page="+1;
		listingParams += "&media.type="+CW_Action_Media.Media_TYPE_MUSIC + "&media.type="+CW_Action_Media.Media_TYPE_IMAGE + "&media.type="+CW_Action_Media.Media_TYPE_VIDEO+"&listing.order=" + CW_Filter.ORDER_ASCINGROUP;
		this.setBrowser( (new Date()).getTime,listingParams,0,false,"membermediabrowser",divId,true);

		this.isPlaylistBrowser = true;
	},
	/**
	 * This function is called by flash player object (via actionscript) when user click on standalone button <img src="img/flash/button_standalone.JPG"/>
	 * The standone popup is a window which have only a player and a browser flash object, those objects must be diplayed the current displayed media in the actual page
	 * so we must process  flashlistingParamValues in order to set the actual page and open a new popup window which have the following path:
	 * standalone.html#[current played media identifier]//[processed flashlistingParamValues], so the standalone must have javascript code
	 * which used window.location.hash in order to retrieve current played media identifier and processed flashlistingParamValues values
	 * this code can be:
	 * <p style="color:#FF0000;font-size: 10pt;">
	 * 	var curHash = window.location.hash; </br>
	 * 	&nbsp;&nbsp;&nbsp;&nbsp;if (curHash!= null && curHash!=""){ </br>
	 * 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (curHash.indexOf("#")==0){curHash = curHash.substr(1);} </br>
	 * 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var mediaId = curHash.substr(0,curHash.indexOf("//")); </br>
	 * 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var listingParam = curHash.substring(curHash.indexOf("//") + 2);</br>
	 * 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PlayerFlash.setBrowserAndPlayer(listingParam,true,false,mediaId);</br>
	 * 	&nbsp;&nbsp;&nbsp;&nbsp;}</br>
	 * </p>
	 */
	standAlone:function () {
		var standaloneParams = "";
		var queryListingParamValues = (new String(this.flashlistingParamValues)).replace("listing.page","listing_page").replace("listing.nbre.elements","listing_nbre_elements").toQueryParams();
		//get the page (the listing page begin at 1 whereas the flash xml page begin at 0):
		var initPage = (parseInt(queryListingParamValues.listing_page));
		var nbElement = (parseInt(queryListingParamValues.listing_nbre_elements));
		var page = 1;
		var nodeNum = this.flashMediaNode +1 ;
		CW_logger.log(CW_logger.LEVEL_NOTICE,"lanch standalone initPage="+ initPage + ", nbElement:" + nbElement + ", nodeNum=" + nodeNum);
		try{
			if ((nodeNum%nbElement)==0){
				page = parseInt(nodeNum/nbElement);
			}else{
				page = parseInt(nodeNum/nbElement) + 1;
			}
		}catch(e){
			CW_logger.log(CW_logger.LEVEL_ERROR,"lanch standalone: can't eval the page, error:" + e);
		}
		if (page == NaN){
			page = 1;
		}
		var paramListing = this.flashlistingParamValues.replace("listing.page=" + initPage ,"listing.page=" + page);

		CW_logger.log(CW_logger.LEVEL_NOTICE,"lanch standalone: mediaId=" +  this.flashMediaId + " page=" + page + " paramListing=" + paramListing);
		standalonePopup = window.open("standalone.html#"+ this.flashMediaId + "//" +paramListing  , "StandAlone", this.standaloneWindowParam);
	}
}

/**
 * object which permits to give static PlayerFlash method
 */
var PlayerFlash = new PlayerFlash();

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// F U N C T I O N    C A L L E D    B Y     F LA S H    O B J E C T S                                    //
////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * This function is called by flash objects (via actionscript) when those objects want to play a new media (video,music,image)
 * @param {int} mediaID comweb media identifier of the current played media, provides by the xml playlist content with the "id" attribute of the "media" node
 * @param {int} nodeNum current xml node number which is corresponding to the playing media (media values come from xml playlist)
 * @see PlayerFlash#flashPlayMedia
 * @return {void}
 */
function flashPlayMedia (mediaID, nodeNum){
	PlayerFlash.flashPlayMedia(mediaID, nodeNum);
}

/**
 * This function is called by flash browser object when it want to highlight a preview media for the first time, the browser automatically inform
 * the player to play this media but don't execute the flashPlayMedia method
 * @param {int} mediaID comweb media identifier of the current played media, provides by the xml playlist content with the "id" attribute of the "media" node
 * @param {int} nodeNum current xml node number which is corresponding to the playing media (media values come from xml playlist)
 * @see PlayerFlash#flashHighLightMedia
 * @return {void}
 */
function flashHighLightMedia(mediaID, nodeNum){
	PlayerFlash.flashHighLightMedia(mediaID, nodeNum);
}
/**
 * This function is called by flash player object (via actionscript) when user click on standalone button <img src="img/flash/button_standalone.JPG"/>
 */
function standAlone(){
	try{
		PlayerFlash.standAlone();
	}catch(e){
		//alert("PlayerFlash.standAlone(), Error:" + e);
	}
}
/**
 * This function is called by flash player object (via actionscript) when user click on size main
 */
function player_size(pSize){
	PlayerFlash.flash_player.flashChangeSize(pSize);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// E N D   :   F U N C T I O N    C A L L E D    B Y     F LA S H    O B J E C T S                        //
////////////////////////////////////////////////////////////////////////////////////////////////////////////

function setBrowserAndPlayer(listingParamValues,isStandalone,isFullScreen,mediaId){
	PlayerFlash.setBrowserAndPlayer(listingParamValues,isStandalone,isFullScreen,mediaId);
}

function setBrowserMemberMedia (memberId,CW_Action_Media_Type,divId){
	PlayerFlash.setBrowserMemberMedia (memberId,CW_Action_Media_Type,divId);
}

function setPlayer(currentCache,isStandalone,isFullScreen,playerName,playerDivId,mediaType){
	PlayerFlash.setPlayer(currentCache,isStandalone,isFullScreen,playerName,playerDivId,mediaType);
}