/**
 * RokParallax - Parallax showcase
 * 
 * @version		1.1
 * 
 * @author		Djamil Legato <djamil@rockettheme.com>
 * @copyright	Andy Miller @ Rockettheme, LLC
 */

var RokParallax=new Class({version:'1.1',options:{limits:[160,100,50],unit:(!window.opera)?'%':'',mouse:'showcase'},initialize:function(layouts,options){this.setOptions(options);if(window.gecko&&!document.getElementByClassName)this.ff2=true;this.layouts=$$(layouts);this.main=this.layouts[0];this.mainSize=this.main.getSize().size;this.center=this.getCenter();this.positions=this.getOriginalPositions();var unit=this.options.unit;if(!window.opera){this.layouts.each(function(layout){var bgpos=this.getBackground(layout);layout.fx=new Fx.Style(layout,'background-position',{wait:false,duration:150,unit:unit,onComplete:function(){this.element.anim=false}}).set((window.ie)?layout.getStyle('background-position-x')+' '+layout.getStyle('background-position-y'):bgpos[0]+' '+bgpos[1])},this)};if(window.gecko){this.layouts.each(function(layout){layout.setStyle('font-family',$(document.body).getStyle('font-family'))})};this.attachEvents()},attachEvents:function(){var self=this;var movement=(this.options.mouse=='showcase')?$(this.layouts[this.layouts.length-1]):$(document.body);movement.addEvents({'mouseenter':function(e){e=new Event(e);self.mouse=e.client;self.layouts.each(function(layout,i){var position={x:(e.client.x*self.options.limits[i]/ (self.mainSize.x/2))-self.options.limits[i],y:(window.opera)?(!i)?0:100:self.positions[i].y};position.x+=(window.opera)?0:self.positions[i].x;layout.anim=(window.opera)?false:true;self.setBackground(layout,position,(window.opera)?false:true)})},'mousemove':function(e){e=new Event(e);self.layouts.each(function(layout,i){if(layout.anim)return;var position={x:(e.client.x*self.options.limits[i]/ (self.mainSize.x/2))-self.options.limits[i],y:(window.opera)?(!i)?0:100:self.positions[i].y};position.x+=(window.opera)?0:self.positions[i].x;self.setBackground(layout,position)})}})},getCenter:function(){return{x:this.mainSize.x/2,y:this.mainSize.y/2}},getOriginalPositions:function(){var positions=[];this.layouts.each(function(layout){positions.push(this.getBackground(layout))},this);return positions},getBackground:function(el){var coords={x:0,y:0};if(window.ie){coords={x:el.getStyle('background-position-x').replace('%','','g').replace('px','','g').toInt(),y:el.getStyle('background-position-y').replace('%','','g').replace('px','','g').toInt()}}else if(this.ff2){var bg=el.getStyle('font-family').replace('"',"",'g').replace('%','','g').replace('px','','g').split(' ');coords={x:bg[0].toInt(),y:bg[1].toInt()+'%'}}else if(window.opera){var bg=el.getStyle('background-position').replace('%','','g').replace('px','','g').split(' ');coords={x:bg[0].toInt(),y:bg[1].toInt()+'%'}}else{var bg=el.getStyle('background-position').replace('%','','g').replace('px','','g').split(' ');coords={x:bg[0].toInt(),y:bg[1].toInt()}};return coords},setBackground:function(el,position,animated){var unit=this.options.unit;if(window.opera&&position.y!=0)position.y='100%';if(this.ff2){position.x=position.x.toInt();position.y=position.y.toInt()};if(!animated)return el.setStyle('background-position',position.x+unit+' '+position.y+unit);else return el.fx.start(position.x+unit+' '+position.y+unit)}});RokParallax.implement(new Options,new Events);

