var myProgressBar = Class.create();

    myProgressBar.prototype = {

	initialize: function(id) {
			this.progressBar = $(id);
			this.width = 200;
			this.limit = 70;
			this.interval = null;
			this.buildProgressBar();
	 },

	buildProgressBar: function() {	
		
		var content = '\
					<div id="progressbar_mContainer" style="text-align:left;width:'+ this.width +'px;" >\
						<div id="progressbar_gradient" style="width:'+ this.width +'px;"></div>\
						<div id="progressbar_mask" style="left:0px; width:'+ this.width +'px;"></div>\
						<div id="progressbar_progressIndicator" style="z-index:10; width:'+ this.width +'px;">0%</div>\
					</div>';
					
		this.progressBar.update(content);
		
	},
	
	demoProgressBar: function() {
		curWidth = parseInt($("progressbar_mask").offsetWidth);
		curLeft = parseInt($("progressbar_mask").offsetLeft);
		curWidth --;
		curLeft ++;
	
		if(curLeft == this.width + 1) {
			clearInterval(this.interval);
			$("progressbar_mask").style.display = "none";
			return;
		}
	
	
		$("progressbar_mask").style.left = curLeft + "px";
		if(parseInt($("progressbar_mask").offsetWidth)>10)
			$("progressbar_mask").style.width = curWidth + "px";
			
		$("progressbar_progressIndicator").innerHTML = Math.floor((curLeft / parseInt($("progressbar_gradient").offsetWidth))*100) + "%";
	},
	

	demoProgressBar2: function() {
		curWidth = parseInt($("progressbar_mask").offsetWidth);
		curLeft = parseInt($("progressbar_mask").offsetLeft);
		curWidth --;
		curLeft ++;
		
		pourcent = this.width / 100 
		limit = pourcent * this.limit;
	
		if(curLeft == limit + 1) {
			clearInterval(this.interval);
			//$("mask").style.display = "none";
			return;
		}
	
	
		$("progressbar_mask").style.left = curLeft + "px";
		if(parseInt($("progressbar_mask").offsetWidth)>10)
			$("progressbar_mask").style.width = curWidth + "px";
			
		$("progressbar_progressIndicator").innerHTML = Math.floor((curLeft / parseInt($("progressbar_gradient").offsetWidth))*100) + "%";
	},
	
	setProgressBar: function(statValue,endValue){
		
		//alert('setProgressBar')

		pourcent = this.width / 100 
		
		if(statValue != 0 && endValue != 0)
			actualPourcent = (statValue / endValue) * 100;
		else
			actualPourcent = 0
		
		//alert("statValue :" + statValue + " endValue " + endValue + " actualPourcent : " + actualPourcent);
		
		
		curLeft  = actualPourcent * pourcent;
		curWidth = (100 - actualPourcent) * pourcent;
	
		$("progressbar_mask").style.left = curLeft + "px";
		$("progressbar_mask").style.width = curWidth + "px";
			
		$("progressbar_progressIndicator").innerHTML = Math.round(actualPourcent) + "%";
	},
	
	setProgressBarASP: function(pourcentASP){
		
		//alert('setProgressBar')

		pourcent = this.width / 100 
		
		
		actualPourcent = pourcentASP;
		
		//alert("statValue :" + statValue + " endValue " + endValue + " actualPourcent : " + actualPourcent);
		
		
		curLeft  = actualPourcent * pourcent;
		curWidth = (100 - actualPourcent) * pourcent;
	
		$("progressbar_mask").style.left = curLeft + "px";
		$("progressbar_mask").style.width = curWidth + "px";
			
		$("progressbar_progressIndicator").innerHTML = Math.round(actualPourcent) + "%";
	},
	
	startDemoProgressBar: function() {
		this.interval = setInterval(this.demoProgressBar.bind(this),10);
		//this.setProgressBar(215,500);
	}   
	
}; 
