(function(n){var i=function(t,i){t.data("flipped",!0);var u="rotate"+t.data("axis");t.find(t.data("front")).css({transform:u+(t.data("reverse")?"(-180deg)":"(180deg)"),"z-index":"0"});t.find(t.data("back")).css({transform:u+"(0deg)","z-index":"1"});t.one(r(),function(){n(this).trigger("flip:done");i!==undefined&&i.call(this)})},t=function(t,i){t.data("flipped",!1);var u="rotate"+t.data("axis");t.find(t.data("front")).css({transform:u+"(0deg)","z-index":"1"});t.find(t.data("back")).css({transform:u+(t.data("reverse")?"(180deg)":"(-180deg)"),"z-index":"0"});t.one(r(),function(){n(this).trigger("flip:done");i!==undefined&&i.call(this)})},r=function(){var n,i=document.createElement("fakeelement"),t={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(n in t)if(i.style[n]!==undefined)return t[n]},u;n.fn.flip=function(r,f){return typeof r=="function"&&(f=r),this.each(function(){var e=n(this),o,h,l,a,s,v,c;if(r!==undefined&&(typeof r=="boolean"||typeof r=="string"))r=="toggle"&&(r=!e.data("flipped")),r?i(e,f):t(e,f);else if(e.data("initiated"))r&&(r.axis!==undefined||r.reverse!==undefined)&&u.call(this,r,function(){e.trigger("flip:change");f!==undefined&&f.call(this)});else if(e.data("initiated",!0),o=n.extend({axis:"y",reverse:!1,trigger:"click",speed:500,forceHeight:!1,forceWidth:!1,autoSize:!0,front:"auto",back:"auto"},r),o.front=="auto"?o.front=e.find(".front").length>0?".front":"div:first-child":o.front=="autostrict"&&(o.front="div:first-child"),o.back=="auto"?o.back=e.find(".back").length>0?".back":"div:first-child + div":o.back=="autostrict"&&(o.back="div:first-child + div"),e.data("reverse",o.reverse),e.data("axis",o.axis),e.data("front",o.front),e.data("back",o.back),h="rotate"+(o.axis.toLowerCase()=="x"?"x":"y"),l=e["outer"+(h=="rotatex"?"Height":"Width")]()*2,e.find(e.data("back")).css({transform:h+"("+(o.reverse?"180deg":"-180deg")+")"}),e.css({perspective:l,position:"relative"}),a=o.speed/1e3||.5,s=e.find(o.front).add(o.back,e),o.forceHeight?s.outerHeight(e.height()):o.autoSize&&s.css({height:"100%"}),o.forceWidth?s.outerWidth(e.width()):o.autoSize&&s.css({width:"100%"}),s.css({"backface-visibility":"hidden","transform-style":"preserve-3d",position:"absolute","z-index":"1"}),s.find("*").css({"backface-visibility":"hidden"}),e.find(e.data("back")).css({transform:h+"("+(o.reverse?"180deg":"-180deg")+")","z-index":"0"}),(window.chrome||window.Intl&&Intl.v8BreakIterator)&&"CSS"in window&&e.css({"-webkit-transform-style":"preserve-3d"}),setTimeout(function(){s.css({transition:"all "+a+"s ease-out"});f!==undefined&&f.call(this)},20),o.trigger.toLowerCase()=="click")e.on(n.fn.tap?"tap.flip":"click.flip",function(r){(r||(r=window.event),e.find(n(r.target).closest('button, a, input[type="submit"]')).length)||(e.data("flipped")?t(e):i(e))});else if(o.trigger.toLowerCase()=="hover"){v=function(){e.off("mouseleave.flip");i(e);setTimeout(function(){e.on("mouseleave.flip",c);e.is(":hover")||t(e)},o.speed+150)};c=function(){t(e)};e.on("mouseenter.flip",v);e.on("mouseleave.flip",c)}}),this};u=function(t,i){var u=!1,r,e,f;t.axis!==undefined&&n(this).data("axis")!=t.axis.toLowerCase()&&(n(this).data("axis",t.axis.toLowerCase()),u=!0);t.reverse!==undefined&&n(this).data("reverse")!=t.reverse&&(n(this).data("reverse",t.reverse),u=!0);u?(r=n(this).find(n(this).data("front")).add(n(this).data("back"),n(this)),e=r.css(["transition-property","transition-timing-function","transition-duration","transition-delay"]),r.css({transition:"none"}),f="rotate"+n(this).data("axis"),n(this).data("flipped")?n(this).find(n(this).data("front")).css({transform:f+(n(this).data("reverse")?"(-180deg)":"(180deg)"),"z-index":"0"}):n(this).find(n(this).data("back")).css({transform:f+"("+(n(this).data("reverse")?"180deg":"-180deg")+")","z-index":"0"}),setTimeout(function(){r.css(e);i.call(this)}.bind(this),0)):setTimeout(i.bind(this),0)}})(jQuery)