/**
 * turn.js 3rd release
 * www.turnjs.com
 *
 * Copyright (C) 2012, Emmanuel Garcia.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * 2. Any redistribution, use, or modification is done solely for personal 
 * benefit and not for any commercial purpose or for monetary gain.
 * 
 **/
!function(a){"use strict";var b,c="",d=Math.PI,e=d/2,f="ontouchstart"in window,g=f?{start:"touchstart",move:"touchmove",end:"touchend"}:{start:"mousedown",move:"mousemove",end:"mouseup"},h={backward:["bl","tl"],forward:["br","tr"],all:["tl","bl","tr","br"]},i=["single","double"],j={page:1,gradients:!0,duration:600,acceleration:!0,display:"double",when:null},k={folding:null,corners:"forward",cornerSize:100,gradients:!0,duration:600,acceleration:!0},l=6,m={0:{top:0,left:0,right:"auto",bottom:"auto"},1:{top:0,right:0,left:"auto",bottom:"auto"}},n=function(a,b,c,d){return{css:{position:"absolute",top:a,left:b,overflow:d||"hidden","z-index":c||"auto"}}},o=function(a,b,c,d,e){var f=1-e,g=f*f*f,h=e*e*e;return r(Math.round(g*a.x+3*e*f*f*b.x+3*e*e*f*c.x+h*d.x),Math.round(g*a.y+3*e*f*f*b.y+3*e*e*f*c.y+h*d.y))},q=function(a){return a/d*180},r=function(a,b){return{x:a,y:b}},s=function(a,c,d){return b&&d?" translate3d("+a+"px,"+c+"px, 0px) ":" translate("+a+"px, "+c+"px) "},t=function(a){return" rotate("+a+"deg) "},u=function(a,b){return Object.prototype.hasOwnProperty.call(b,a)},v=function(){for(var a=["Moz","Webkit","Khtml","O","ms"],b=a.length,c="";b--;)a[b]+"Transform"in document.body.style&&(c="-"+a[b].toLowerCase()+"-");return c},w=function(a,b,d,e,f){var g,h=[];if("-webkit-"==c){for(g=0;g<f;g++)h.push("color-stop("+e[g][0]+", "+e[g][1]+")");a.css({"background-image":"-webkit-gradient(linear, "+b.x+"% "+b.y+"%,  "+d.x+"% "+d.y+"%, "+h.join(",")+" )"})}else{b={x:b.x/100*a.width(),y:b.y/100*a.height()},d={x:d.x/100*a.width(),y:d.y/100*a.height()};var i=d.x-b.x,j=d.y-b.y,k=Math.atan2(j,i),l=k-Math.PI/2,m=Math.abs(a.width()*Math.sin(l))+Math.abs(a.height()*Math.cos(l)),n=Math.sqrt(j*j+i*i),o=r(d.x<b.x?a.width():0,d.y<b.y?a.height():0),p=Math.tan(k),q=-1/p,s=(q*o.x-o.y-p*b.x+b.y)/(q-p),t={x:s,y:q*s-q*o.x+o.y},u=Math.sqrt(Math.pow(t.x-b.x,2)+Math.pow(t.y-b.y,2));for(g=0;g<f;g++)h.push(" "+e[g][1]+" "+100*(u+n*e[g][0])/m+"%");a.css({"background-image":c+"linear-gradient("+-k+"rad,"+h.join(",")+")"})}},x={init:function(d){void 0===b&&(b="WebKitCSSMatrix"in window||"MozPerspective"in document.body.style,c=v());var e,i=this.data(),k=this.children();if(d=a.extend({width:this.width(),height:this.height()},j,d),i.opts=d,i.pageObjs={},i.pages={},i.pageWrap={},i.pagePlace={},i.pageMv=[],i.totalPages=d.pages||0,d.when)for(e in d.when)u(e,d.when)&&this.bind(e,d.when[e]);for(this.css({position:"relative",width:d.width,height:d.height}),this.turn("display",d.display),b&&!f&&d.acceleration&&this.transform(s(0,0,!0)),e=0;e<k.length;e++)this.turn("addPage",k[e],e+1);return this.turn("page",d.page),h=a.extend({},h,d.corners),a(this).bind(g.start,function(a){for(var b in i.pages)if(u(b,i.pages)&&!1===y._eventStart.call(i.pages[b],a))return!1}),a(document).bind(g.move,function(a){for(var b in i.pages)u(b,i.pages)&&y._eventMove.call(i.pages[b],a)}).bind(g.end,function(a){for(var b in i.pages)u(b,i.pages)&&y._eventEnd.call(i.pages[b],a)}),i.done=!0,this},addPage:function(b,c){var d=!1,e=this.data(),f=e.totalPages+1;if(c){if(c==f)c=f,d=!0;else if(c>f)throw new Error('It is impossible to add the page "'+c+'", the maximum value is: "'+f+'"')}else c=f,d=!0;return c>=1&&c<=f&&(e.done&&this.turn("stop"),c in e.pageObjs&&x._movePages.call(this,c,1),d&&(e.totalPages=f),e.pageObjs[c]=a(b).addClass("turn-page p"+c),x._addPage.call(this,c),e.done&&this.turn("update"),x._removeFromDOM.call(this)),this},_addPage:function(b){var c=this.data(),d=c.pageObjs[b];if(d)if(x._necessPage.call(this,b)){if(!c.pageWrap[b]){var e="double"==c.display?this.width()/2:this.width(),f=this.height();d.css({width:e,height:f}),c.pagePlace[b]=b,c.pageWrap[b]=a("<div/>",{class:"turn-page-wrapper",page:b,css:{position:"absolute",overflow:"hidden",width:e,height:f}}).css(m["double"==c.display?b%2:0]),this.append(c.pageWrap[b]),c.pageWrap[b].prepend(c.pageObjs[b])}b&&1!=x._setPageLoc.call(this,b)||x._makeFlip.call(this,b)}else c.pagePlace[b]=0,c.pageObjs[b]&&c.pageObjs[b].remove()},hasPage:function(a){return a in this.data().pageObjs},_makeFlip:function(a){var b=this.data();if(!b.pages[a]&&b.pagePlace[a]==a){var c="single"==b.display,d=a%2;b.pages[a]=b.pageObjs[a].css({width:c?this.width():this.width()/2,height:this.height()}).flip({page:a,next:c&&a===b.totalPages?a-1:d||c?a+1:a-1,turn:this,duration:b.opts.duration,acceleration:b.opts.acceleration,corners:c?"all":d?"forward":"backward",backGradient:b.opts.gradients,frontGradient:b.opts.gradients}).flip("disable",b.disabled).bind("pressed",x._pressed).bind("released",x._released).bind("start",x._start).bind("end",x._end).bind("flip",x._flip)}return b.pages[a]},_makeRange:function(){var a,c=(this.data(),this.turn("range"));for(a=c[0];a<=c[1];a++)x._addPage.call(this,a)},range:function(a){var b,c,d,e=this.data();a=a||e.tpage||e.page;var f=x._view.call(this,a);if(a<1||a>e.totalPages)throw new Error('"'+a+'" is not a page for range');return f[1]=f[1]||f[0],f[0]>=1&&f[1]<=e.totalPages?(b=Math.floor((l-2)/2),e.totalPages-f[1]>f[0]?(c=Math.min(f[0]-1,b),d=2*b-c):(d=Math.min(e.totalPages-f[1],b),c=2*b-d)):(c=l-1,d=l-1),[Math.max(1,f[0]-c),Math.min(e.totalPages,f[1]+d)]},_necessPage:function(a){if(0===a)return!0;var b=this.turn("range");return a>=b[0]&&a<=b[1]},_removeFromDOM:function(){var a,b=this.data();for(a in b.pageWrap)u(a,b.pageWrap)&&!x._necessPage.call(this,a)&&x._removePageFromDOM.call(this,a)},_removePageFromDOM:function(a){var b=this.data();if(b.pages[a]){var c=b.pages[a].data();c.f&&c.f.fwrapper&&c.f.fwrapper.remove(),b.pages[a].remove(),delete b.pages[a]}b.pageObjs[a]&&b.pageObjs[a].remove(),b.pageWrap[a]&&(b.pageWrap[a].remove(),delete b.pageWrap[a]),delete b.pagePlace[a]},removePage:function(a){var b=this.data();return b.pageObjs[a]&&(this.turn("stop"),x._removePageFromDOM.call(this,a),delete b.pageObjs[a],x._movePages.call(this,a,-1),b.totalPages=b.totalPages-1,x._makeRange.call(this),b.page>b.totalPages&&this.turn("page",b.totalPages)),this},_movePages:function(a,b){var c,d=this.data(),e="single"==d.display,f=function(a){var c=a+b,f=c%2;d.pageObjs[a]&&(d.pageObjs[c]=d.pageObjs[a].removeClass("page"+a).addClass("page"+c)),d.pagePlace[a]&&d.pageWrap[a]&&(d.pagePlace[c]=c,d.pageWrap[c]=d.pageWrap[a].css(m[e?0:f]).attr("page",c),d.pages[a]&&(d.pages[c]=d.pages[a].flip("options",{page:c,next:e||f?c+1:c-1,corners:e?"all":f?"forward":"backward"})),b&&(delete d.pages[a],delete d.pagePlace[a],delete d.pageObjs[a],delete d.pageWrap[a],delete d.pageObjs[a]))};if(b>0)for(c=d.totalPages;c>=a;c--)f(c);else for(c=a;c<=d.totalPages;c++)f(c)},display:function(b){var c=this.data(),d=c.display;if(b){if(-1==a.inArray(b,i))throw new Error('"'+b+'" is not a value for display');if("single"==b?c.pageObjs[0]||(this.turn("stop").css({overflow:"hidden"}),c.pageObjs[0]=a("<div />",{class:"turn-page p-temporal"}).css({width:this.width(),height:this.height()}).appendTo(this)):c.pageObjs[0]&&(this.turn("stop").css({overflow:""}),c.pageObjs[0].remove(),delete c.pageObjs[0]),c.display=b,d){var e=this.turn("size");x._movePages.call(this,1,0),this.turn("size",e.width,e.height).turn("update")}return this}return d},animating:function(){return this.data().pageMv.length>0},disable:function(b){var c,d=this.data(),e=this.turn("view");d.disabled=void 0===b||!0===b;for(c in d.pages)u(c,d.pages)&&d.pages[c].flip("disable",!!b&&a.inArray(c,e));return this},size:function(a,b){if(a&&b){var e,c=this.data(),d="double"==c.display?a/2:a;this.css({width:a,height:b}),c.pageObjs[0]&&c.pageObjs[0].css({width:d,height:b});for(e in c.pageWrap)u(e,c.pageWrap)&&(c.pageObjs[e].css({width:d,height:b}),c.pageWrap[e].css({width:d,height:b}),c.pages[e]&&c.pages[e].css({width:d,height:b}));return this.turn("resize"),this}return{width:this.width(),height:this.height()}},resize:function(){var a,b=this.data();for(b.pages[0]&&(b.pageWrap[0].css({left:-this.width()}),b.pages[0].flip("resize",!0)),a=1;a<=b.totalPages;a++)b.pages[a]&&b.pages[a].flip("resize",!0)},_removeMv:function(a){var b,c=this.data();for(b=0;b<c.pageMv.length;b++)if(c.pageMv[b]==a)return c.pageMv.splice(b,1),!0;return!1},_addMv:function(a){var b=this.data();x._removeMv.call(this,a),b.pageMv.push(a)},_view:function(a){var b=this.data();return a=a||b.page,"double"==b.display?a%2?[a-1,a]:[a,a+1]:[a]},view:function(a){var b=this.data(),c=x._view.call(this,a);return"double"==b.display?[c[0]>0?c[0]:0,c[1]<=b.totalPages?c[1]:0]:[c[0]>0&&c[0]<=b.totalPages?c[0]:0]},stop:function(a){var b,c,d=this.data(),e=d.pageMv;d.pageMv=[],d.tpage&&(d.page=d.tpage,delete d.tpage);for(b in e)u(b,e)&&(c=d.pages[e[b]].data().f.opts,y._moveFoldingPage.call(d.pages[e[b]],null),d.pages[e[b]].flip("hideFoldedPage"),d.pagePlace[c.next]=c.next,c.force&&(c.next=c.page%2==0?c.page-1:c.page+1,delete c.force));return this.turn("update"),this},pages:function(a){var b=this.data();if(a){if(a<b.totalPages){for(var c=a+1;c<=b.totalPages;c++)this.turn("removePage",c);this.turn("page")>a&&this.turn("page",a)}return b.totalPages=a,this}return b.totalPages},_fitPage:function(b,c){var d=this.data(),e=this.turn("view",b);d.page!=b&&(this.trigger("turning",[b,e]),-1!=a.inArray(1,e)&&this.trigger("first"),-1!=a.inArray(d.totalPages,e)&&this.trigger("last")),d.pageObjs[b]&&(d.tpage=b,this.turn("stop",c),x._removeFromDOM.call(this),x._makeRange.call(this),this.trigger("turned",[b,e]))},_turnPage:function(b){var c,d,e=this.data(),f=this.turn("view"),g=this.turn("view",b);if(e.page!=b&&(this.trigger("turning",[b,g]),-1!=a.inArray(1,g)&&this.trigger("first"),-1!=a.inArray(e.totalPages,g)&&this.trigger("last")),e.pageObjs[b]&&(e.tpage=b,this.turn("stop"),x._makeRange.call(this),"single"==e.display?(c=f[0],d=g[0]):f[1]&&b>f[1]?(c=f[1],d=g[0]):f[0]&&b<f[0]&&(c=f[0],d=g[1]),e.pages[c])){var h=e.pages[c].data().f.opts;e.tpage=d,h.next!=d&&(h.next=d,e.pagePlace[d]=h.page,h.force=!0),"single"==e.display?e.pages[c].flip("turnPage",g[0]>f[0]?"br":"bl"):e.pages[c].flip("turnPage")}},page:function(b){b=parseInt(b,10);var c=this.data();return b>0&&b<=c.totalPages?(c.done&&-1==a.inArray(b,this.turn("view"))?x._turnPage.call(this,b):x._fitPage.call(this,b),this):c.page},next:function(){var a=this.data();return this.turn("page",x._view.call(this,a.page).pop()+1)},previous:function(){var a=this.data();return this.turn("page",x._view.call(this,a.page).shift()-1)},_addMotionPage:function(){var b=a(this).data().f.opts,c=b.turn,d=c.data();b.pageMv=b.page,x._addMv.call(c,b.pageMv),d.pagePlace[b.next]=b.page,c.turn("update")},_start:function(b,c,d){var e=c.turn.data(),f=a.Event("start");if(b.stopPropagation(),c.turn.trigger(f,[c,d]),f.isDefaultPrevented())return void b.preventDefault();if("single"==e.display){var g="l"==d.charAt(1);1==c.page&&g||c.page==e.totalPages&&!g?b.preventDefault():g?(c.next=c.next<c.page?c.next:c.page-1,c.force=!0):c.next=c.next>c.page?c.next:c.page+1}x._addMotionPage.call(this)},_end:function(b,c){var d=a(this),e=d.data().f,f=e.opts,g=f.turn,h=g.data();b.stopPropagation(),c||h.tpage?h.tpage!=f.next&&h.tpage!=f.page||(delete h.tpage,x._fitPage.call(g,h.tpage||f.next,!0)):g.turn("update")},_pressed:function(){var b,c=a(this),d=c.data().f,e=d.opts.turn,f=e.data().pages;for(b in f)b!=d.opts.page&&f[b].flip("disable",!0);return d.time=(new Date).getTime()},_released:function(b,c){var d=a(this),e=d.data().f;b.stopPropagation(),((new Date).getTime()-e.time<200||c.x<0||c.x>a(this).width())&&(b.preventDefault(),e.opts.turn.data().tpage=e.opts.next,e.opts.turn.turn("update"),a(d).flip("turnPage"))},_flip:function(){var b=a(this).data().f.opts;b.turn.trigger("turn",[b.next])},calculateZ:function(a){var b,c,d,e,f,g=this,h=this.data(),i=this.turn("view"),j=i[0]||i[1],k={pageZ:{},partZ:{},pageV:{}},l=function(a){var b=g.turn("view",a);b[0]&&(k.pageV[b[0]]=!0),b[1]&&(k.pageV[b[1]]=!0)};for(b=0;b<a.length;b++)c=a[b],d=h.pages[c].data().f.opts.next,e=h.pagePlace[c],l(c),l(d),f=h.pagePlace[d]==d?d:c,k.pageZ[f]=h.totalPages-Math.abs(j-f),k.partZ[e]=2*h.totalPages+Math.abs(j-f);return k},update:function(){var a,b=this.data();if(b.pageMv.length&&0!==b.pageMv[0]){var d=this.turn("calculateZ",b.pageMv),e=this.turn("view",b.tpage);b.pagePlace[e[0]]==e[0]?e[0]:b.pagePlace[e[1]]==e[1]&&e[1];for(a in b.pageWrap)u(a,b.pageWrap)&&(b.pageWrap[a].css({display:d.pageV[a]?"":"none","z-index":d.pageZ[a]||0}),b.pages[a]&&(b.pages[a].flip("z",d.partZ[a]||null),d.pageV[a]&&b.pages[a].flip("resize"),b.tpage&&b.pages[a].flip("disable",!0)))}else for(a in b.pageWrap)if(u(a,b.pageWrap)){var f=x._setPageLoc.call(this,a);b.pages[a]&&b.pages[a].flip("disable",b.disabled||1!=f).flip("z",null)}},_setPageLoc:function(a){var b=this.data(),c=this.turn("view");return a==c[0]||a==c[1]?(b.pageWrap[a].css({"z-index":b.totalPages,display:""}),1):"single"==b.display&&a==c[0]+1||"double"==b.display&&a==c[0]-2||a==c[1]+2?(b.pageWrap[a].css({"z-index":b.totalPages-1,display:""}),2):(b.pageWrap[a].css({"z-index":0,display:"none"}),0)}},y={init:function(a){return a.gradients&&(a.frontGradient=!0,a.backGradient=!0),this.data({f:{}}),this.flip("options",a),y._addPageWrapper.call(this),this},setData:function(b){var c=this.data();return c.f=a.extend(c.f,b),this},options:function(b){var c=this.data().f;return b?(y.setData.call(this,{opts:a.extend({},c.opts||k,b)}),this):c.opts},z:function(a){var b=this.data().f;return b.opts["z-index"]=a,b.fwrapper.css({"z-index":a||parseInt(b.parent.css("z-index"),10)||0}),this},_cAllowed:function(){return h[this.data().f.opts.corners]||this.data().f.opts.corners},_cornerActivated:function(b){if(void 0===b.originalEvent)return!1;b=f?b.originalEvent.touches:[b];var c=this.data().f,d=c.parent.offset(),e=this.width(),g=this.height(),h={x:Math.max(0,b[0].pageX-d.left),y:Math.max(0,b[0].pageY-d.top)},i=c.opts.cornerSize,j=y._cAllowed.call(this);if(h.x<=0||h.y<=0||h.x>=e||h.y>=g)return!1;if(h.y<i)h.corner="t";else{if(!(h.y>=g-i))return!1;h.corner="b"}if(h.x<=i)h.corner+="l";else{if(!(h.x>=e-i))return!1;h.corner+="r"}return-1!=a.inArray(h.corner,j)&&h},_c:function(a,b){return b=b||0,{tl:r(b,b),tr:r(this.width()-b,b),bl:r(b,this.height()-b),br:r(this.width()-b,this.height()-b)}[a]},_c2:function(a){return{tl:r(2*this.width(),0),tr:r(-this.width(),0),bl:r(2*this.width(),this.height()),br:r(-this.width(),this.height())}[a]},_foldingPage:function(a){var b=this.data().f.opts;if(b.folding)return b.folding;if(b.turn){var c=b.turn.data();return"single"==c.display?c.pageObjs[b.next]?c.pageObjs[0]:null:c.pageObjs[b.next]}},_backGradient:function(){var b=this.data().f,c=b.opts.turn,d=b.opts.backGradient&&(!c||"single"==c.data().display||2!=b.opts.page&&b.opts.page!=c.data().totalPages-1);return d&&!b.bshadow&&(b.bshadow=a("<div/>",n(0,0,1)).css({position:"",width:this.width(),height:this.height()}).appendTo(b.parent)),d},resize:function(a){var b=this.data().f,c=this.width(),d=this.height(),e=Math.round(Math.sqrt(Math.pow(c,2)+Math.pow(d,2)));a&&(b.wrapper.css({width:e,height:e}),b.fwrapper.css({width:e,height:e}).children(":first-child").css({width:c,height:d}),b.fpage.css({width:d,height:c}),b.opts.frontGradient&&b.ashadow.css({width:d,height:c}),y._backGradient.call(this)&&b.bshadow.css({width:c,height:d})),b.parent.is(":visible")&&(b.fwrapper.css({top:b.parent.offset().top,left:b.parent.offset().left}),b.opts.turn&&b.fparent.css({top:-b.opts.turn.offset().top,left:-b.opts.turn.offset().left})),this.flip("z",b.opts["z-index"])},_addPageWrapper:function(){var c=this.data().f,d=this.parent();if(!c.wrapper){var g=(this.css("left"),this.css("top"),this.width()),h=this.height();Math.round(Math.sqrt(Math.pow(g,2)+Math.pow(h,2)));if(c.parent=d,c.fparent=c.opts.turn?c.opts.turn.data().fparent:a("#turn-fwrappers"),!c.fparent){var j=a("<div/>",{css:{"pointer-events":"none"}}).hide();j.data().flips=0,c.opts.turn?(j.css(n(-c.opts.turn.offset().top,-c.opts.turn.offset().left,"auto","visible").css).appendTo(c.opts.turn),c.opts.turn.data().fparent=j):j.css(n(0,0,"auto","visible").css).attr("id","turn-fwrappers").appendTo(a("body")),c.fparent=j}this.css({position:"absolute",top:0,left:0,bottom:"auto",right:"auto"}),c.wrapper=a("<div/>",n(0,0,this.css("z-index"))).appendTo(d).prepend(this),c.fwrapper=a("<div/>",n(d.offset().top,d.offset().left)).hide().appendTo(c.fparent),c.fpage=a("<div/>",{css:{cursor:"default"}}).appendTo(a("<div/>",n(0,0,0,"visible")).appendTo(c.fwrapper)),c.opts.frontGradient&&(c.ashadow=a("<div/>",n(0,0,1)).appendTo(c.fpage)),y.setData.call(this,c),y.resize.call(this,!0)}},_fold:function(a){var h,i,j,k,l,m,b=this,c=0,f=0,n=r(0,0),o=r(0,0),p=r(0,0),u=this.width(),v=this.height(),x=y._foldingPage.call(this),A=(Math.tan(f),this.data().f),B=A.opts.acceleration,C=A.wrapper.height(),D=y._c.call(this,a.corner),E="t"==a.corner.substr(0,1),F="l"==a.corner.substr(1,1),G=function(){var t,g=r(D.x?D.x-a.x:a.x,D.y?D.y-a.y:a.y),s=Math.atan2(g.y,g.x);f=e-s,c=q(f),t=r(F?u-g.x/2:a.x+g.x/2,g.y/2);var w=f-Math.atan2(t.y,t.x),x=Math.max(0,Math.sin(w)*Math.sqrt(Math.pow(t.x,2)+Math.pow(t.y,2)));if(p=r(x*Math.sin(f),x*Math.cos(f)),f>e&&(p.x=p.x+Math.abs(p.y*Math.tan(s)),p.y=0,Math.round(p.x*Math.tan(d-f))<v))return a.y=Math.sqrt(Math.pow(v,2)+2*t.x*g.x),E&&(a.y=v-a.y),G();if(f>e){var z=d-f,B=C-v/Math.sin(z);n=r(Math.round(B*Math.cos(z)),Math.round(B*Math.sin(z))),F&&(n.x=-n.x),E&&(n.y=-n.y)}h=Math.round(p.y/Math.tan(f)+p.x);var H=u-h,I=H*Math.cos(2*f),J=H*Math.sin(2*f);o=r(Math.round(F?H-I:h+I),Math.round(E?J:v-J)),l=H*Math.sin(f);var K=y._c2.call(b,a.corner),L=Math.sqrt(Math.pow(K.x-a.x,2)+Math.pow(K.y-a.y,2));return m=L<u?L/u:1,A.opts.frontGradient&&(k=l>100?(l-100)/l:0,i=r(l*Math.sin(e-f)/v*100,l*Math.cos(e-f)/u*100),E&&(i.y=100-i.y),F&&(i.x=100-i.x)),y._backGradient.call(b)&&(j=r(l*Math.sin(f)/u*100,l*Math.cos(f)/v*100),F||(j.x=100-j.x),E||(j.y=100-j.y)),p.x=Math.round(p.x),p.y=Math.round(p.y),!0},H=function(a,c,d,e){var g=["0","auto"],h=(u-C)*d[0]/100,l=(v-C)*d[1]/100,p={left:g[c[0]],top:g[c[1]],right:g[c[2]],bottom:g[c[3]]},q=90!=e&&-90!=e?F?-1:1:0;d=d[0]+"% "+d[1]+"%",b.css(p).transform(t(e)+s(a.x+q,a.y,B),d),A.fpage.parent().css(p),A.wrapper.transform(s(-a.x+h-q,-a.y+l,B)+t(-e),d),A.fwrapper.transform(s(-a.x+n.x+h,-a.y+n.y+l,B)+t(-e),d),A.fpage.parent().transform(t(e)+s(a.x+o.x-n.x,a.y+o.y-n.y,B),d),A.opts.frontGradient&&w(A.ashadow,r(F?100:0,E?100:0),r(i.x,i.y),[[k,"rgba(0,0,0,0)"],[.8*(1-k)+k,"rgba(0,0,0,"+.2*m+")"],[1,"rgba(255,255,255,"+.2*m+")"]],3,f),y._backGradient.call(b)&&w(A.bshadow,r(F?0:100,E?0:100),r(j.x,j.y),[[.8,"rgba(0,0,0,0)"],[1,"rgba(0,0,0,"+.3*m+")"],[1,"rgba(0,0,0,0)"]],3)};switch(a.corner){case"tl":a.x=Math.max(a.x,1),G(),H(p,[1,0,0,1],[100,0],c),A.fpage.transform(s(-v,-u,B)+t(90-2*c),"100% 100%"),x.transform(t(90)+s(0,-v,B),"0% 0%");break;case"tr":a.x=Math.min(a.x,u-1),G(),H(r(-p.x,p.y),[0,0,0,1],[0,0],-c),A.fpage.transform(s(0,-u,B)+t(2*c-90),"0% 100%"),x.transform(t(270)+s(-u,0,B),"0% 0%");break;case"bl":a.x=Math.max(a.x,1),G(),H(r(p.x,-p.y),[1,1,0,0],[100,100],-c),A.fpage.transform(s(-v,0,B)+t(2*c-90),"100% 0%"),x.transform(t(270)+s(-u,0,B),"0% 0%");break;case"br":a.x=Math.min(a.x,u-1),G(),H(r(-p.x,-p.y),[0,1,1,0],[0,100],c),A.fpage.transform(t(90-2*c),"0% 0%"),x.transform(t(90)+s(0,-v,B),"0% 0%")}A.point=a},_moveFoldingPage:function(a){var b=this.data().f,c=y._foldingPage.call(this);c&&(a?b.fpage.children()[b.ashadow?"1":"0"]||(y.setData.call(this,{backParent:c.parent()}),b.fpage.prepend(c)):b.backParent&&b.backParent.prepend(c))},_showFoldedPage:function(b,c){var d=y._foldingPage.call(this),e=this.data(),f=e.f;if(!f.point||f.point.corner!=b.corner){var g=a.Event("start");if(this.trigger(g,[f.opts,b.corner]),g.isDefaultPrevented())return!1}if(d){if(c){var h=this,i=f.point&&f.point.corner==b.corner?f.point:y._c.call(this,b.corner,1);this.animatef({from:[i.x,i.y],to:[b.x,b.y],duration:500,frame:function(a){b.x=Math.round(a[0]),b.y=Math.round(a[1]),y._fold.call(h,b)}})}else y._fold.call(this,b),e.effect&&!e.effect.turning&&this.animatef(!1);return f.fwrapper.is(":visible")||(f.fparent.show().data().flips++,y._moveFoldingPage.call(this,!0),f.fwrapper.show(),f.bshadow&&f.bshadow.show()),!0}return!1},hide:function(){var a=this.data().f,b=y._foldingPage.call(this);return 0==--a.fparent.data().flips&&a.fparent.hide(),this.css({left:0,top:0,right:"auto",bottom:"auto"}).transform("","0% 100%"),a.wrapper.transform("","0% 100%"),a.fwrapper.hide(),a.bshadow&&a.bshadow.hide(),b.transform("","0% 0%"),this},hideFoldedPage:function(a){var b=this.data().f;if(b.point){var c=this,d=b.point,e=function(){b.point=null,c.flip("hide"),c.trigger("end",[!1])};if(a){var f=y._c.call(this,d.corner),g="t"==d.corner.substr(0,1),h=g?Math.min(0,d.y-f.y)/2:Math.max(0,d.y-f.y)/2,i=r(d.x,d.y+h),j=r(f.x,f.y-h);this.animatef({from:0,to:1,frame:function(a){var b=o(d,i,j,f,a);d.x=b.x,d.y=b.y,y._fold.call(c,d)},complete:e,duration:800,hiding:!0})}else this.animatef(!1),e()}},turnPage:function(a){var b=this,c=this.data().f;a={corner:c.corner?c.corner.corner:a||y._cAllowed.call(this)[0]};var d=c.point||y._c.call(this,a.corner,c.opts.turn?c.opts.turn.data().opts.elevation:0),e=y._c2.call(this,a.corner);this.trigger("flip").animatef({from:0,to:1,frame:function(c){var f=o(d,d,e,e,c);a.x=f.x,a.y=f.y,y._showFoldedPage.call(b,a)},complete:function(){b.trigger("end",[!0])},duration:c.opts.duration,turning:!0}),c.corner=null},moving:function(){return"effect"in this.data()},isTurning:function(){return this.flip("moving")&&this.data().effect.turning},_eventStart:function(a){var b=this.data().f;if(!b.disabled&&!this.flip("isTurning")){if(b.corner=y._cornerActivated.call(this,a),b.corner&&y._foldingPage.call(this,b.corner))return y._moveFoldingPage.call(this,!0),this.trigger("pressed",[b.point]),!1;b.corner=null}},_eventMove:function(a){var b=this.data().f;if(!b.disabled)if(a=f?a.originalEvent.touches:[a],b.corner){var c=b.parent.offset();b.corner.x=a[0].pageX-c.left,b.corner.y=a[0].pageY-c.top,y._showFoldedPage.call(this,b.corner)}else if(!this.data().effect&&this.is(":visible")){var d=y._cornerActivated.call(this,a[0]);if(d){var e=y._c.call(this,d.corner,b.opts.cornerSize/2);d.x=e.x,d.y=e.y,y._showFoldedPage.call(this,d,!0)}else y.hideFoldedPage.call(this,!0)}},_eventEnd:function(){var b=this.data().f;if(!b.disabled&&b.point){var c=a.Event("released");this.trigger(c,[b.point]),c.isDefaultPrevented()||y.hideFoldedPage.call(this,!0)}b.corner=null},disable:function(a){return y.setData.call(this,{disabled:a}),this}},z=function(a,b,c){if(c[0]&&"object"!=typeof c[0]){if(b[c[0]]&&"_"!=c[0].toString().substr(0,1))return b[c[0]].apply(a,Array.prototype.slice.call(c,1));throw c[0]+" is an invalid value"}return b.init.apply(a,c)};a.extend(a.fn,{flip:function(a,b){return z(this,y,arguments)},turn:function(a){return z(this,x,arguments)},transform:function(a,b){var d={};return b&&(d[c+"transform-origin"]=b),d[c+"transform"]=a,this.css(d)},animatef:function(a){var b=this.data();if(b.effect&&clearInterval(b.effect.handle),a){a.to.length||(a.to=[a.to]),a.from.length||(a.from=[a.from]),a.easing||(a.easing=function(a,b,c,d,e){return d*Math.sqrt(1-(b=b/e-1)*b)+c});var c,d=[],e=a.to.length,f=this,g=a.fps||30,h=-g,i=function(){var c,i=[];for(h=Math.min(a.duration,h+g),c=0;c<e;c++)i.push(a.easing(1,h,a.from[c],d[c],a.duration));a.frame(1==e?i[0]:i),h==a.duration&&(clearInterval(b.effect.handle),delete b.effect,f.data(b),a.complete&&a.complete())};for(c=0;c<e;c++)d.push(a.to[c]-a.from[c]);b.effect=a,b.effect.handle=setInterval(i,g),this.data(b),i()}else delete b.effect}}),a.isTouch=f}(jQuery);