

//version 2.0.2.1
/**
    MediaPlayer constructor.
    Take objectId and url in parameter, and an array of other optionnal parameters.
    Set the object methods.
*/
function AbstractMediaPlayer(objectIdParam, urlParam, parametersArray) {
    // save config parameters in the object
    if (parametersArray) {
        for (s_key in parametersArray) {
            this[s_key] = parametersArray[s_key];
        }
    }
    thePlayer = this;
    this.objectId = objectIdParam;
    this.playerObject = document.getElementById(this.objectId);
    this.url = urlParam;
    this.volumePlayer = 0;
    this.volumeImage = 5;
    this.sliderRef;
    this.buffering = true;
    this.waitoneboucle = 0;

}
/**
    This method is launched automatically every second.
    This method update the Slider position.
*/
AbstractMediaPlayer.prototype.automaticCall = function (weblogger) {

		window.setTimeout("thePlayer.automaticCall(" + weblogger + ")", 1000);

    if(data.isPollingActive()){
        if(isIE && this.playerObject  && (this.isBuffering() + '' == 'false') && (this.isLoading() + '' == 'false')){
	   	 	this.initSlider();
		    this.updateSliderPosition();
		   
	    } 
	    if(!isIE){
	    	this.initSlider();
		    this.updateSliderPosition();
	    }
		this.updatePlayerFormat();
		this.updateTechnicalDataDiv(weblogger);
		this.updateBufferDiv(false);
    }

   
};


/**
    This method is launched automatically every second.
    * just for buffering
*/
AbstractMediaPlayer.prototype.automaticCallBuffer = function () {
    window.setTimeout("thePlayer.automaticCallBuffer()", 1000);
    this.updateBufferDiv(true);
    
};



/**
    Init the player slider in function of the video length
*/
AbstractMediaPlayer.prototype.initSlider = function (videoLength) {
    var A_TPL = {"b_vertical":false, "b_watch":false, "n_controlWidth":150, "n_controlHeight":16, "n_sliderWidth":10, "n_sliderHeight":10, "n_pathLeft":1, "n_pathTop":2, "n_pathLength":150, "s_imgControl":"/wps-europarl-internet/vod/illustration/g_bg.gif /wps-europarl-internet/vod/illustration/player_icone_musique_black.gif", "s_imgSlider":"/wps-europarl-internet/vod/illustration/player_curseur.gif", "n_zIndex":1, "s_divId":this.divNameForSlider, "s_eventMethodToCall":"thePlayer.sliderIsMoved"};
    var A_INIT = {"s_form":"player_final_content_sb:TechnicalVideoDataForm", "s_name":"player_final_content_sb:TechnicalVideoDataForm:vodSliderTextField", "n_minValue":0, "n_maxValue":videoLength, "n_value":0, "n_step":1};
    this.sliderRef = new Slider(A_INIT, A_TPL);
};
/**
    Method decrease the MediaPlayer volume, and change the volume image
*/
AbstractMediaPlayer.prototype.decreaseVolume = function (volumeImageDivId) {
    if (this.volumePlayer + 0 > 0 && this.volumeImage > 0) {
        this.volumePlayer -= 10;
        this.volumeImage -= 1;
        var id = volumeImageDivId + String(this.volumeImage + 1);
        url = "/wps-europarl-internet/vod/illustration/player_volume_none.gif";
        swap_image(id, url);
    }
};

    // Changement d'image ----------------------------------------
function swap_image(img, url) {
    if (document.getElementById) { // IE5+/NS6+
        theImg = document.getElementById(img);
    } else {
        if (document.all) { // IE4+
            theImg = document.all(img);
        }
    }
    theImg.src = url;
}
/**
    Method increase the MediaPlayer volume, and change the volume image
*/
AbstractMediaPlayer.prototype.increaseVolume = function (volumeImageDivId) {
    if (this.volumePlayer + 0 < 100 && this.volumeImage < 9) {
        this.volumePlayer += 10;
        this.volumeImage += 1;
        var id = volumeImageDivId + String(this.volumeImage);
        url = "/wps-europarl-internet/vod/illustration/player_volume_niv" + String(this.volumeImage) + ".gif";
        swap_image(id, url);
    }
};
AbstractMediaPlayer.prototype.updateTechnicalDataDiv = function (weblogger) {
    if (this.playerObject) {
    	if(weblogger == 'true'){
        	document.getElementById(this.divNameForTechnicalData).innerHTML = this.buildTechnicaleData();
        }
        if (this.isLoading() && !isIE){
            document.getElementById("testDiv").innerHTML = '<img src="/wps-europarl-internet/vod/illustration/PE_loading.gif" alt="Loading, please wait ..." />';
        }
        else {
        	if(document.getElementById("testDiv").innerHTML != '' && !isIE){
           		 document.getElementById("testDiv").innerHTML = '';
        	}
        }
    }
};

AbstractMediaPlayer.prototype.updateBufferDiv = function (islivevideo) {
    if (this.playerObject) {
    	
        if (this.isBuffering() + '' == 'true' ){
            if(isNS){
        	   document.getElementById("testDiv").innerHTML = '<img src="/wps-europarl-internet/vod/illustration/PE_loading.gif" alt="Loading, please wait ..." />';
        	}
        	if (document.getElementById("videocontainer") &&  !islivevideo) {
       			if(document.getElementById("videocontainer").style.visibility =='visible' || document.getElementById("testDiv").innerHTML == ''){
       				playLoadingGif();
       			}
        	   
        	}
            if (document.getElementById("table-video") && islivevideo) {
                 if(document.getElementById("table-video")!=''){
                 	   playLoadingGif();     	 
                 }
            	 document.getElementById("table-video").className = '';
            }
            this.buffering = true;
            
        }
        else {
            this.buffering = false;
            if(this.waitoneboucle > 1 || !islivevideo){
	        	if(document.getElementById("testDiv").innerHTML != ''){
	          		 document.getElementById("testDiv").innerHTML = '';
	        	}
	            if (document.getElementById("videocontainer") &&  document.getElementById("videocontainer").style.visibility == 'hidden'){
	            	document.getElementById("videocontainer").style.visibility="visible";
	            }
	            if (document.getElementById("table-video")){ 
	            	document.getElementById("table-video").className = 'table-video';
	            }
	            this.waitoneboucle = 0;
	         }
             this.waitoneboucle +=1;
        }
    }
};

function playLoadingGif(){
        if (document.getElementById("videocontainer"))
			document.getElementById("videocontainer").style.visibility="hidden";
		if (document.getElementById("testDiv"))
    		document.getElementById("testDiv").innerHTML = '<img src="/wps-europarl-internet/vod/illustration/PE_loading.gif" title="Loading, please wait ..." alt="Loading, please wait ..." />';
}

