var autoHook=true;
var defaultOptions={animate:true,showText:true,width:120,boxImage:"images/bramus/percentImage.png",barImage:"images/bramus/percentImage_back1.png",height:12,onTick:function(_1){
return true;
}};
if(!JS_BRAMUS){
var JS_BRAMUS=new Object();
}
JS_BRAMUS.jsProgressBar=Class.create();
JS_BRAMUS.jsProgressBar.prototype={el:null,id:null,percentage:null,options:null,initialPos:null,initialPerc:null,pxPerPercent:null,backIndex:null,numPreloaded:null,running:null,queue:false,initialize:function(el,_3,_4){
this.options=Object.clone(defaultOptions);
Object.extend(this.options,_4||{});
this.el=$(el);
this.id=$(el).id;
this.percentage=0;
this.backIndex=0;
this.numPreloaded=0;
this.running=false;
this.queue=Array();
this.imgWidth=this.options.width*2;
this.initialPos=this.options.width*(-1);
this.pxPerPercent=this.options.width/100;
this.initialPerc=_3;
if(this.options.barImage.constructor!=Array){
this.options.barImage=Array(this.options.barImage);
}
this.preloadImages();
},preloadImages:function(){
for(i=0;i<this.options.barImage.length;i++){
var _5=null;
_5=new Image();
_5.onload=function(){
this.numPreloaded++;
}.bind(this);
_5.onerror=function(){
this.numPreloaded++;
}.bind(this);
_5.onabort=function(){
this.numPreloaded++;
}.bind(this);
_5.src=this.options.barImage[i];
if(_5.complete){
this.numPreloaded++;
}
}
if(!Prototype.Browser.IE){
this.checkPreloadedImages();
}else{
this.initVisuals();
}
},checkPreloadedImages:function(){
if(parseInt(this.numPreloaded,10)>=parseInt(this.options.barImage.length,10)){
this.initVisuals();
}else{
if(parseInt(this.numPreloaded,10)<=parseInt(this.options.barImage.length,10)){
setTimeout(function(){
this.checkPreloadedImages();
}.bind(this),100);
}
}
},initVisuals:function(){
$(this.el).update("<img id=\""+this.id+"_percentImage\" src=\""+this.options.boxImage+"\" alt=\"0%\" style=\"width: "+this.options.width+"px; height: "+this.options.height+"px; background-position: "+this.initialPos+"px 50%; background-image: url("+this.options.barImage[this.backIndex]+"); padding: 0; margin: 0;\" class=\"percentImage\" />"+((this.options.showText==true)?"<span id=\""+this.id+"_percentText\" class=\"percentText\">0%</span>":""));
this.setPercentage(this.initialPerc);
},setPercentage:function(_6,_7){
if(_7){
this.percentage=(this.queue.length!=0)?this.queue[0]:_6;
this.timer=null;
this.queue=[];
setTimeout(function(){
this.setPercentage(_6);
}.bind(this),10);
}else{
this.queue.push(_6);
if(this.running==false){
this.processQueue();
}
}
},processQueue:function(){
if(this.queue.length>0){
this.running=true;
this.processQueueEntry(this.queue[0]);
}else{
return;
}
},processQueueEntry:function(_8){
var _9=parseInt(this.percentage,10);
if((_8.toString().substring(0,1)=="+")||(_8.toString().substring(0,1)=="-")){
_8=_9+parseInt(_8);
}
if(_8<0){
_8=0;
}
if(_8>100){
_8=100;
}
if(this.options.animate==false){
this.queue.splice(0,1);
this._setBgPosition(_8);
if(!this.options.onTick(this)){
return;
}
this.running=false;
this.processQueue();
return;
}
if(_8!=_9){
if(_9<_8){
newPercentage=_9+1;
}else{
newPercentage=_9-1;
}
callTick=true;
}else{
newPercentage=_9;
callTick=false;
}
this._setBgPosition(newPercentage);
if(callTick&&!this.options.onTick(this)){
return;
}
if(_9!=newPercentage){
this.timer=setTimeout(function(){
this.processQueueEntry(_8);
}.bind(this),10);
}else{
this.queue.splice(0,1);
this.running=false;
this.timer=null;
this.processQueue();
return;
}
},getPercentage:function(id){
return this.percentage;
},_setBgPosition:function(_b){
$(this.id+"_percentImage").style.backgroundPosition=(this.initialPos+(_b*this.pxPerPercent))+"px 50%";
var _c=Math.floor((_b-1)/(100/this.options.barImage.length));
if((_c!=this.backIndex)&&(this.options.barImage[_c]!=undefined)){
$(this.id+"_percentImage").style.backgroundImage="url("+this.options.barImage[_c]+")";
}
this.backIndex=_c;
$(this.id+"_percentImage").alt=_b+"%";
$(this.id+"_percentImage").title=_b+"%";
if(this.options.showText==true){
$(this.id+"_percentText").update(""+_b+"%");
}
this.percentage=_b;
}};
JS_BRAMUS.jsProgressBarHandler=Class.create();
JS_BRAMUS.jsProgressBarHandler.prototype={pbArray:new Array(),initialize:function(){
$$("span.progressBar").each(function(el){
this.pbArray[el.id]=new JS_BRAMUS.jsProgressBar(el,parseInt(el.innerHTML.replace("%","")));
}.bind(this));
},setPercentage:function(el,_f,_10){
this.pbArray[el].setPercentage(_f,_10);
},getPercentage:function(el){
return this.pbArray[el].getPercentage();
}};
if(autoHook==true){
function initProgressBarHandler(){
myJsProgressBarHandler=new JS_BRAMUS.jsProgressBarHandler();
}
document.observe("dom:loaded",initProgressBarHandler,false);
}


