(function(d){d.extend({progressBar:new (function(){this.defaults={steps:20,stepDuration:20,max:100,showText:true,textFormat:"percentage",width:120,height:12,callback:null,boxImage:"images/progressbar.gif",barImage:{0:"images/progressbg_red.gif",30:"images/progressbg_orange.gif",70:"images/progressbg_green.gif"},running_value:0,value:0,image:null};this.construct=function(k,o){var e=null,h=null;if(k!=null)if(isNaN(k))h=k;else{e=k;if(o!=null)h=o}return this.each(function(){function p(c){var f=c.barImage;
if(typeof c.barImage=="object")for(var l in c.barImage)if(c.running_value>=parseInt(l))f=c.barImage[l];else break;return f}function i(c){if(c.showText)if(c.textFormat=="percentage")return" "+Math.round(c.running_value)+"%";else if(c.textFormat=="fraction")return" "+c.running_value+"/"+c.max}var m=this,a=this.config;if(e!=null&&this.bar!=null&&this.config!=null){this.config.value=e;if(h!=null)m.config=d.extend(this.config,h);a=m.config}else{var g=d(this);a=d.extend({},d.progressBar.defaults,h);a.id=
g.attr("id")?g.attr("id"):Math.ceil(Math.random()*1E5);if(e==null)e=g.html().replace("%","");a.value=e;a.running_value=0;a.image=p(a);g.html("");var b=document.createElement("img"),j=document.createElement("span");b=d(b);j=d(j);m.bar=b;b.attr("id",a.id+"_pbImage");j.attr("id",a.id+"_pbText");j.html(i(a));b.attr("title",i(a));b.attr("alt",i(a));b.attr("src",a.boxImage);b.attr("width",a.width);b.css("width",a.width+"px");b.css("height",a.height+"px");b.css("background-image","url("+a.image+")");b.css("background-position",
a.width*-1+"px 50%");b.css("padding","0");b.css("margin","0");g.append(b);g.append(j)}a.increment=Math.round((a.value-a.running_value)/a.steps);if(a.increment<0)a.increment*=-1;if(a.increment<1)a.increment=1;var q=setInterval(function(){var c=a.width/100;if(a.running_value>a.value)if(a.running_value-a.increment<a.value)a.running_value=a.value;else a.running_value-=a.increment;else if(a.running_value<a.value)if(a.running_value+a.increment>a.value)a.running_value=a.value;else a.running_value+=a.increment;
a.running_value==a.value&&clearInterval(q);var f=d("#"+a.id+"_pbImage"),l=d("#"+a.id+"_pbText"),n=p(a);if(n!=a.image){f.css("background-image","url("+n+")");a.image=n}f.css("background-position",a.width*-1+a.running_value*100/a.max*c+"px 50%");f.attr("title",i(a));l.html(i(a));a.callback!=null&&typeof a.callback=="function"&&a.callback(a);m.config=a},a.stepDuration)})}})});d.fn.extend({progressBar:d.progressBar.construct})})(jQuery);
