/**
 * Additional visual effects module
 *
 * Copyright (C) 2008-2010 Nikolay V. Nemshilov
 */
if (!self.Fx) throw "RightJS Fx is missing";Fx.Move=new Class(Fx.Morph,{extend:{Options:Object.merge(Fx.Options,{duration:'long',position:'absolute'})},prepare:function(e){return this.$super(this.getEndPosition(e))},getEndPosition:function(e){var b=this.element.getStyle('position'),a={};if(b!='absolute'||b!='relative')this.element.style.position=b=b=='fixed'?'absolute':'relative';if(e.top)e.y=e.top.toInt();if(e.left)e.x=e.left.toInt();var c=this.element.position();var p=this.getParentPosition();var r=c.x-p.x;var d=c.y-p.y;if(this.options.position=='relative'){if(b=='absolute'){if(defined(e.x))e.x+=c.x;if(defined(e.y))e.y+=c.x}else{if(defined(e.x))e.x+=r;if(defined(e.y))e.y+=d}}else if(b=='relative'){if(defined(e.x))e.x+=r-c.x;if(defined(e.y))e.y+=d-c.y}for(var k in e)switch(k){case 'top':case 'left':break;case 'y':a.top=e.y+'px';break;case 'x':a.left=e.x+'px';break;default:a[k]=e[k]}return a},getParentPosition:function(){Fx.Move.Dummy=Fx.Move.Dummy||new Element('div',{style:'width:0;height:0;visibility:hidden'});this.element.insert(Fx.Move.Dummy,'before');var p=Fx.Move.Dummy.position();Fx.Move.Dummy.remove();return p}});Fx.Zoom=new Class(Fx.Move,{PROPERTIES:$w('width height lineHeight paddingTop paddingRight paddingBottom paddingLeft fontSize borderWidth'),extend:{Options:Object.merge(Fx.Move.Options,{position:'relative',duration:'normal',from:'center'})},prepare:function(s,a){return this.$super(this._getZoomedStyle(s,a))},_getZoomedStyle:function(s,a){var p=this._getProportion(s);return Object.merge(this._getBasicStyle(p),this._getEndPosition(p),a||{})},_getProportion:function(s){if(isHash(s)){var a=$E('div').insertTo($E('div',{style:"visibility:hidden;float:left;height:0;width:0"}).insertTo(document.body)).setStyle(s).sizes();if(s.height)s=a.y/this.element.sizes().y;else s=a.x/this.element.sizes().x}else if(isString(s))s=s.endsWith('%')?s.toFloat()/100:s.toFloat();return s},_getBasicStyle:function(p){var s=this._cloneStyle(this.element,this.PROPERTIES),r=/([\d\.]+)/g;for(var k in s){if(k==='width'||k==='height')s[k]=s[k]||(this.element['offset'+k.capitalize()]+'px');if(s[k].match(r))s[k]=s[k].replace(r,function(a){return ''+(a.toFloat()*p)});else delete(s[k])}if(s.borderWidth&&s.borderWidth.toFloat()<1)s.borderWidth='1px';return s},_getEndPosition:function(a){var p={};var s=this.element.sizes();var x=s.x*(a-1);var y=s.y*(a-1);switch(this.options.from.replace('-',' ').split(' ').sort().join('_')){case 'top':p.x=-x/2;break;case 'right':p.x=-x;p.y=-y/2;break;case 'bottom':p.x=-x/2;case 'bottom_left':p.y=-y;break;case 'bottom_right':p.y=-y;case 'right_top':p.x=-x;break;case 'center':p.x=-x/2;case 'left':p.y=-y/2;break;default:}return p}});Fx.Bounce=new Class(Fx,{extend:{Options:Object.merge(Fx.Options,{duration:'short',direction:'top',value:16})},prepare:function(v){v=v||this.options.value;var p=this.element.position();var a=Fx.Durations[this.options.duration]||this.options.duration;var m={duration:a,position:'relative'};var k='y';switch(this.options.direction){case 'right':v=-v;case 'left':k='x';break;case 'bottom':v=-v}var u={},d={};u[k]=-v;d[k]=v;new Fx.Move(this.element,m).start(u);new Fx.Move(this.element,m).start(d);this.finish.bind(this).delay(1);return this}});Fx.Run=new Class(Fx.Move,{extend:{Options:Object.merge(Fx.Move.Options,{direction:'left'})},prepare:function(h){var h=h||'toggle',p={},d=this.element.dimensions(),t=80;if(h=='out'||(h=='toggle'&&this.element.visible())){if(this.options.direction=='left')p.x=-d.width-t;else p.y=-d.height-t;this.onFinish(function(){this.element.hide().setStyle(this.getEndPosition({x:d.left,y:d.top}))})}else{d=this.element.setStyle('visibility: hidden').show().dimensions();var a={};if(this.options.direction=='left'){a.x=-d.width-t;p.x=d.left}else{a.y=-d.height-t;p.y=d.top}this.element.setStyle(this.getEndPosition(a)).setStyle('visibility: visible')}return this.$super(p)}});Fx.Puff=new Class(Fx.Zoom,{extend:{Options:Object.merge(Fx.Zoom.Options,{size:1.4})},prepare:function(h){var h=h||'toggle',o=0,s=this.options.size;if(h=='out'||(h=='toggle'&&this.element.visible())){var i=this.getEndPosition(this._getZoomedStyle(1));this.onFinish(function(){i.opacity=1;this.element.hide().setStyle(i)})}else{this.element.setStyle('visibility: visible').show();var w=this.element.offsetWidth;var i=this.getEndPosition(this._getZoomedStyle(1));this.onFinish(function(){this.element.setStyle(i)});this.element.setStyle(Object.merge(this.getEndPosition(this._getZoomedStyle(s)),{opacity:0,visibility:'visible'}));s=w/this.element.offsetWidth;o=1}return this.$super(s,{opacity:o})}});Fx.CSS=new Class(Fx.Morph,{STYLES:$w('width height lineHeight opacity border padding margin color fontSize background top left right bottom'),prepare:function(a,r){this.addClass=a||'';this.removeClass=r||'';if(a)this.onFinish(this.element.addClass.bind(this.element,a));if(r)this.onFinish(this.element.removeClass.bind(this.element,r));return this.$super({})},_endStyle:eval("({f:"+Fx.Morph.prototype._endStyle.toString().replace(/(\.setStyle\(\w+\))/,'$1.addClass(this.addClass).removeClass(this.removeClass)')+"})").f,_styleKeys:function(){var h={};this.STYLES.each(function(n){h[n]=1});return this.$super(h)}});Element.include({move:function(p,o){return this.fx('move',[p,o||{}])},bounce:function(){return this.fx('bounce',arguments)},zoom:function(s,o){return this.fx('zoom',[s,o||{}])},run:function(){return this.fx('run',arguments)},puff:function(){return this.fx('puff',arguments)},morphToClass:function(){var a=$A(arguments);if(a[0]===null)a[0]='';return this.fx('CSS',a)}});