/*
 * jLayers - javascript plugin for creating mouse-driven motion animations
 *
 * @author flGravity 
 * @site http://codecanyon.net/user/flGravity
 * @created 16/06/11
*/

(function(){if(window.jLayers&&typeof window.jLayers=='function')return;window.jLayers=function(d,s){var f={alpha:1,catchGlobalMove:false,cssPosition:undefined,cssLeft:undefined,cssTop:undefined,offsetX:0,offsetY:0,offsetCenter:'center',easing:true,easingRate:50,easingSpeed:3};f.get=function(a,b){var c=this[a];if(b!=undefined&&c instanceof Array){var s=c[b];if(s==undefined)s=c[c.length-1];return s}else{if(typeof c=='boolean')return(c)?-1:1;else return parseInt(c)}};if(s&&typeof s=='object'){for(var g in f){if(s[g]!=undefined)f[g]=s[g]}}if(typeof d=="string"){d=document.getElementById(d)}if(f.cssPosition)d.style.position=f.cssPosition;if(f.cssTop)d.style.top=f.cssTop;if(f.cssLeft)d.style.left=f.cssLeft;var h=new Array();var j=d.firstChild;var k;while(j!=undefined){if(j.nodeType==1){k=document.createElement('div');d.insertBefore(k,j);k.appendChild(j);h.push(k);k.className='jlayers-layer';j.className+=(j.className.length==0)?'jlayers-content':' jlayers-content';j=k}j=j.nextSibling}var i;var a;for(i=0;i<h.length;i++){a=f.get('alpha',i);if(a>1)a=1;if(a<0)a=0;if(navigator.appName.indexOf('Microsoft')==-1){h[i].style.opacity=a.toString()}else{h[i].style.filter='alpha(opacity='+a*100+')'}}var l=function(t){if(t==null){return[0,0]}else{var a=t.offsetLeft;var b=t.offsetTop;var c=arguments.callee(t.offsetParent);return[a+c[0],b+c[1]]}};d.posx=l(d)[0];d.posy=l(d)[1];h.tmpX=0;h.tmpY=0;h.endX=0;h.endY=0;var m=function(){if(Math.abs(h.tmpX-h.endX)>0.0001||Math.abs(h.tmpX-h.endX)>0.0001){h.tmpX+=(h.endX-h.tmpX)/f.easingSpeed;h.tmpY+=(h.endY-h.tmpY)/f.easingSpeed;for(var i=0;i<h.length;i++){h[i].style.left=h.tmpX*f.get('offsetX',i)+'px';h[i].style.top=h.tmpY*f.get('offsetY',i)+'px'}}};var n=function(e){e=e||window.event;var a=e.clientX;var b=e.clientY;if(f.catchGlobalMove==false){a-=d.posx;b-=d.posy}h.endX=2*a/d.offsetWidth-1;h.endY=2*b/d.offsetHeight-1;if(/left/i.test(f.offsetCenter)){h.endX=a/d.offsetWidth}if(/right/i.test(f.offsetCenter)){h.endX=1-a/d.offsetWidth}if(/top/i.test(f.offsetCenter)){h.endY=b/d.offsetHeight}if(/bottom/i.test(f.offsetCenter)){h.endY=1-b/d.offsetHeight}if(f.easing){if(d.timer==undefined)d.timer=setInterval(m,f.easingRate)}else{for(var i=0;i<h.length;i++){h[i].style.left=h.endX*f.get('offsetX',i)+'px';h[i].style.top=h.endY*f.get('offsetY',i)+'px'}}};var o=function(a,b,c){if(a.addEventListener){a.addEventListener(b,c,false)}else if(a.attachEvent){a.attachEvent('on'+b,c)}};o((f.catchGlobalMove)?document:d,'mousemove',n);o(window,'unload',function(){clearInterval(d.timer)});o(window,'resize',function(){d.posx=l(d)[0];d.posy=l(d)[1]});return f};window.jLayers.layerSize=function(a){if(typeof a=='string')a=document.getElementById(a);return{width:a.offsetWidth,height:a.offsetHeight}};window.jLayers.documentSize=function(){if(window.innerWidth)return{width:window.innerWidth,height:window.innerHeight};else if(document.body&&document.body.offsetWidth)return{width:document.body.offsetWidth,height:document.body.offsetHeight};else if(document.documentElement&&document.documentElement.offsetWidth)return{width:document.documentElement.offsetWidth,height:document.documentElement.offsetHeight}}})();

