(function(a){var b={getRGBvalues:function(b){if(typeof b=="string"){var c={r:null,g:null,b:null};if(b.indexOf("#")===0){b=b.substr(1);if(b.length==3)c={r:parseInt(b[0]+b[0],16),g:parseInt(b[1]+b[1],16),b:parseInt(b[2]+b[2],16)};else c={r:parseInt(b.substr(0,2),16),g:parseInt(b.substr(2,2),16),b:parseInt(b.substr(4,2),16)}}else if(b.indexOf("rgb(")===0){var d=b.indexOf(",");c.r=parseInt(b.substr(4,d));c.g=parseInt(b.substr(d+1,b.indexOf(",",d)));c.b=parseInt(b.substr(b.indexOf(",",d+1)+1,b.indexOf(")")))}return c}else a.error('wrong syntax for "getRGBvalues" function call: argument must be a string like "#rrggbb", "#rgb" or "rgb(x,y,z)".')},init:function(c){var d=a(this);d.data("colorBar",{topColor:"#0a0",topValue:100,bottomColor:"#a00",bottomValue:0,startValue:0,currentValue:0,animSpeed:"fast",displayNumbers:false});a.extend(d.data("colorBar"),c);d.css({overflow:"hidden"});d.data("colorBar").currentValue=d.data("colorBar").startValue;var e=d.data("colorBar").topValue-d.data("colorBar").bottomValue,f=b.getRGBvalues(d.data("colorBar").bottomColor),g=b.getRGBvalues(d.data("colorBar").topColor),h={r:Math.round((g.r-f.r)*(d.data("colorBar").startValue-d.data("colorBar").bottomValue)/e)+f.r,g:Math.round((g.g-f.g)*(d.data("colorBar").startValue-d.data("colorBar").bottomValue)/e)+f.g,b:Math.round((g.b-f.b)*(d.data("colorBar").startValue-d.data("colorBar").bottomValue)/e)+f.b};d.append("<div></div>").find("div").height(d.height());var i=d.find("div");if(d.data("colorBar").displayNumbers)i.append("<span>"+d.data("colorBar").startValue+"</span>").find("span").css({"margin-right":".2em","float":"right","vertical-align":"middle","line-height":d.height()+"px","font-size":d.height()*.8+"px"});i.css({width:d.width()*(d.data("colorBar").startValue-d.data("colorBar").bottomValue)/(d.data("colorBar").topValue-d.data("colorBar").bottomValue),"background-color":"rgb("+h.r+","+h.g+","+h.b+")"});return a(this)},change:function(c){var d=a(this);if(typeof c=="number"&&c!=d.data("colorBar").currentValue){c=c<d.data("colorBar").bottomValue?d.data("colorBar").bottomValue:c>d.data("colorBar").topValue?c=d.data("colorBar").topValue:c;var e=d.data("colorBar").topValue-d.data("colorBar").bottomValue,f=b.getRGBvalues(d.data("colorBar").bottomColor),g=b.getRGBvalues(d.data("colorBar").topColor),h={r:Math.round((g.r-f.r)*(c-d.data("colorBar").bottomValue)/e)+f.r,g:Math.round((g.g-f.g)*(c-d.data("colorBar").bottomValue)/e)+f.g,b:Math.round((g.b-f.b)*(c-d.data("colorBar").bottomValue)/e)+f.b};var i,j=d.data("colorBar").currentValue-d.data("colorBar").bottomValue;d.data("colorBar").currentValue=c;d.animate({"text-indent":d.css("text-indent")},{duration:d.data("colorBar").animSpeed,step:function(a,b){i=Math.round(j-b.pos*(j-(c-d.data("colorBar").bottomValue)));d.find("div").css({width:d.width()*i/(d.data("colorBar").topValue-d.data("colorBar").bottomValue),"background-color":"rgb("+h.r+","+h.g+","+h.b+")"});if(d.data("colorBar").displayNumbers)d.find("div>span").text(d.data("colorBar").bottomValue+i)},queue:false})}}};a.fn.colorBar=function(c,d){switch(typeof c){case"string":if(c.indexOf("+=")===0||c.indexOf("-=")===0){if(a(this).find("div").length==1){var e=c.substr(0,2)=="+="?parseInt(c.substr(2)):-parseInt(c.substr(2));e+=a(this).data("colorBar").currentValue;return b.change.apply(this,[e])}}else if(b[c]!=undefined){if(d!=undefined)return b[c].apply(this,[d])}break;case"number":return b.change.apply(this,[c]);break;case"object":return b.init.apply(this,[c]);break;case"undefined":return b.init.apply(this);break;default:a.error("wrong parameters syntax. ("+typeof c+') "'+c+'"" is not an acceptable type of data for colorBar.')}}})(jQuery)
