/* turn.js | turnjs.com | (c) 2012 Emmanuel Garcia | MIT Licensed */ (function(f){var E=Math.PI,C=E/2,H="WebKitCSSMatrix"in window&&"m11"in new WebKitCSSMatrix,t="Touch"in window,L={backward:["bl","tl"],forward:["br","tr"],all:["tl","bl","tr","br"]},M={page:1,shadows:!0,duration:600,acceleration:!0},N={back:null,corners:"forward",cornerSize:100,shadows:!0,duration:600,acceleration:!0},u=function(a,b,c,d,e,g){return{css:{position:"absolute",top:a,left:b,width:c,height:d,"z-index":e||"auto",overflow:g||"hidden"}}},J=function(a,b,c,d,e){var g=1-e,B=g*g*g;mu3=e*e*e;return j(Math.round(B* a.x+3*e*g*g*b.x+3*e*e*g*c.x+mu3*d.x),Math.round(B*a.y+3*e*g*g*b.y+3*e*e*g*c.y+mu3*d.y))},j=function(a,b){return{x:a,y:b}},o=function(a,b,c){return H&&c?" translate3d("+a+"px,"+b+"px, 0px) ":" translate("+a+"px, "+b+"px) "},r=function(a){return" rotate("+a+"deg) "},i={init:function(a){var b,c,d=this.data();c=this.children();var e=c.length,a=f.extend({},M,a);d.opt=a;d.pageObjs={};d.pages={};d.pageWrap={};d.pagePlace={};d.pageMv=[];d.totalPages=e;this.css({position:"relative"});H&&!t&&a.acceleration&& this.transform(o(0,0,!0));for(b=1;b<=e;b++)d.pagePlace[b]=b,d.pageObjs[b]=f(c[b-1]).addClass("turn-page").addClass("p"+b),d.pageWrap[b]=f("
",{"class":"turn-page-wrapper",css:{position:"absolute",width:d.pageObjs[b].width(),height:d.pageObjs[b].height()}}).attr("page",b).appendTo(this).prepend(d.pageObjs[b]);for(b=1;b<=e;b++)c=b%2==0,d.pages[b]=d.pageWrap[b].css(c?{top:0,left:0}:{top:0,right:0}).children(":first").flip({next:c?b-1:b+1,page:b,turn:this,duration:a.duration,acceleration:a.acceleration, corners:c?"backward":"forward",back:c?d.pageObjs[b-1]:d.pageObjs[b+1],backShadow:a.shadows&&b!=2&&b!=e-1,frontShadow:a.shadows}).bind("pressed",i._pressed).bind("released",i._released).bind("start",i._start).bind("end",i._end).bind("flip",i._flip);i.page.apply(this,[a.page]);d.done=!0;return this},_visiblePages:function(a){a=a||this.data().page;return a%2==0?[a,a+1]:[a-1,a]},_removeMv:function(a){var b,c=this.data();for(b=0;b=c[0])&&(!c[1]||a<=c[1]))b.tpage=a,this.turn("stop"),this.trigger("turned",[a,pg]);else{b.tpage=a;this.turn("stop");var d,e,g=this.turn("view",a);c[1]&&a>c[1]?(d=c[1],e=g[0]):c[0]&&af(this).width())a.stopPropagation(),e.opt.turn.data().tpage=e.opt.next,e.opt.turn.turn("update"),f(c).flip("turnPage")},_flip:function(){var a=f(this).data().pageFlip.opt;a.turn.trigger("turning",[a.next])},disable:function(a){var b=this.data(),a=typeof a=="undefined"?!0:a===!0;for(p=1;p<=b.totalPages;p++)b.pages[p].flip("disable", a)}},h={init:function(a){if(a.shadows)a.frontShadow=!0,a.backShadow=!0;h.setData.apply(this,[{opt:f.extend({},N,a)}]);h._addEvents.apply(this);h._addPageWrapper.apply(this);return this},setData:function(a){var b=this.data();b.pageFlip=f.extend(b.pageFlip||{},a)},_cAllowed:function(){return L[this.data().pageFlip.opt.corners]||this.data().pageFlip.opt.corners},_cornerActivated:function(a){var a=t?a.originalEvent.touches:[a],b;b=this.data().pageFlip;var c=b.parent.offset(),d=this.width(),e=this.height(), g=Math.max(0,a[0].pageX-c.left),a=Math.max(0,a[0].pageY-c.top),f=b.opt.cornerSize,c=h._cAllowed.apply(this);if(!b.opt.back||g<=0||a<=0||g>=d||a>=e)b=!1;else if(g<=f&&a<=f)b="tl";else if(g>=d-f&&a<=f)b="tr";else if(g<=f&&a>=e-f)b="bl";else if(g>=d-f&&a>=e-f)b="br";else return!1;return jQuery.inArray(b,c)!=-1?{corner:b,x:g,y:a}:!1},_c:function(a,b){b=b||0;return{tl:j(b,b),tr:j(this.width()-b,b),bl:j(b,this.height()-b),br:j(this.width()-b,this.height()-b)}[a]},_c2:function(a){return{tl:j(this.width()* 2,0),tr:j(-this.width(),0),bl:j(this.width()*2,this.height()),br:j(-this.width(),this.height())}[a]},z:function(a){var b=this.data().pageFlip;b.opt["z-index"]=a;b.fwrapper.css({"z-index":a||parseInt(b.parent.css("z-index"))||0})},resize:function(){var a=this.data().pageFlip;a.parent.is(":visible")&&(a.fwrapper.css({top:a.parent.offset().top,left:a.parent.offset().left}),a.opt.turn&&a.fparent.css({top:-a.opt.turn.offset().top,left:-a.opt.turn.offset().left}));this.flip("z",a.opt["z-index"])},_addPageWrapper:function(){var a= this.data().pageFlip,b=this.parent();if(!a.wrapper){var c=this.css("left"),d=this.css("top"),e=this.width(),g=this.height(),j=Math.round(Math.sqrt(Math.pow(e,2)+Math.pow(g,2)));a.fparent=a.opt.turn?a.opt.turn.data().fparent:f("#turn-fwrappers");if(!a.fparent){var i=f("
").hide();i.data().flips=0;a.opt.turn?(i.css(u(-a.opt.turn.offset().top,-a.opt.turn.offset().left,"auto","auto","auto","visible").css).appendTo(a.opt.turn),a.opt.turn.data().fparent=i):i.css(u(0,0,"auto","auto","auto","visible").css).attr("id", "turn-fwrappers").appendTo(f("body"));a.fparent=i}a.parent=b;this.css({position:"absolute",top:0,left:0,bottom:"auto",right:"auto"});a.wrapper=f("
",u(d,c,j,j,this.css("z-index"))).appendTo(b).prepend(this);a.fwrapper=f("
",u(b.offset().top,b.offset().left,j,j)).hide().appendTo(a.fparent);a.fpage=f("
",{fpage:1,css:{width:g,height:e,cursor:"default"}}).appendTo(f("
",u(0,0,e,g,0,"visible")).appendTo(a.fwrapper));if(a.opt.frontShadow)a.ashadow=f("
",u(0,0,g,e,1)).appendTo(a.fpage); if(a.opt.backShadow)a.bshadow=f("
",u(0,0,e,g,1)).css({position:""}).appendTo(b);h.setData.apply(this,[a]);h.resize.apply(this)}},_displayCorner:function(a){var b=this,c=0,d=0,e,g,f,i,F,w=j(0,0),I=j(0,0),k=j(0,0),m=this.width(),q=this.height(),l=this.data().pageFlip,v=l.opt.acceleration,u=l.wrapper.height(),t=h._c.apply(this,[a.corner]),A=a.corner.substr(0,1)=="t",x=a.corner.substr(1,1)=="l",D=function(){var n=j(t.x?t.x-a.x:a.x,t.y?t.y-a.y:a.y),y=Math.atan2(n.y,n.x),s;d=C-y;c=d/E*180;s=j(x?m- n.x/2:a.x+n.x/2,n.y/2);var z=Math.max(0,Math.sin(d-Math.atan2(s.y,s.x))*Math.sqrt(Math.pow(s.x,2)+Math.pow(s.y,2)));k=j(z*Math.sin(d),z*Math.cos(d));if(d>C&&(k.x+=Math.abs(k.y*Math.tan(y)),k.y=0,Math.round(k.x*Math.tan(E-d))C){y=E-d;s=u-q/Math.sin(y);w=j(Math.round(s*Math.cos(y)),Math.round(s*Math.sin(y)));if(x)w.x=-w.x;if(A)w.y=-w.y}if(l.opt.frontShadow){ppcen=n/(d100?(n-100)/n:0;g=j(n*Math.sin(C-d)/q*100,n*Math.cos(C-d)/m*100);if(A)g.y=100-g.y;if(x)g.x=100-g.x}if(l.opt.backShadow){f=j(n*Math.sin(d)/m*100,n*Math.cos(d)/q*100);if(!x)f.x=100-f.x;if(!A)f.y=100-f.y}k.x=Math.round(k.x);k.y=Math.round(k.y);return!0},G=function(a, c,d,e){var h=["0","auto"],j=(m-u)*d[0]/100,k=(q-u)*d[1]/100,d=d[0]+"% "+d[1]+"%",c={left:h[c[0]],top:h[c[1]],right:h[c[2]],bottom:h[c[3]]};b.css(c).transform(r(e)+o(a.x,a.y,v),d);l.fpage.parent().css(c);l.wrapper.transform(o(-a.x+j,-a.y+k,v)+r(-e),d);l.fwrapper.transform(o(-a.x+w.x+j,-a.y+w.y+k,v)+r(-e),d);l.fpage.parent().transform(r(e)+o(a.x+I.x-w.x,a.y+I.y-w.y,v),d);l.opt.frontShadow&&l.ashadow.css({"background-image":"-webkit-gradient(linear, "+(x?100:0)+"% "+(A?100:0)+"%, "+g.x+"% "+g.y+"%, color-stop("+ i+",rgba(0,0,0,0)), color-stop("+((1-i)*0.8+i)+",rgba(0,0,0,"+0.2*F+")), to(rgba(255,255,255,"+0.2*F+")) )"});l.opt.backShadow&&l.bshadow.css({"background-image":"-webkit-gradient(linear, "+(x?0:100)+"% "+(A?0:100)+"%, "+f.x+"% "+f.y+"%, color-stop(0.8,rgba(0,0,0,0)), color-stop(1, rgba(0,0,0,"+0.2*F+")), to(rgba(0,0,0,0)) )"})};switch(a.corner){case "tl":a.x=Math.max(a.x,1);D();G(k,[1,0,0,1],[100,0],c);l.fpage.transform(o(-q,-m,v)+r(90-c*2),"100% 100%");l.opt.back.transform(r(90)+o(0,-q,v),"0% 0%"); break;case "tr":a.x=Math.min(a.x,m-1);D();G(j(-k.x,k.y),[0,0,0,1],[0,0],-c);l.fpage.transform(o(0,-m,v)+r(-90+c*2),"0% 100%");l.opt.back.transform(r(270)+o(-m,0,v),"0% 0%");break;case "bl":a.x=Math.max(a.x,1);D();G(j(k.x,-k.y),[1,1,0,0],[100,100],-c);l.fpage.transform(o(-q,0,v)+r(-90+c*2),"100% 0%");l.opt.back.transform(r(270)+o(-m,0,v),"0% 0%");break;case "br":a.x=Math.min(a.x,m-1),D(),G(j(-k.x,-k.y),[0,1,1,0],[0,100],c),l.fpage.transform(r(90-c*2),"0% 0%"),l.opt.back.transform(r(90)+o(0,-q,v),"0% 0%")}l.p= a},setBackPage:function(a){var b=this.data().pageFlip;b.opt.back=a;b.backParent=a.parent()},_moveBackPage:function(a){var b=this.data().pageFlip;if(b.opt.back)if(a){if(!((b.ashadow?"1":"0")in b.fpage.children()))h.setData.apply(this,[{backParent:b.opt.back.parent()}]),b.fpage.prepend(b.opt.back)}else b.opt.back.transform("","0% 0%"),b.backParent&&b.backParent.prepend(b.opt.back)},_showThumbIndex:function(a,b){var c=this.data(),d=c.pageFlip;if(d.opt.back){if(b){var e=this,c=d.p||h._c.apply(this,[a.corner, 1]);this.animatef({from:[c.x,c.y],to:[a.x,a.y],duration:500,frame:function(b){h._displayCorner.apply(e,[{corner:a.corner,x:b[0],y:b[1]}])}})}else h._displayCorner.apply(this,[a]),c.effect&&!c.effect.turning&&this.animatef(!1);d.fwrapper.is(":visible")||(d.fparent.show().data().flips++,h._moveBackPage.apply(this,[!0]),d.fwrapper.show(),d.opt.backShadow&&d.bshadow.show(),this.trigger("start"))}},hide:function(){var a=this.data().pageFlip;--a.fparent.data().flips==0&&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.opt.backShadow&&a.bshadow.hide();a.opt.back.transform("","0% 0%")},hideThumbIndex:function(a){var b=this.data().pageFlip;if(b.p){var c=this,d=b.p,e=function(){b.p=null;c.flip("hide");c.trigger("end",[!1])};if(a){var g,f,i=h._c.apply(this,[d.corner]),a=d.corner.substr(0,1)=="t",o=Math.abs((d.y-i.y)/2);g=j(d.x,d.y+o);f=j(i.x,a?i.y+o:i.y-o);this.animatef({from:0,to:1,frame:function(a){a=J(d, g,f,i,a);a.corner=d.corner;h._displayCorner.apply(c,[a])},complete:e,duration:800,hiding:!0})}else this.animatef(!1),e()}},turnPage:function(){var a=this,b=this.data().pageFlip,c=b.cornerActivated?b.cornerActivated.corner:h._cAllowed.apply(this)[0],d=b.p||h._c.apply(this,[c]),e=h._c2.apply(this,[c]);this.trigger("flip");this.animatef({from:0,to:1,frame:function(b){b=J(d,d,e,e,b);b.corner=c;h._showThumbIndex.apply(a,[b])},complete:function(){a.trigger("end",[!0])},duration:b.opt.duration,turning:!0}); b.cornerActivated=null},moving:function(){return"effect"in this.data()},isTurning:function(){return this.flip("moving")&&this.data().effect.turning},_addEvents:function(){var a=this,b=t?{start:"touchstart",move:"touchmove",end:"touchend"}:{start:"mousedown",move:"mousemove",end:"mouseup"};f(document).bind(b.start,function(){return h._eventStart.apply(a,arguments)}).bind(b.move,function(){h._eventMove.apply(a,arguments)}).bind(b.end,function(){h._eventEnd.apply(a,arguments)})},_eventStart:function(a){var b= this.data().pageFlip;if(!b.disabled&&!this.flip("isTurning")&&(b.cornerActivated=h._cornerActivated.apply(this,[a]),b.cornerActivated))return h._moveBackPage.apply(this,[!0]),this.trigger("pressed",[b.p]),!1},_eventMove:function(a){var b=this.data(),c=b.pageFlip,a=t?a.originalEvent.touches:[a];c.disabled||(c.cornerActivated?(b=c.parent.offset(),h._showThumbIndex.apply(this,[{corner:c.cornerActivated.corner,x:a[0].pageX-b.left,y:a[0].pageY-b.top}])):!b.effect&&!t&&((corner=h._cornerActivated.apply(this, [a[0]]))?(a=h._c.apply(this,[corner.corner,c.opt.cornerSize/2]),h._showThumbIndex.apply(this,[{corner:corner.corner,x:a.x,y:a.y},!0])):h.hideThumbIndex.apply(this,[!0])))},_eventEnd:function(){var a=this.data().pageFlip;if(!a.disabled&&a.cornerActivated){var b=jQuery.Event("released");this.trigger(b,[a.p]);b.isPropagationStopped()||h.hideThumbIndex.apply(this,[!0])}a.cornerActivated=null},disable:function(a){h.setData.apply(this,[{disabled:a}])}},K=function(a,b,c){if(!c[0]||typeof c[0]=="object")return b.init.apply(a, c);else if(b[c[0]]&&c[0].toString().substr(0,1)!="_")return b[c[0]].apply(a,Array.prototype.slice.call(c,1));else throw c[0]+" is an invalid value";};f.extend(f.fn,{flip:function(a,b){return K(this,h,arguments)},turn:function(a){return K(this,i,arguments)},transform:function(a,b){b&&this.css({"transform-origin":b,"-moz-transform-origin":b,"-o-transform-origin":b,"-webkit-transform-origin":b,"-ms-transform-origin":b});return this.css({transform:a,"-moz-transform":a,"-o-transform":a,"-webkit-transform":a, "-ms-transform":a})},animatef:function(a){var b=this.data();b.effect&&clearInterval(b.effect.handle);if(a){if(!a.to.length)a.to=[a.to];if(!a.from.length)a.from=[a.from];if(!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,h=a.fps||30,i=-h,j=function(){var c,j=[];i=Math.min(a.duration,i+h);for(c=0;c