
/// Classe

if(typeof Pg_barre_player == "undefined"){

	var Pg_barre_player = function(width,path){
		this.setWidth(width);
		this.setMediaPath(path);
		this.setIsRandom(true);
		this.setIsRandomTime(true);
		
		this._img_barre_left_w 	= 42;
		this._img_barre_right_w = 82;
		this._img_bouton_w = 18;
		
		this.lecture_time = 0;
		this.lecture_width = 0;
		this.barre_lu_w = 0;
		this.barre_non_lu_w = 0;
		this.current_pourcent = 0;
		
		this._omout = "";
		this._omover = "";
		this._oclic = "";
	}

	Pg_barre_player.prototype = {
		setWidth : function(width){
			this._width=width;
		},
		setMediaPath : function(path){
			this._media_path=path;
		},
		set_OMOver : function(js){
			this._omover = js;
		},
		set_OMOut : function(js){
			this._omout = js;
		},
		set_OClic : function(js){
			this._oclic = js;
		},
		setMaxLecture : function(max){
			this._max_lecture = max;
		},
		setMinLecture : function(min){
			this._min_lecture = min;
		},
		setIsRandom : function(bool){
			this.is_random = bool;
		},
		setIsRandomTime : function(bool){
			this.is_random_time = bool;
		},
		setFixeValue : function(val){
			if(val>100) val = 100; 
			if(val<0) val = 0; 
			this.fixe_value = val;
			this.setIsRandom(false);
		},
		setFixeTimeValue : function(val){
			if(val<=0) val = 1; 
			if(val>=60) val = 59; 
			this.fixe_value_time = val*60;
			this.setIsRandomTime(false);
		},
		Draw : function(){
			TplBarre = this.Get();
			document.write(TplBarre);
		},
		Get : function(){
			if(this.is_random) this.current_pourcent = Math.round(100*Math.random());
			else this.current_pourcent = Math.round(this.fixe_value);
			
			if(this.is_random_time) this.lecture_time_total = 1800 + Math.round(1800*Math.random());
			else this.lecture_time_total = this.fixe_value_time;
			
			this.lecture_width = this._width-this._img_barre_left_w-this._img_barre_right_w-this._img_bouton_w;
			
			this.barre_lu_w 	= Math.round(this.current_pourcent*this.lecture_width/100);
			this.barre_non_lu_w = Math.round((100-this.current_pourcent)*this.lecture_width/100);
			this.lecture_time =  Math.round(this.current_pourcent*this.lecture_time_total/100);
			
			this.TraductTime();
			
			var TplBarre = '<table cellpadding="0" cellspacing="0" style="width:'+this._width+'px;font-size:11px;font-family:Verdana;'+(this._oclic.length>0?'cursor:pointer;':'')+'">'
			+ '<tr'
			+ (this._omout.length>0?' onMouseOut="'+this._omout+'" ':'') 
			+ ' ' + (this._omover.length>0?' onMouseOver="'+this._omover+'" ':'') 
			+ ' ' + (this._oclic.length>0?' onClick="'+this._oclic+'" ':'') 
			+ '><td><img src="'+this._media_path+'barre_left.jpg" width="'+this._img_barre_left_w+'px"><td>'
			+ '<td style="background-image:url(\''+this._media_path+'fond_lu.jpg\');background-repeat : repeat-x;width:'+this.barre_lu_w+'px"></td>'
			+ '<td><img src="'+this._media_path+'bouton.jpg" width="'+this._img_bouton_w+'px"></td>'
			+ '<td style="background-image:url(\''+this._media_path+'fond_non_lu.jpg\');background-repeat : repeat-x;width:'+this.barre_non_lu_w+'px"></td>'
			+ '<td style="font-size:11px;text-align:left;padding-left:10px;background-image:url(\''+this._media_path+'barre_right.jpg\');background-repeat : no-repeat;width:'+(this._img_barre_right_w-10)+'px">'
			+ this.lecture_time_txt
			+ '</td></tr></table>';
			//alert(TplBarre);
			
			return TplBarre;
			
			
		},
		TraductTime : function(){
			if(this.lecture_time == 0){
				return false;
			}
			var Secondes = this.lecture_time%60;
			var Minutes = (this.lecture_time-Secondes)/60;
			if(Secondes<10) Secondes = "0"+Secondes;
			if(Minutes<10) Minutes = "0"+Minutes;
			this.lecture_time_txt = Minutes+":"+Secondes;
		}

	}
}
