/**
 * Class for imageless, cross-browser linear gradients
 * @author Lea Verou
 * @version 1.0
 * MIT-style license
 */
function Gradient(d,a,b,c){this.canvas=document.createElement("canvas");if(!this.canvas.getContext){this.canvas=document.createElement("span");this.canvas.style.display="inline-block";this.canvas.style.zoom=1;this.canvas.style.overflow="hidden"}this.colors=b;this.vertical=c;this.resize(d,a)}Gradient.prototype={paint:function(a,d){this.colors=a||this.colors;this.vertical=d!==undefined?!!d:this.vertical;if(!this.colors){return this}if(this.canvas.getContext){var l=this.canvas.getContext("2d");l.clearRect(0,0,this.width,this.height);var b=l.createLinearGradient(0,0,this.vertical?0:this.width,this.vertical?this.height:0);for(var f=0;f<this.colors.length;f++){var e=this.colors[f];if(e=="transparent"){if(this.colors[f-1]){e="rgba("+this.__getRGB(this.colors[f-1]).join(",")+",0)";b.addColorStop(f/(this.colors.length-1),e)}if(this.colors[f+1]){e="rgba("+this.__getRGB(this.colors[f+1]).join(",")+",0)"}}b.addColorStop(f/(this.colors.length-1),e)}l.fillStyle=b;l.fillRect(0,0,this.width,this.height)}else{this.canvas.innerHTML="";if(this.colors.length==2){var h=this.colors[0],g=this.colors[1];if(h=="transparent"){h="#00"+g.substr(1)}if(g=="transparent"){g="#00"+h.substr(1)}this.canvas.style.filter="progid:DXImageTransform.Microsoft.Gradient(startColorStr="+h+",endColorStr="+g+",gradientType="+(!this.vertical+0)+")"}else{var k=this[this.vertical?"height":"width"];for(var f=0;f<this.colors.length-1;f++){var j=document.createElement("span"),c;k-=c=Math.round(this[this.vertical?"height":"width"]/(this.colors.length-1));if(f==this.colors.length-2){c+=k}j.style[this.vertical?"height":"width"]=c+"px";j.style[this.vertical?"width":"height"]=this[this.vertical?"width":"height"]+"px";j.style.display="block";if(!this.vertical){j.style.cssFloat=j.style.styleFloat="left"}var h=this.colors[f],g=this.colors[f+1];if(h=="transparent"){h="#00"+g.substr(1)}if(g=="transparent"){g="#00"+h.substr(1)}j.style.filter="progid:DXImageTransform.Microsoft.Gradient(startColorStr="+h+",endColorStr="+g+",gradientType="+(!this.vertical+0)+")";this.canvas.appendChild(j)}}}return this},setColorAt:function(b,a){b=Math.min(this.colors.length-1,Math.max(0,b));this.colors[b]=a;return this.paint()},resize:function(b,a){this.width=b||this.width||0;this.height=a||this.height||0;if(this.canvas.getContext){this.canvas.width=this.width;this.canvas.height=this.height}else{this.canvas.style.width=this.width+"px";this.canvas.style.height=this.height+"px"}return this.paint()},direction:function(a){this.vertical=arguments.length?a:!this.vertical;return this.paint()},flip:function(){this.colors=this.colors.reverse();return this.paint()},rotate:function(){if(this.vertical){this.flip()}return this.direction()},__getRGB:function(a){a=a.substr(1);return[parseInt(a.substring(0,2),16),parseInt(a.substring(2,4),16),parseInt(a.substring(4),16)]}};