// Copyright (c) 2007-2008 Chris Schneider, <http://www.chrisbk.de>
// a cow makes moo, this script too. requires mootools 1.2b or compatible.
// MIT-style licence

var CssEffects={prefix:"-moofx",initialValues:{duration:"0ms",property:"all",transition:"sine-in-out"}};if(!Browser.Engine.trident4&&!Browser.Engine.presto){(function(){CssEffects.Rule=new Class({initialize:function(c){this.importances=new Hash();this.values=new Hash();this.selector=c.replace(/:active|:focus|:hover/ig,"");this.dynamicPseudos=c.match(/(:active|:focus|:hover)/ig)||[];this.specificity=(function(){var f=c.replace(/:(before|after|first-letter|first-line)/,"");var e=f.match(/#/g);e=e?e.length:0;var d=f.match(/\[|\:|\./g);d=d?d.length:0;var g=f.match(/( |\+|>)[a-z]+/ig);g=g?g.length:0;if(f.match(/^[a-z]+/i)){g++}return 100*e+10*d+g})();this.use()},addDeclaration:function(e,d,c){if(!e){return this.addShortHand(d,c)}if(!this.importances.has(e)||this.importances.get(e)<=c){if(d.contains(",")){d=d.split(/\s*,\s*/)}this.values.set(e,d);this.importances.set(e,c)}return this},addShortHand:function(d,c){d.match(/([^\s,]+\s*,\s*)+[^\s,]+|[^\s,]+/gi).each(function(f){var e=(f.match(/\d+ms/)||CssEffects.Durations.has(f))?"duration":(CssEffects.Transitions.has(f))?"transition":"property";this.addDeclaration(e,f,c)},this);return this},use:function(){$$(this.selector).each(function(c){CssEffects.Element.getInstance(c).addRule(this)},this)}});CssEffects.Parser={addCss:function(g){var f=new RegExp("(?:\\s)*([^{}]+?)\\s*{([^}]*"+CssEffects.prefix+"[^}]*)}","gi");var d=new RegExp(CssEffects.prefix+"(?:-?([a-z\\-]+))?\\s*:\\s*([^;]+?)\\s*(!important)?\\s*;","gi");while(a=f.exec(g)){var e=a[1].split(/\s*,\s*/);rules=e.map(function(h){return new CssEffects.Rule(h)});while(b=d.exec(a[2])){var c=(b[3]=="!important")?2:1;rules.each(function(h){h.addDeclaration(b[1],b[2],c)})}}return this},addStylesheet:function(c){switch(c.get("tag")){case"style":this.addCss(c.get("html"));break;case"link":new Request({onSuccess:function(d){this.addCss(d)}.bind(this),url:c.href,method:"get"}).send()}return this},processDocument:function(){$each(document.styleSheets,function(d){var c=$(d[d.ownerNode?"ownerNode":"owningElement"]);this.addStylesheet(c)},this);return this}};CssEffects.Element=new Class({initialize:function(c){this.element=c;c.store("CssEffects",this);this.previous={};this.dynamicPseudos=[];this.rules=[];this.styleAttribute="";this.saveStyleAttribute();this.effect=new Fx.Morph(this.element,{onCancel:function(){this.previous=this.getStyles(this.dynamicPseudos)}.bind(this),onComplete:this.element.setStyles.bind(this.element,this.previous)});(function(){this.previous=this.getStyles();c.setStyles(this.previous)}).delay(1,this);CssEffects.DynamicPseudos.each(function(e,d){["begin","end"].each(function(f){$splat(e[f]).each(function(g){c.addEvent(g,this.change.bind(this,[f,d]))},this)},this)},this)},change:function(c,d){d=d||"";(function(){if(d.length>0){if(c=="end"&&!this.dynamicPseudos.contains(d)){return}this.dynamicPseudos.push(d)}this.effect.cancel();this.restoreStyleAttribute();var e=this.getStyles(this.dynamicPseudos);this.element.setStyles(this.previous);var h={};Hash.each(e,function(i,j){if(!$defined(this.previous[j])||this.previous[j]!=i){h[j]=e[j]}},this);var f=this.getOwnStyle("duration",this.dynamicPseudos);var g=this.getOwnStyle("transition",this.dynamicPseudos);this.effect.options.duration=f.match(/\d+ms/)?f.toInt():CssEffects.Durations.get(f);this.effect.options.transition=CssEffects.Transitions.get(g);this.effect.start(h);this.previous=e}).delay(1,this);return this},addRule:function(c){this.rules.include(c);return this},hasRule:function(c){return this.rules.contains(c)},removeRule:function(c){this.rules.erase(c);return this},getOwnStyle:function(h,d){d=d||[];var f=d.sort().join("$");var i=this.rules.filter(function(k){var j=k.dynamicPseudos.sort().join("$");return(!j||k.values.has(h)&&f==j)});var g=CssEffects.initialValues[h];var c=0,e=0;i.each(function(k){var j=k.importances.get(h);if(j>c||(j==c&&k.specificity>=e)){c=j;e=k.specificity;g=k.values.get(h)}});return g},getStyles:function(c){var d=this.getOwnStyle("property",c);if(d=="none"){return{}}d=(d=="all")?CssEffects.Properties:$splat(d);return this.element.getStyles.apply(this.element,d)},saveStyleAttribute:function(){this.styleAttribute=this.element.get("style")||"";return this},restoreStyleAttribute:function(){return this.element.set("style",this.styleAttribute)}});CssEffects.Element.getInstance=function(c){return c.retrieve("CssEffects")||new CssEffects.Element(c)};CssEffects.Durations=new Hash({"short":250,normal:500,"long":750});CssEffects.Properties=["backgroundColor","backgroundPosition","borderBottomColor","borderBottomStyle","borderBottomWidth","borderLeftColor","borderLeftStyle","borderLeftWidth","borderRightColor","borderRightStyle","borderRightWidth","borderTopColor","borderTopStyle","borderTopWidth","bottom","color","fontSize","fontWeight","height","left","letterSpacing","lineHeight","marginBottom","marginLeft","marginRight","marginTop","maxHeight","maxWidth","opacity","paddingBottom","paddingLeft","paddingRight","paddingTop","right","textIndent","top","width","zIndex","zoom"];CssEffects.DynamicPseudos=new Hash({":active":{begin:"mousedown",end:["mouseup","mouseout"]},":focus":{begin:"focus",end:"blur"},":hover":{begin:"mouseenter",end:"mouseleave"}});CssEffects.Transitions=new Hash({linear:Fx.Transitions.linear});["Quad","Cubic","Quart","Quint","Expo","Circ","Sine","Back","Bounce","Elastic"].each(function(c){["In","Out","InOut"].each(function(e){var d=c.toLowerCase()+e.hyphenate().toLowerCase();CssEffects.Transitions.set(d,Fx.Transitions[c]["ease"+e])})});window.addEvent("domready",CssEffects.Parser.processDocument.bind(CssEffects.Parser))})()};