(function(e,t,n,o){e.fn.shape=function(t){var i,a=e(this),s=e.extend(!0,{},e.fn.shape.settings,t),r="."+s.namespace,l="module-"+s.namespace,c=arguments[0],u=[].slice.call(arguments,1),d="string"==typeof c;return a.each(function(){var t,a,f,p=e(this),m=p.find(s.selector.shape),g=p.find(s.selector.side),h="transitionend msTransitionEnd oTransitionEnd",v=(p.selector||"",this),b=p.data(l),y=(s.namespace,s.error),x=s.className;f={initialize:function(){f.verbose("Initializing module for",v),f.set.defaultSide(),b=f,p.data(l,b)},destroy:function(){f.verbose("Destroying previous module for",v),p.removeData(l).off(r)},refresh:function(){f.verbose("Refreshing selector cache for",v),p=e(v),m=e(this).find(s.selector.shape),g=e(this).find(s.selector.side)},repaint:function(){f.verbose("Forcing repaint event");var e=m.get(0)||n.createElement("div");e.offsetWidth},animate:function(n,o){f.verbose("Animating box with properties",n),o=o||function(t){f.reset(),f.set.active(),e.proxy(s.onChange,a)(),t.stopImmediatePropagation()},s.useCSS?(f.verbose("Starting CSS animation"),p.addClass(x.animating),f.set.stageSize(),f.repaint(),p.addClass(x.css),t.addClass(x.hidden),m.css(n).one(h,o)):(f.verbose("Starting javascript animation"),p.addClass(x.animating).removeClass(x.css),f.set.stageSize(),f.repaint(),t.animate({opacity:0},s.duration,s.easing),m.animate(n,s.duration,s.easing,o))},queue:function(e){f.debug("Queueing animation of",e),m.one(h,function(){f.debug("Executing queued animation"),p.shape(e)})},reset:function(){f.verbose("Animating states reset"),p.removeClass(x.css).removeClass(x.animating).removeAttr("style"),m.removeAttr("style"),g.removeAttr("style").removeClass(x.hidden),a.removeClass(x.animating).removeAttr("style")},is:{animating:function(){return p.hasClass(x.animating)}},get:{nextSide:function(){return t.next(s.selector.side).size()>0?t.next(s.selector.side):p.find(s.selector.side).first()}},set:{defaultSide:function(){t=p.find("."+s.className.active),a=t.next(s.selector.side).size()>0?t.next(s.selector.side):p.find(s.selector.side).first(),f.verbose("Active side set to",t),f.verbose("Next side set to",a)},stageSize:function(){var e={width:a.outerWidth(),height:a.outerHeight()};f.verbose("Resizing stage to fit new content",e),p.css({width:e.width,height:e.height})},nextSide:function(e){a=p.find(e),0===a.size()&&f.error(y.side),f.verbose("Next side manually set to",a)},active:function(){f.verbose("Setting new side to active",a),g.removeClass(x.active),a.addClass(x.active),f.set.defaultSide()}},flip:{up:function(){f.debug("Flipping up",a),f.is.animating()?f.queue("flip.up"):(f.stage.above(),f.animate(f.getTransform.up()))},down:function(){f.debug("Flipping down",a),f.is.animating()?f.queue("flip.down"):(f.stage.below(),f.animate(f.getTransform.down()))},left:function(){f.debug("Flipping left",a),f.is.animating()?f.queue("flip.left"):(f.stage.left(),f.animate(f.getTransform.left()))},right:function(){f.debug("Flipping right",a),f.is.animating()?f.queue("flip.right"):(f.stage.right(),f.animate(f.getTransform.right()))},over:function(){f.debug("Flipping over",a),f.is.animating()?f.queue("flip.over"):(f.stage.behind(),f.animate(f.getTransform.behind()))}},getTransform:{up:function(){var e={y:-((t.outerHeight()-a.outerHeight())/2),z:-(t.outerHeight()/2)};return{transform:"translateY("+e.y+"px) translateZ("+e.z+"px) rotateX(-90deg)"}},down:function(){var e={y:-((t.outerHeight()-a.outerHeight())/2),z:-(t.outerHeight()/2)};return{transform:"translateY("+e.y+"px) translateZ("+e.z+"px) rotateX(90deg)"}},left:function(){var e={x:-((t.outerWidth()-a.outerWidth())/2),z:-(t.outerWidth()/2)};return{transform:"translateX("+e.x+"px) translateZ("+e.z+"px) rotateY(90deg)"}},right:function(){var e={x:-((t.outerWidth()-a.outerWidth())/2),z:-(t.outerWidth()/2)};return{transform:"translateX("+e.x+"px) translateZ("+e.z+"px) rotateY(-90deg)"}},behind:function(){var e={x:-((t.outerWidth()-a.outerWidth())/2)};return{transform:"translateX("+e.x+"px) rotateY(180deg)"}}},stage:{above:function(){var e={origin:(t.outerHeight()-a.outerHeight())/2,depth:{active:a.outerHeight()/2,next:t.outerHeight()/2}};f.verbose("Setting the initial animation position as above",a,e),t.css({transform:"rotateY(0deg) translateZ("+e.depth.active+"px)"}),a.addClass(x.animating).css({display:"block",top:e.origin+"px",transform:"rotateX(90deg) translateZ("+e.depth.next+"px)"})},below:function(){var e={origin:(t.outerHeight()-a.outerHeight())/2,depth:{active:a.outerHeight()/2,next:t.outerHeight()/2}};f.verbose("Setting the initial animation position as below",a,e),t.css({transform:"rotateY(0deg) translateZ("+e.depth.active+"px)"}),a.addClass(x.animating).css({display:"block",top:e.origin+"px",transform:"rotateX(-90deg) translateZ("+e.depth.next+"px)"})},left:function(){var e={origin:(t.outerWidth()-a.outerWidth())/2,depth:{active:a.outerWidth()/2,next:t.outerWidth()/2}};f.verbose("Setting the initial animation position as left",a,e),t.css({transform:"rotateY(0deg) translateZ("+e.depth.active+"px)"}),a.addClass(x.animating).css({display:"block",left:e.origin+"px",transform:"rotateY(-90deg) translateZ("+e.depth.next+"px)"})},right:function(){var e={origin:(t.outerWidth()-a.outerWidth())/2,depth:{active:a.outerWidth()/2,next:t.outerWidth()/2}};f.verbose("Setting the initial animation position as left",a,e),t.css({transform:"rotateY(0deg) translateZ("+e.depth.active+"px)"}),a.addClass(x.animating).css({display:"block",left:e.origin+"px",transform:"rotateY(90deg) translateZ("+e.depth.next+"px)"})},behind:function(){var e={origin:(t.outerWidth()-a.outerWidth())/2,depth:{active:a.outerWidth()/2,next:t.outerWidth()/2}};f.verbose("Setting the initial animation position as behind",a,e),t.css({transform:"rotateY(0deg)"}),a.addClass(x.animating).css({display:"block",left:e.origin+"px",transform:"rotateY(-180deg)"})}},setting:function(t,n){if(e.isPlainObject(t))e.extend(!0,s,t);else{if(n===o)return s[t];s[t]=n}},verbose:function(){s.verbose&&f.debug.apply(this,arguments)},debug:function(){var e=[],t=s.moduleName+": "+arguments[0],n=[].slice.call(arguments,1),o=console.info||console.log||function(){};o=Function.prototype.bind.call(o,console),s.debug&&(e.push(t),o.apply(console,e.concat(n)))},error:function(){var e=[],t=s.moduleName+": "+arguments[0],n=[].slice.call(arguments,1),o=console.warn||console.log||function(){};o=Function.prototype.bind.call(o,console),s.debug&&(e.push(t),e.concat(n),o.apply(console,e.concat(n)))},invoke:function(t,n,i){var a,s;return n=n||u||[].slice.call(arguments,2),i=v||i,"string"==typeof t&&b!==o&&(t=t.split("."),a=t.length-1,e.each(t,function(t,n){return e.isPlainObject(b[n])&&t!=a?(b=b[n],!0):b[n]!==o?(s=b[n],!0):(f.error(y.method),!1)})),e.isFunction(s)?(f.verbose("Executing invoked function",s),s.apply(i,n)):s||!1}},d?(b===o&&f.initialize(),i=f.invoke(c)):(b!==o&&f.destroy(),f.initialize())}),i?i:this},e.fn.shape.settings={moduleName:"Shape Module",debug:!0,verbose:!0,namespace:"shape",beforeChange:function(){},onChange:function(){},useCSS:!0,duration:1e3,easing:"easeInOutQuad",error:{side:"You tried to switch to a side that does not exist.",method:"The method you called is not defined"},className:{css:"css",animating:"animating",hidden:"hidden",active:"active"},selector:{shape:".shape",side:".side"}}})(jQuery,window,document);