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