//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2008 Valerio Proietti, <http://mad4milk.net>, MIT Style License.

Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(a,b){this.elements=this.subject=$$(a);this.parent(b)},compute:function(a,b,c){var d={};for(var i in a){var e=a[i],iTo=b[i],iNow=d[i]={};for(var p in e)iNow[p]=this.parent(e[p],iTo[p],c)}return d},set:function(a){for(var i in a){var b=a[i];for(var p in b)this.render(this.elements[i],p,b[p],this.options.unit)}return this},start:function(a){if(!this.check(arguments.callee,a))return this;var b={},to={};for(var i in a){var c=a[i],iFrom=b[i]={},iTo=to[i]={};for(var p in c){var d=this.prepare(this.elements[i],p,c[p]);iFrom[p]=d.from;iTo[p]=d.to}}return this.parent(b,to)}});var Color=new Native({initialize:function(a,b){if(arguments.length>=3){b="rgb";a=Array.slice(arguments,0,3)}else if(typeof a=='string'){if(a.match(/rgb/))a=a.rgbToHex().hexToRgb(true);else if(a.match(/hsb/))a=a.hsbToRgb();else a=a.hexToRgb(true)}b=b||'rgb';switch(b){case'hsb':var c=a;a=a.hsbToRgb();a.hsb=c;break;case'hex':a=a.hexToRgb(true);break}a.rgb=a.slice(0,3);a.hsb=a.hsb||a.rgbToHsb();a.hex=a.rgbToHex();return $extend(a,this)}});Color.implement({mix:function(){var b=Array.slice(arguments);var c=($type(b.getLast())=='number')?b.pop():50;var d=this.slice();b.each(function(a){a=new Color(a);for(var i=0;i<3;i++)d[i]=Math.round((d[i]/100*(100-c))+(a[i]/100*c))});return new Color(d,'rgb')},invert:function(){return new Color(this.map(function(a){return 255-a}))},setHue:function(a){return new Color([a,this.hsb[1],this.hsb[2]],'hsb')},setSaturation:function(a){return new Color([this.hsb[0],a,this.hsb[2]],'hsb')},setBrightness:function(a){return new Color([this.hsb[0],this.hsb[1],a],'hsb')}});function $RGB(r,g,b){return new Color([r,g,b],'rgb')};function $HSB(h,s,b){return new Color([h,s,b],'hsb')};function $HEX(a){return new Color(a,'hex')};Array.implement({rgbToHsb:function(){var a=this[0],green=this[1],blue=this[2];var b,saturation,brightness;var c=Math.max(a,green,blue),min=Math.min(a,green,blue);var d=c-min;brightness=c/255;saturation=(c!=0)?d/c:0;if(saturation==0){b=0}else{var e=(c-a)/d;var f=(c-green)/d;var g=(c-blue)/d;if(a==c)b=g-f;else if(green==c)b=2+e-g;else b=4+f-e;b/=6;if(b<0)b++}return[Math.round(b*360),Math.round(saturation*100),Math.round(brightness*100)]},hsbToRgb:function(){var a=Math.round(this[2]/100*255);if(this[1]==0){return[a,a,a]}else{var b=this[0]%360;var f=b%60;var p=Math.round((this[2]*(100-this[1]))/10000*255);var q=Math.round((this[2]*(6000-this[1]*f))/600000*255);var t=Math.round((this[2]*(6000-this[1]*(60-f)))/600000*255);switch(Math.floor(b/60)){case 0:return[a,t,p];case 1:return[q,a,p];case 2:return[p,a,t];case 3:return[p,q,a];case 4:return[t,p,a];case 5:return[a,p,q]}}return false}});String.implement({rgbToHsb:function(){var a=this.match(/\d{1,3}/g);return(a)?hsb.rgbToHsb():null},hsbToRgb:function(){var a=this.match(/\d{1,3}/g);return(a)?a.hsbToRgb():null}});var Tips=new Class({Implements:[Events,Options],options:{onShow:function(a){a.setStyle('visibility','visible')},onHide:function(a){a.setStyle('visibility','hidden')},showDelay:100,hideDelay:100,className:null,offsets:{x:16,y:16},fixed:false},initialize:function(){var a=Array.link(arguments,{options:Object.type,elements:$defined});this.setOptions(a.options||null);this.tip=new Element('div').inject(document.body);if(this.options.className)this.tip.addClass(this.options.className);var b=new Element('div',{'class':'tip-top'}).inject(this.tip);this.container=new Element('div',{'class':'tip'}).inject(this.tip);var c=new Element('div',{'class':'tip-bottom'}).inject(this.tip);this.tip.setStyles({position:'absolute',top:0,left:0,visibility:'hidden'});if(a.elements)this.attach(a.elements)},attach:function(g){$$(g).each(function(a){var b=a.retrieve('tip:title',a.get('title'));var c=a.retrieve('tip:text',a.get('rel')||a.get('href'));var d=a.retrieve('tip:enter',this.elementEnter.bindWithEvent(this,a));var e=a.retrieve('tip:leave',this.elementLeave.bindWithEvent(this,a));a.addEvents({mouseenter:d,mouseleave:e});if(!this.options.fixed){var f=a.retrieve('tip:move',this.elementMove.bindWithEvent(this,a));a.addEvent('mousemove',f)}a.store('tip:native',a.get('title'));a.erase('title')},this);return this},detach:function(c){$$(c).each(function(a){a.removeEvent('mouseenter',a.retrieve('tip:enter')||$empty);a.removeEvent('mouseleave',a.retrieve('tip:leave')||$empty);a.removeEvent('mousemove',a.retrieve('tip:move')||$empty);a.eliminate('tip:enter').eliminate('tip:leave').eliminate('tip:move');var b=a.retrieve('tip:native');if(b)a.set('title',b)});return this},elementEnter:function(a,b){$A(this.container.childNodes).each(Element.dispose);var c=b.retrieve('tip:title');if(c){this.titleElement=new Element('div',{'class':'tip-title'}).inject(this.container);this.fill(this.titleElement,c)}var d=b.retrieve('tip:text');if(d){this.textElement=new Element('div',{'class':'tip-text'}).inject(this.container);this.fill(this.textElement,d)}this.timer=$clear(this.timer);this.timer=this.show.delay(this.options.showDelay,this);this.position((!this.options.fixed)?a:{page:b.getPosition()})},elementLeave:function(a){$clear(this.timer);this.timer=this.hide.delay(this.options.hideDelay,this)},elementMove:function(a){this.position(a)},position:function(a){var b=window.getSize(),scroll=window.getScroll();var c={x:this.tip.offsetWidth,y:this.tip.offsetHeight};var d={x:'left',y:'top'};for(var z in d){var e=a.page[z]+this.options.offsets[z];if((e+c[z]-scroll[z])>b[z])e=a.page[z]-this.options.offsets[z]-c[z];this.tip.setStyle(d[z],e)}},fill:function(a,b){(typeof b=='string')?a.set('html',b):a.adopt(b)},show:function(){this.fireEvent('show',this.tip)},hide:function(){this.fireEvent('hide',this.tip)}});var Accordion=new Class({Extends:Fx.Elements,options:{display:0,show:false,height:true,width:false,opacity:true,fixedHeight:false,fixedWidth:false,wait:false,alwaysHide:false},initialize:function(){var c=Array.link(arguments,{'container':Element.type,'options':Object.type,'togglers':$defined,'elements':$defined});this.parent(c.elements,c.options);this.togglers=$$(c.togglers);this.container=$(c.container);this.previous=-1;if(this.options.alwaysHide)this.options.wait=true;if($chk(this.options.show)){this.options.display=false;this.previous=this.options.show}if(this.options.start){this.options.display=false;this.options.show=false}this.effects={};if(this.options.opacity)this.effects.opacity='fullOpacity';if(this.options.width)this.effects.width=this.options.fixedWidth?'fullWidth':'offsetWidth';if(this.options.height)this.effects.height=this.options.fixedHeight?'fullHeight':'scrollHeight';for(var i=0,l=this.togglers.length;i<l;i++)this.addSection(this.togglers[i],this.elements[i]);this.elements.each(function(a,i){if(this.options.show===i){this.fireEvent('active',[this.togglers[i],a])}else{for(var b in this.effects)a.setStyle(b,0)}},this);if($chk(this.options.display))this.display(this.options.display)},addSection:function(a,b,c){a=$(a);b=$(b);var d=this.togglers.contains(a);var e=this.togglers.length;this.togglers.include(a);this.elements.include(b);if(e&&(!d||c)){c=$pick(c,e-1);a.inject(this.togglers[c],'before');b.inject(a,'after')}else if(this.container&&!d){a.inject(this.container);b.inject(this.container)}var f=this.togglers.indexOf(a);a.addEvent('click',this.display.bind(this,f));if(this.options.height)b.setStyles({'padding-top':0,'border-top':'none','padding-bottom':0,'border-bottom':'none'});if(this.options.width)b.setStyles({'padding-left':0,'border-left':'none','padding-right':0,'border-right':'none'});b.fullOpacity=1;if(this.options.fixedWidth)b.fullWidth=this.options.fixedWidth;if(this.options.fixedHeight)b.fullHeight=this.options.fixedHeight;b.setStyle('overflow','hidden');if(!d){for(var g in this.effects)b.setStyle(g,0)}return this},display:function(d){d=($type(d)=='element')?this.elements.indexOf(d):d;if((this.timer&&this.options.wait)||(d===this.previous&&!this.options.alwaysHide))return this;this.previous=d;var e={};this.elements.each(function(a,i){e[i]={};var b=(i!=d)||(this.options.alwaysHide&&(a.offsetHeight>0));this.fireEvent(b?'background':'active',[this.togglers[i],a]);for(var c in this.effects)e[i][c]=b?0:a[this.effects[c]]},this);return this.start(e)}});