(function($,W,D){var c={top:function(a){return{top:0-a.height(),left:a.offset().left}},topLeft:function(a){return{top:0-a.height(),left:0-(a.width()/2)}},topRight:function(a){return{top:0-a.height(),left:$(W).width()+(a.width()/2)}},left:function(a){return{top:a.offset().top,left:0-a.width()}},right:function(a){return{top:a.offset().top,left:$(W).width()+a.width()}},btmLeft:function(a){return{top:getWindowHeight()+a.height(),left:0-(a.width()/2)}},btmRight:function(a){return{top:getWindowHeight()+a.height(),left:getWindowHeight()+(a.width()/2)}},btm:function(a){return{top:getWindowHeight(),left:a.offset().left}}};function getWindowHeight(){return W.innerHeight||$(window).height()}function randDirection(){var a=[],count=0;for(var i in c){a.push(i);count++}return a[parseInt(Math.random()*count,10)]}function prepareOverflow(){var a=$(D).width()<=$(W).width(),oY=$(D).height()<=$(W).height(),oR=a&&oY;a&&$('body').css('overflow-x','hidden');oY&&$('body').css('overflow-y','hidden');oR&&$('body').css('overflow','hidden')}function flyElement(s){var b=$(this),direction=s.direction.toLowerCase()==='random'?randDirection():s.direction,tweens=$.extend(s.tween,c[direction](b)),positionProps='position,left,top,bottom,right,width,height,paddingTop,paddingRight,paddingBottom,paddingLeft,marginTop,marginRight,marginBottom,marginLeft,zIndex,overflow,clip,display',clone=$(b.clone()).removeAttr('id').attr('id','replaced-element-'+(+new Date())).css((function(){var a=positionProps.split(','),length=a.length,d styles={};while(length--){styles[a[length]]=b.css(a[length])}return styles})());prepareOverflow();$(b).css({left:tweens.left?b.offset().left:null,top:tweens.top?b.offset().top:null,position:'absolute',zIndex:999,width:b.outerWidth(),height:b.outerHeight()}).animate(tweens,s.duration,function(){b.remove()}).filter(function(){return!!s.retainSpace}).before($(clone).css('opacity',0));if(s.retainSpace&&typeof s.retainSpace==='object'){$(clone).animate(s.retainSpace,s.duration,function(){$(this).remove()})}}$.fn.flyOffPage=function(a){var s=$.extend({direction:'random',tween:{},retainSpace:true,duration:500},a);return this.each(function(){flyElement.call(this,s)})}})(jQuery,window,document);