
Color=function(r,g,b){this.set(r,g,b);};Color.prototype={set:function(r,g,b){if(r!=undefined&&g!=undefined&&b!=undefined){r=parseFloat(r);g=parseFloat(g);b=parseFloat(b);}
else if(r!=undefined){var str=r;var r=0,g=0,b=0;if(typeof str!='undefined'){str=str.replace(/\s+/g,'').toLowerCase();if(str.substr(0,1)=='#'){str=str.substr(1);if(str.length==6){r=parseInt(str.substr(0,2),16);g=parseInt(str.substr(2,2),16);b=parseInt(str.substr(4,2),16);}
else if(str.length==3){r=parseInt(str.substr(0,1)+str.substr(0,1),16);g=parseInt(str.substr(1,1)+str.substr(1,1),16);b=parseInt(str.substr(2,1)+str.substr(2,1),16);}}
else if(str.substr(0,3)=='rgb'){var colors=str.substring(str.indexOf('(')+1,str.indexOf(')')).split(',');r=colors[0];g=colors[1];b=colors[2];r=r.indexOf('%')>-1?r.substring(0,r.indexOf('%'))*2.55:parseInt(r);g=g.indexOf('%')>-1?g.substring(0,g.indexOf('%'))*2.55:parseInt(g);b=b.indexOf('%')>-1?bsubstring(0,b.indexOf('%'))*2.55:parseInt(b);}
else if(Color[str]instanceof Color){r=Color[str].r;g=Color[str].g;b=Color[str].b;}}}
this.r=r;this.g=g;this.b=b;},get:function(){return'rgb('+Math.round(this.r)+','+Math.round(this.g)+','+Math.round(this.b)+')';},toString:function(){return this.get();}};Object.extend(Color,{add:function(color1,color2){return Color._add(color1,color2,1);},subtract:function(color1,color2){return Color._add(color1,color2,-1);},_add:function(color1,color2,add){return new Color(color1.r+add*color2.r,color1.g+add*color2.g,color1.b+add*color2.b);},black:new Color(0,0,0),gray:new Color(128,128,128),maroon:new Color(128,0,0),red:new Color(255,0,0),green:new Color(0,128,0),lime:new Color(0,255,0),olive:new Color(128,128,0),yellow:new Color(255,255,0),navy:new Color(0,0,128),blue:new Color(0,0,255),purple:new Color(128,0,128),fuchsia:new Color(255,0,255),teal:new Color(0,128,128),aqua:new Color(0,255,255),silver:new Color(192,192,192),white:new Color(255,255,255)});Dimension=function(value,unit){this.set(value,unit);};Dimension.prototype={set:function(value,unit){var D=Dimension;if(value==undefined)
value=0;if(unit==undefined){str=String(value).replace(/\s+/g,'').toLowerCase();value=parseFloat(str);unit=str.substr(String(value).length);}
var allUnits=[].concat(D._units.screen,D._units.relative,D._units.absolute);if(!allUnits.include(unit))
unit='px';this.value=value;this.unit=unit;if(D._units.absolute.include(unit)){value=this.inchValue();unit='in';}
this.value=value;this.unit=unit;},inchValue:function(){var value=this.value;switch(this.unit){case'pt':value/=72;break;case'pc':value/=6;break;case'mm':value*=5/127;break;case'cm':value*=50/127;break;}
return value;},pxValue:function(){var u=Dimension._units;if(u.relative.include(this.unit))
return Number.NaN;if(u.absolute.include(this.unit))
return this.inchValue()*72;return this.value;},get:function(){if(this.unit=='px')
return Math.round(this.value)+this.unit;return this.value+this.unit;},toString:function(){return this.get();}};Object.extend(Dimension,{add:function(dim1,dim2){return Dimension._add(dim1,dim2,1);},subtract:function(dim1,dim2){return Dimension._add(dim1,dim2,-1);},_add:function(dim1,dim2,add){var D=Dimension;switch(D._compatible(dim1,dim2)){case 0:return new Dimension((dim1.value+add*dim2.value)+dim1.unit);case 1:return null;case 2:return new Dimension((dim1.inchValue()+add*dim2.inchValue())+'in');case 3:return new Dimension((dim1.pxValue()+add*dim2.pxValue())+'px');}},_units:{screen:['px'],relative:['em','ex','%'],absolute:['pt','pc','in','mm','cm']},_compatible:function(dim1,dim2){var D=Dimension;if(dim1.unit==dim2.unit)
return 0;if(D._units.relative.include(dim1.unit)||D._units.relative.include(dim2.unit))
return 1;if(D._units.absolute.include(dim1.unit)&&D._units.absolute.include(dim2.unit))
return 2;return 3;}});Run=function(settings){this._id=Run._id++;this.flow=Run.flow;this.iterations=Run.iterations;this.velocity=Run.velocity;Run._listenerTypes.each(function(type){this['on'+type]=null;});this._time=Run.time;this.setFrequency(Run.frequency);this._paused=Run.pauses;this._elements=[];this._style={};if(settings!=undefined)
this.set(settings);this._iteration=0;this._paused=!this._paused;if(this._paused)
this.play();else
this._paused=true;};Run.prototype={set:function(settings){var s=settings;if(s.flow!=undefined)
this.flow=s.flow;if(s.iterations>=0)
this.iterations=s.iterations;if(s.velocity!=undefined)
this.velocity=s.velocity;var types=Run._listenerTypes;for(var i=0;i<types.length;i++){var type='on'+types[i];if(s[type]!=undefined){if(!isArray(s[type]))
s[type]=[s[type]];for(var j=0;j<s[type].length;j++){this.addEventListener(types[i],s[type][j]);}}}
if(s.time>0)
this.setTime(s.time);if(s.frequency>0)
this.setFrequency(s.frequency);if(s.steps>0)
this.setSteps(s.steps);if(s.pauses!=undefined)
this._paused=s.pauses;if(s.elements!=undefined)
this.addElements(s.elements);if(s.style!=undefined)
this.addStyle(s.style);return this;},addElements:function(elements){if(!isArray(elements))
elements=[elements];for(var i=0;i<elements.length;i++){var e=elements[i]=$(elements[i]);if(!this._elements.include(e)){if(typeof e.RunStyle=='undefined')
e.RunStyle={};this._elements.push(e);}}
this._calculateStyle(elements);return this;},removeElements:function(elements){if(elements==undefined)
elements=this._elements;if(!isArray(elements))
elements=[elements];var es=this._elements;for(var i=0;i<elements.length;i++){var e=$(elements[i]);var index=es.indexOf(e);if(index>-1){es.splice(index,1);for(var attr in e.RunStyle)
if(e.RunStyle[attr].id==this._id)
delete e.RunStyle[attr];}}
return this;},getElements:function(){return this._elements;},addStyle:function(style){var attrs=[];for(var attr in style){if(!isArray(style[attr]))
style[attr]=[style[attr]];var a=style[attr];switch(a.length){case 1:a[1]=a[0];a[0]=Prototype.K;break;case 2:case 3:break;default:delete style[attr];continue;}
[0,1].each(function(n){if(a[n]==null)
a[n]=Prototype.K;else if(typeof a[n]!='function'){var type=Run._styleAttributes[attr];if(type!=Number)
a[n]=new type(a[n]);else if(attr=='opacity'&&a[n]>1)
a[n]/=100;}});}
Object.extend(this._style,style);this._calculateStyle(style);return this;},removeStyle:function(style){if(style==undefined)
style=this._style;for(var attr in style){delete this._style[attr];for(var i=0;i<this._elements.length;i++){var e=this._elements[i];if(e.RunStyle[attr].id=this._id)
delete e.RunStyle[attr];}}
return this;},getStyle:function(){return this._style;},_calculateStyle:function(stylements){var style,elements;if(stylements==undefined){style=this._style;elements=this._elements;}
else if(isArray(stylements)){style=this._style;elements=stylements;}
else{style=stylements;elements=this._elements;}
for(var i=0;i<elements.length;i++){var e=elements[i];for(var attr in style){var a=style[attr];if(typeof e.RunStyle[attr]=='undefined')
e.RunStyle[attr]=[];eAttr=e.RunStyle[attr];[0,1].each(function(n){if(typeof a[n]=='function'){var value=Element.getStyle(e,attr.uncamelize());if(value==null){if(attr=='width'||attr=='height'){var dim=Element.getDimensions(e,true);value=dim[attr]+'px';}
else if(attr=='left'||attr=='top'){var position=Element.getStyle(e,'position'),pos;if(position=='absolute'||position=='fixed'){if(position=='absolute')
pos=Position.get(e,undefined,true,true);else if(position=='fixed')
pos=Position.get(e,undefined,true);value=pos[attr]+'px';}}
else if(attr=='opacity')
value=1;}
if(value!=null){eAttr[n]=new Run._styleAttributes[attr](value);a[n](eAttr[n]);}}
else
eAttr[n]=a[n];});eAttr[1]=(typeof eAttr[1]!='number')?Run._styleAttributes[attr].subtract(eAttr[1],eAttr[0]):eAttr[1]-eAttr[0];eAttr['id']=this._id;}}},setTime:function(time){this._time=time>0?time:Run.time;this._calculateRun();return this;},getTime:function(){return this._time;},setFrequency:function(frequency){this._frequency=frequency>0?frequency:Run.frequency;this._calculateRun();return this;},getFrequency:function(){return this._frequency;},setSteps:function(steps){if(steps>=1){this._steps=steps;this._time=steps/this._frequency;}
return this;},getSteps:function(){return this._steps;},_calculateRun:function(){this._steps=Math.round(this._time*this._frequency);this._delay=Math.round(1000/this._frequency);},play:function(){if(this._paused){this._paused=false;var this_=this;var delay;(delay=function(){if(!this_._paused){this_.next();window.setTimeout(delay,this_._delay);}})();this._callListener('play');}
return this;},pause:function(){if(!this._paused){this._paused=true;this._callListener('pause');}
return this;},pauses:function(){return this._paused;},stop:function(){if(this._step>-1){this._step=-1;this.setStep(0);this.pause();this._iteration=0;this._callListener('stop');}
return this;},next:function(){this.setStep(this._step+this.velocity);return this;},previous:function(){this.setStep(this._step-this.velocity);return this;},first:function(){this.setStep(0);return this;},last:function(){this.setStep(this._steps);return this;},setStep:function(step){var prev=this._step;var it=this._iteration;if(step>this._steps)
it++;else if(step<0)
it--;if(this.iterations==0||(it<this.iterations&&it>=0)){if(step>this._steps)
this._step=step%(this._steps+1);else if(step<0)
this._step=this._steps+1+step%(this._steps+1);else
this._step=step;this._iteration=it;this._setStepStyle();if(step==prev+this.velocity)
this._callListener('next');if(step==prev-this.velocity)
this._callListener('previous');if(this._step==0)
this._callListener('first');if(this._step==this._steps)
this._callListener('last');}
else{if(!this.pauses()){this._step=-1;this.pause();this._iteration=0;}
this._callListener('end');}
return this;},getStep:function(){return this._step;},addEventListener:function(type,handler){var ontype='on'+type;for(var k=0;typeof this[type+k]=='function';k++);if(k==0){if(this[ontype]){this[type+k]=this[ontype];this[ontype]=null;k++;}}
this[type+k]=handler;if(!this[ontype])
this[ontype]=function(){for(var j=0;typeof this[type+j]=='function';j++);for(var i=0;i<j;i++)
this[type+i]();};return this;},removeEventListener:function(type,handler){for(var k=0;typeof this[type+k]!='undefined';k++){if(this[type+k]==handler)
delete this[type+k];}
return this;},_setStepStyle:function(){var s=this._style,a,type,add,get;var x=this._step/this._steps,y;var flow=this.flow;for(var i=0;i<this._elements.length;i++){var e=this._elements[i];for(var attr in s){a=e.RunStyle[attr];if(a.id==this._id){y=(typeof s[attr][2]=='function')?s[attr][2](x):flow(x);type=Run._styleAttributes[attr];switch(type){case Color:e.style[attr]=(c=new Color(a[0].r+a[1].r*y,a[0].g+a[1].g*y,a[0].b+a[1].b*y))+'';break;case Dimension:add=new Dimension(a[1].value*y,a[1].unit);var res=Dimension.add(a[0],add);if(attr=='fontSize'&&res.value==0)
res.value=1;e.style[attr]=res+'';break;case Number:value=a[0]+a[1]*y;e.style[attr]=attr=='opacity'?Element.setOpacity(e,value):value;}}}}},_callListener:function(type){var ontype='on'+type;if(this[ontype]!=null)
this[ontype]();},_step:-1};Object.extend(Run,{frequency:40,iterations:1,pauses:false,step:0,time:1,velocity:1,LINEAR:Prototype.K,SINUS:function(x){return 0.5+0.5*Math.sin(x*Math.PI*2-0.5*Math.PI);},COSINUS:function(x){return 0.5+0.5*Math.cos(x*Math.PI*2-0.5*Math.PI);},SMOOTH:function(x){return Math.sin(x*Math.PI/2);},INQUAD:function(x){return x*x;},OUTQUAD:function(x){return-1*x*(x-2);},INCUBIC:function(x){return x*x*x;},INQUARD:function(x){return x*x*x*x;},INQUINT:function(x){return x*x*x*x*x;},INSINE:function(x){return-1*Math.cos(x*(Math.PI/2))+1;},OUTSINE:function(x){return Math.sin(x*(Math.PI/2));},INOUTSINE:function(x){return-1/2*(Math.cos(Math.PI*x)-1);},INEXPO:function(x){return(x==0)?0:Math.pow(2,10*(x-1));},OUTEXPO:function(x){return(x==1)?1:-Math.pow(2,-10*x)+1;},INCIRC:function(x){return-1*(Math.sqrt(1-x*x)-1);},INBACK:function(x){var s=1.70158;return x*x*((s+1)*x-s);},INELASTIC:function(x){if(x==0||x==1)
return x;var p=.3;var s=p/4;return-(Math.pow(2,10*(x-=1))*Math.sin((x*1-s)*(2*Math.PI)/p));},OUTBOUNCE:function(x){if(x<(1/2.75))
return 7.5625*x*x;else if(x<(2/2.75))
return 7.5625*(x-=(1.5/2.75))*x+.75;else if(x<(2.5/2.75))
return 7.5625*(x-=(2.25/2.75))*x+.9375;return 7.5625*(x-=(2.625/2.75))*x+.984375;},GRAYSCALE:function(c){var s=(c.r+c.g+c.b)/3;c.r=s;c.g=s;c.b=s;},INVERT:function(c){c.r=255-c.r;c.g=255-c.g;c.b=255-c.b;},LIGHTEN:function(c){c.r+=85;c.g+=85;c.b+=85;},DARKEN:function(c){c.r-=85;c.g-=85;c.b-=85;},_listenerTypes:['first','last','next','previous','play','pause','stop','end'],_id:0});Run._styleAttributes={};['left','top','borderBottomWidth','borderLeftWidth','borderRightWidth','borderTopWidth','bottom','fontSize','height','letterSpacing','lineHeight','marginBottom','marginLeft','marginRight','marginTop','maxHeight','maxWidth','minHeight','minWidth','paddingBottom','paddingLeft','paddingRight','paddingTop','textIndent','width','wordSpacing','MozBorderBottomRadius','MozBorderLeftRadius','MozBorderRadius','MozBorderRightRadius','MozBorderTopRadius'].each(function(attr){Run._styleAttributes[attr]=Dimension;});['backgroundColor','borderBottomColor','borderColor','borderLeftColor','borderRightColor','borderTopColor','color','scrollbar3dLightColor','scrollbarArrowColor','scrollbarBaseColor','scrollbarDarkshadowColor','scrollbarFaceColor','scrollbarHighlightColor','scrollbarShadowColor','scrollbarTrackColor'].each(function(attr){Run._styleAttributes[attr]=Color;});Run._styleAttributes.opacity=Number;Run.flow=Run.LINEAR;