/*
 * jQuery Booklet Plugin
 * Copyright (c) 2010 - 2012 W. Grauvogel (http://builtbywill.com/)
 *
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version : 1.3.1
 *
 * Originally based on the work of:
 *	1) Charles Mangin (http://clickheredammit.com/pageflip/)
 */
;(function(a){a.fn.booklet=function(c){return a(this).each(function(){var g,e,f,d;if(typeof c=="string"){if(a(this).data("booklet")){g=c.toLowerCase();f=a(this).data("booklet");if(g=="next"){f.next()}else{if(g=="prev"){f.prev()}}}}else{if(typeof c=="number"){if(a(this).data("booklet")){d=c;f=a(this).data("booklet");if(d%2!=0){d-=1}if(f.options.direction=="RTL"){d=Math.abs(d-f.options.pageTotal)-2}f.goToPage(d)}}else{e=a.extend({},a.fn.booklet.defaults,c);f=new b(a(this),e);f.init();return this}}})};function b(aR,aL){var ao=aR,aq=aL,Z=false,Q=false,az=false,d=false,ay=false,k={empty:'<div class="b-page-empty" title=""></div>',blank:'<div class="b-page-blank" title=""></div>',sF:'<div class="b-shadow-f"></div>',sB:'<div class="b-shadow-b"></div>'},av={leftToRight:"LTR",rightToLeft:"RTL"},au={},S={},c,aH,x,p=new Array(),T="",ah="/page/",R,N,L,P,Y,t,I,an,am,ak,aj,ag,aP,aw,M,y,e,aM,aI,aO,aQ,ar,o,aB,w,aG,aF,V,aD,aC,r,H,G,F,E,g,f,q,K,U,ad,A,C,X,ab,s,aE,ax=function(){if(!Z){a(".b-load").children().unwrap();ao.addClass("booklet");ao.data("booklet",this);ao.data("total",ao.children().length);aq.currentIndex=0;n();v();al();ap();aN();Z=true}},n=function(){if((ao.children().length%2)!=0){if(aq.closed&&aq.covers){ao.children().last().before(k.blank)}else{ao.children().last().after(k.blank)}}if(aq.closed){a(k.empty).attr({title:aq.closedFrontTitle||"",rel:aq.closedFrontChapter||""}).prependTo(ao);ao.children().last().attr({title:aq.closedBackTitle||"",rel:aq.closedBackChapter||""});ao.append(k.empty)}aq.pageTotal=ao.children().length;aq.startingPageNumber=0;if(aq.direction==av.rightToLeft){aq.startingPageNumber=aq.pageTotal;if(aq.closed){aq.startingPageNumber-=2}if(aq.covers){aq.startingPageNumber-=2}a(ao.children().get().reverse()).each(function(){a(this).appendTo(ao)})}ao.children().each(function(h){var j=new aK(a(this),h,aq);p.push(j)});if(Z){v();al();ap();aN()}},aK=function(h,aT,aS){var j="",aU="",i;if(h.attr("rel")){j=h.attr("rel")}if(h.attr("title")){aU=h.attr("title")}if(h.hasClass("b-page-empty")){h.wrap('<div class="b-page"><div class="b-wrap"></div></div>')}else{if(aS.closed&&aS.covers&&(aT==1||aT==aS.pageTotal-2)){h.wrap('<div class="b-page"><div class="b-wrap b-page-cover"></div></div>')}else{if(aT%2!=0){h.wrap('<div class="b-page"><div class="b-wrap b-wrap-right"></div></div>')}else{h.wrap('<div class="b-page"><div class="b-wrap b-wrap-left"></div></div>')}}}i=h.parents(".b-page").addClass("b-page-"+aT);if(aS.pageNumbers&&!h.hasClass("b-page-empty")&&(!aS.closed||(aS.closed&&!aS.covers)||(aS.closed&&aS.covers&&aT!=1&&aT!=aS.pageTotal-2))){if(aS.direction==av.leftToRight){aS.startingPageNumber++}h.parent().append('<div class="b-counter">'+aS.startingPageNumber+"</div>");if(aS.direction==av.rightToLeft){aS.startingPageNumber--}}return{index:aT,contentNode:h,pageNode:i,chapter:j,title:aU}},ae=function(){ao.find(".b-page").removeClass("b-pN b-p0 b-p1 b-p2 b-p3 b-p4").hide();if(aq.currentIndex-2>=0){ao.find(".b-page-"+(aq.currentIndex-2)).addClass("b-pN").show();ao.find(".b-page-"+(aq.currentIndex-1)).addClass("b-p0").show()}ao.find(".b-page-"+(aq.currentIndex)).addClass("b-p1").show();ao.find(".b-page-"+(aq.currentIndex+1)).addClass("b-p2").show();if(aq.currentIndex+3<=aq.pageTotal){ao.find(".b-page-"+(aq.currentIndex+2)).addClass("b-p3").show();ao.find(".b-page-"+(aq.currentIndex+3)).addClass("b-p4").show()}I=ao.find(".b-pN");an=ao.find(".b-p0");am=ao.find(".b-p1");ak=ao.find(".b-p2");aj=ao.find(".b-p3");ag=ao.find(".b-p4");aP=ao.find(".b-pN .b-wrap");aw=ao.find(".b-p0 .b-wrap");M=ao.find(".b-p1 .b-wrap");y=ao.find(".b-p2 .b-wrap");e=ao.find(".b-p3 .b-wrap");aM=ao.find(".b-p4 .b-wrap");aI=ao.find(".b-wrap");if(aq.shadows){ao.find(".b-shadow-f, .b-shadow-b").remove();aO=a(k.sF).css(au.sF).appendTo(aj);aQ=a(k.sB).appendTo(an).css(au.sB)}},W=function(){var aX,h,aY,i,aT,aU,aS,aV,aW,aZ,j;d=ay=ar=o=false;if(aq.manual&&a.ui){aj.draggable({axis:"x",containment:[ao.offset().left,0,ak.offset().left+C-aH,s],drag:function(a0,a1){ar=true;aj.removeClass("b-grab").addClass("b-grabbing");aX=a1.originalPosition.left;h=a1.position.left;aY=aX-h;i=aY/aX;aT=i<0.5?i:(1-i);aU=(aT*aq.shadowBtmWidth*2)+c;aU=aY/aX>=0.5?aU-=c:aU;if(aq.shadows){aO.css({right:"-"+(aq.shadowTopFwdWidth*aT*2)+"px"});if(a.support.opacity){aO.css({opacity:aT*2})}else{aO.css({right:"auto",left:0.1*aj.width()})}}aS=x+aY/2;aS=aS>C?C:aS;aV=C-aS;if(aq.closed&&aq.autoCenter){if(aq.currentIndex==0){aW=0.5+0.5*i;aS=x+(x*i)+aY;aS=aS>C?C:aS;aV=C-aS;ak.css({left:C*i});ag.css({left:C*i});ao.width(aq.width*aW)}else{if(aq.currentIndex==aq.pageTotal-4){aW=(1-i)+0.5*i;aV=C-aS;ag.hide();ao.width(aq.width*aW)}else{ao.width(aq.width)}}}aj.width(aS);e.css({left:aU});ak.width(aV)},stop:function(a0,a1){aJ(false);if(i>aq.hoverThreshold){if(aq.shadows&&!a.support.opacity){aO.css({left:"auto",opacity:0})}at();aj.removeClass("b-grab b-grabbing")}else{ar=false;aj.removeClass("b-grabbing").addClass("b-grab");aO.animate({left:"auto",opacity:0},S.hover.speed,aq.easing).css(au.sF);if(aq.closed&&aq.autoCenter){if(aq.currentIndex==0){ak.animate({left:0},S.hover.speed,aq.easing);ag.animate({left:0},S.hover.speed,aq.easing);ao.animate({width:aq.width*0.5},S.hover.speed,aq.easing)}else{ao.animate({width:aq.width},S.hover.speed,aq.easing)}}}}});an.draggable({axis:"x",containment:[ao.offset().left+x,0,ao.offset().left+aq.width,s],drag:function(a0,a1){o=true;an.removeClass("b-grab").addClass("b-grabbing");aX=a1.originalPosition.left;h=a1.position.left;aY=h-aX;i=aY/(aq.width-aX);if(aq.closed&&aq.autoCenter&&aq.currentIndex==2){i=aY/(C-aX)}if(i>1){i=1}aT=i<0.5?i:(1-i);aU=(aT*aq.shadowBtmWidth*2)+c;aU=aY/aX>=0.5?aU-=c:aU;if(aq.shadows){if(a.support.opacity){aQ.css({opacity:aT*2})}else{aQ.css({left:aq.shadowTopBackWidth*aT*2})}}aS=i*(C-x)+x+aU;aZ=aS-aU;j=-aZ;if(aq.closed&&aq.autoCenter){if(aq.currentIndex==2){aW=(1-i)+0.5*i;aZ=(1-i)*aZ;j=-aZ-(aq.width-(aq.width*aW));I.hide();ak.css({left:C*(1-i)});ag.css({left:C*(1-i)});ao.width(aq.width*aW)}else{if(aq.currentIndex==aq.pageTotal-2){aW=0.5+0.5*i;ao.width(aq.width*aW)}else{ao.width(aq.width)}}}a1.position.left=aZ;an.css({width:aS});aw.css({right:aU});am.css({left:aZ,width:C-aZ});M.css({left:j})},stop:function(a0,a1){aJ(true);if(i>aq.hoverThreshold){D();an.removeClass("b-grab b-grabbing")}else{aQ.animate({opacity:0},S.hover.speed,aq.easing).css(au.sB);o=false;an.removeClass("b-grabbing").addClass("b-grab");if(aq.closed&&aq.autoCenter){if(aq.currentIndex==2){ak.animate({left:C},S.hover.speed*2,aq.easing);ag.animate({left:C},S.hover.speed*2,aq.easing);ao.animate({width:aq.width},S.hover.speed*2,aq.easing)}else{if(aq.currentIndex==aq.pageTotal-2){ao.animate({width:aq.width*0.5},S.hover.speed,aq.easing)}}}}}});a(ao).unbind("mousemove mouseout").bind("mousemove",function(a0){aY=a0.pageX-ao.offset().left;if(aY<S.hover.size){aa(false)}else{if(aY>C-S.hover.size&&aq.currentIndex==0&&aq.autoCenter&&aq.closed){aa(true)}else{if(aY>S.hover.size&&aY<aq.width-S.hover.size){aJ(false);aJ(true)}else{if(aY>aq.width-S.hover.size){aa(true)}}}}}).bind("mouseout",function(){aJ(false);aJ(true)})}},m=function(){ao.find(".b-shadow-f, .b-shadow-b, .b-p0, .b-p3").css({filter:"",zoom:""});if(aq.manual&&a.ui){ao.find(".b-page").draggable("destroy").removeClass("b-grab b-grabbing")}ao.find(".b-page").removeAttr("style");aI.removeAttr("style");aI.css(au.wrap);aw.css(au.p0wrap);am.css(au.p1);ak.css(au.p2);if(aq.closed&&aq.autoCenter&&aq.currentIndex>=aq.pageTotal-2){ak.hide()}I.css(au.pN);an.css(au.p0);aj.stop().css(au.p3);ag.css(au.p4);if(aq.closed&&aq.autoCenter&&aq.currentIndex==0){I.css({left:0});am.css({left:X});ak.css({left:0});aj.css({left:C});ag.css({left:0})}if(aq.closed&&aq.autoCenter&&(aq.currentIndex==0||aq.currentIndex>=aq.pageTotal-2)){if(aq.overlays){w.width("100%")}ao.width(C)}else{if(aq.overlays){w.width("50%")}ao.width(aq.width)}ao.find(".b-page").css({filter:"",zoom:""})},al=function(){ae();m();W()},at=function(){if(!Q){if(az&&aq.currentIndex+2>=aq.pageTotal){z(0)}else{z(aq.currentIndex+2)}}},D=function(){if(!Q){if(az&&aq.currentIndex-2<0){z(aq.pageTotal-2)}else{z(aq.currentIndex-2)}}},z=function(h){var i;if(h>aq.currentIndex&&h<aq.pageTotal&&h>=0&&!Q){Q=true;t=h-aq.currentIndex;aq.currentIndex=h;aq.before.call(this,aq);aN();if(h==aq.pageTotal-2){ap()}O(aq.currentIndex+1,aq);i=ar===true?aq.speed*(aj.width()/C):aE;aA(t,true,aO,i);if(aq.closed&&aq.autoCenter&&h-t==0){ak.stop().animate(S.p2closed,ar===true?i:i*2,aq.easing);ag.stop().animate(S.p4closed,ar===true?i:i*2,aq.easing)}else{ak.stop().animate(S.p2,i,ar===true?aq.easeOut:aq.easeIn)}if(ar){aj.animate(S.p3out,i,aq.easeOut);e.animate(S.p3wrapOut,i,aq.easeOut,function(){J()})}else{aj.stop().animate(S.p3in,i,aq.easeIn).animate(S.p3out,i,aq.easeOut);e.animate(S.p3wrapIn,i,aq.easeIn).animate(S.p3wrapOut,i,aq.easeOut,function(){J()})}}else{if(h<aq.currentIndex&&h<aq.pageTotal&&h>=0&&!Q){Q=true;t=aq.currentIndex-h;aq.currentIndex=h;aq.before.call(this,aq);aN();if(h==0){ap()}O(aq.currentIndex+1,aq);i=o===true?aq.speed*(an.width()/C):aE;aA(t,false,aQ,i);if(o){am.animate(S.p1,i,aq.easeOut);M.animate(S.p1wrap,i,aq.easeOut);if(aq.closed&&aq.autoCenter&&aq.currentIndex==0){an.animate(S.p0outClosed,i,aq.easeOut);ak.stop().animate(S.p2back,i,aq.easeOut)}else{an.animate(S.p0,i,aq.easeOut)}aw.animate(S.p0wrapDrag,i,aq.easeOut,function(){J()})}else{am.animate(S.p1,i*2,aq.easing);M.animate(S.p1wrap,i*2,aq.easing);if(aq.closed&&aq.autoCenter&&aq.currentIndex==0){an.animate(S.p0in,i,aq.easeIn).animate(S.p0outClosed,i,aq.easeOut);ak.stop().animate(S.p2back,i*2,aq.easing)}else{an.animate(S.p0in,i,aq.easeIn).animate(S.p0out,i,aq.easeOut)}aw.animate(S.p0wrapIn,i,aq.easeIn).animate(S.p0wrapOut,i,aq.easeOut,function(){J()})}}}},aa=function(h){if(h){if(!Q&&!d&&!ay&&!ar&&aq.currentIndex+2<=aq.pageTotal-2){ak.stop().animate(S.hover.p2,S.hover.speed,aq.easing);aj.addClass("b-grab");if(aq.closed&&aq.autoCenter&&aq.currentIndex==0){aj.stop().animate(S.hover.p3closed,S.hover.speed,aq.easing)}else{aj.stop().animate(S.hover.p3,S.hover.speed,aq.easing)}e.stop().animate(S.hover.p3wrap,S.hover.speed,aq.easing);if(aq.shadows&&!a.support.opacity){aO.css({right:"auto",left:"-40%"})}d=true}}else{if(!Q&&!ay&&!d&&!o&&aq.currentIndex-2>=0){am.stop().animate(S.hover.p1,S.hover.speed,aq.easing);an.addClass("b-grab");M.stop().animate(S.hover.p1wrap,S.hover.speed,aq.easing);an.stop().animate(S.hover.p0,S.hover.speed,aq.easing);aw.stop().animate(S.hover.p0wrap,S.hover.speed,aq.easing);if(aq.shadows&&!a.support.opacity){aQ.css({left:-0.38*C})}ay=true}}},aJ=function(h){if(h){if(!Q&&d&&!ar&&aq.currentIndex+2<=aq.pageTotal-2){if(aq.closed&&aq.autoCenter&&aq.currentIndex==0){ak.stop().animate(S.hover.p2closedEnd,S.hover.speed,aq.easing);aj.stop().animate(S.hover.p3closedEnd,S.hover.speed,aq.easing)}else{ak.stop().animate(S.hover.p2end,S.hover.speed,aq.easing);aj.stop().animate(S.hover.p3end,S.hover.speed,aq.easing)}e.stop().animate(S.hover.p3wrapEnd,S.hover.speed,aq.easing);if(aq.shadows&&!a.support.opacity){aO.css({left:"auto"})}d=false}}else{if(!Q&&ay&&!o&&aq.currentIndex-2>=0){am.stop().animate(S.hover.p1end,S.hover.speed,aq.easing);M.stop().animate(S.hover.p1wrapEnd,S.hover.speed,aq.easing);an.stop().animate(S.hover.p0end,S.hover.speed,aq.easing);aw.stop().animate(S.hover.p0wrapEnd,S.hover.speed,aq.easing);ay=false}}},aA=function(j,i,aS,h){if(i&&j>2){ao.find(".b-p3, .b-p4").removeClass("b-p3 b-p4").hide();ao.find(".b-page-"+aq.currentIndex).addClass("b-p3").show().stop().css(au.p3);ao.find(".b-page-"+(aq.currentIndex+1)).addClass("b-p4").show().css(au.p4);ao.find(".b-page-"+aq.currentIndex+" .b-wrap").show().css(au.wrap);ao.find(".b-page-"+(aq.currentIndex+1)+" .b-wrap").show().css(au.wrap);aj=ao.find(".b-p3");ag=ao.find(".b-p4");e=ao.find(".b-p3 .b-wrap");aM=ao.find(".b-p4 .b-wrap");if(aq.closed&&aq.autoCenter&&aq.currentIndex-j==0){aj.css({left:C});ag.css({left:0})}if(d){aj.css({left:aq.width-40,width:20,"padding-left":10})}if(aq.shadows){ao.find(".b-shadow-f").remove();aO=a(k.sF).css(au.sF).appendTo(aj);aS=aO}}else{if(!i&&j>2){ao.find(".b-pN, .b-p0").removeClass("b-pN b-p0").hide();ao.find(".b-page-"+aq.currentIndex).addClass("b-pN").show().css(au.pN);ao.find(".b-page-"+(aq.currentIndex+1)).addClass("b-p0").show().css(au.p0);ao.find(".b-page-"+aq.currentIndex+" .b-wrap").show().css(au.wrap);ao.find(".b-page-"+(aq.currentIndex+1)+" .b-wrap").show().css(au.wrap);I=ao.find(".b-pN");an=ao.find(".b-p0");aP=ao.find(".b-pN .b-wrap");aw=ao.find(".b-p0 .b-wrap");if(aq.closed&&aq.autoCenter){I.css({left:0})}aw.css(au.p0wrap);if(ay){an.css({left:10,width:40});aw.css({right:10})}if(aq.shadows){ao.find(".b-shadow-b, .b-shadow-f").remove();aQ=a(k.sB).appendTo(an).css(au.sB);aS=aQ}}}if(aq.closed){if(!i&&aq.currentIndex==0){I.hide()}else{if(!i){I.show()}}if(i&&aq.currentIndex>=aq.pageTotal-2){ag.hide()}else{if(i){ag.show()}}}if(aq.shadows){if(a.support.opacity){if(!ar&&!o){aS.animate({opacity:1},h,aq.easeIn)}aS.animate({opacity:0},h,aq.easeOut)}else{if(i){aS.animate({right:aq.shadowTopFwdWidth},h*2,aq.easeIn)}else{aS.animate({left:aq.shadowTopBackWidth},h*2,aq.easeIn)}}}if(aq.closed&&aq.autoCenter){if(aq.currentIndex==0){aj.hide();ag.hide();ao.animate({width:C},!ar&&!o?h*2:h,aq.easing)}else{if(aq.currentIndex>=aq.pageTotal-2){an.hide();I.hide();ao.animate({width:C},h*2,aq.easing)}else{ao.animate({width:aq.width},h*2,aq.easing)}}}},J=function(){al();aN();aq.after.call(this,aq);ap();Q=false;if(aq.auto&&aq.delay){clearTimeout(Y);Y=setTimeout(function(){if(aq.direction==av.leftToRight){at()}else{D()}},aq.delay)}},af=function(){au={wrap:{left:0,width:C-(aq.pagePadding*2)-(aq.pageBorder*2),height:s-(aq.pagePadding*2)-(aq.pageBorder*2),padding:aq.pagePadding},p0wrap:{right:0,left:"auto"},p1:{left:0,width:C,height:s},p2:{left:C,width:C,opacity:1,height:s},pN:{left:0,width:C,height:s},p0:{left:0,width:0,height:s},p3:{left:C*2,width:0,height:s,paddingLeft:0},p4:{left:C,width:C,height:s},sF:{right:0,width:C,height:s},sB:{left:0,width:C,height:s}};c=10;aH=aq.hoverWidth+c;x=(aq.hoverWidth/2)+c;S={hover:{speed:aq.hoverSpeed,size:aq.hoverWidth,p2:{width:C-x},p3:{left:aq.width-aH,width:x},p3closed:{left:C-aq.hoverWidth,width:x},p3wrap:{left:c},p2end:{width:C},p2closedEnd:{width:C,left:0},p3end:{left:aq.width,width:0},p3closedEnd:{left:C,width:0},p3wrapEnd:{left:10},p1:{left:x,width:C-x},p1wrap:{left:"-"+x+"px"},p0:{left:x,width:x},p0wrap:{right:c},p1end:{left:0,width:C},p1wrapEnd:{left:0},p0end:{left:0,width:0},p0wrapEnd:{right:0}},p2:{width:0},p2closed:{width:0,left:C},p4closed:{left:C},p3in:{left:ab,width:ab,paddingLeft:aq.shadowBtmWidth},p3inDrag:{left:C/4,width:C*0.75,paddingLeft:aq.shadowBtmWidth},p3out:{left:0,width:C,paddingLeft:0},p3wrapIn:{left:aq.shadowBtmWidth},p3wrapOut:{left:0},p1:{left:C,width:0},p1wrap:{left:X},p0:{left:C,width:C},p0in:{left:ab,width:ab},p0out:{left:C,width:C},p0outClosed:{left:0,width:C},p2back:{left:0},p0wrapDrag:{right:0},p0wrapIn:{right:aq.shadowBtmWidth},p0wrapOut:{right:0}}},v=function(){aq.pageTotal=ao.children().length;if(!Z){if(!aq.width){aq.width=ao.width()}else{if(typeof aq.width=="string"&&aq.width.indexOf("%")!=-1){K=true;U=aq.width;aq.width=(aq.width.replace("%","")/100)*parseFloat(ao.parent().css("width"))}}if(!aq.height){aq.height=ao.height()}else{if(typeof aq.height=="string"&&aq.height.indexOf("%")!=-1){ad=true;A=aq.height;aq.height=(aq.height.replace("%","")/100)*parseFloat(ao.parent().css("height"))}}ao.width(aq.width);ao.height(aq.height);C=aq.width/2;X="-"+(C)+"px";ab=C/2;s=aq.height;aE=aq.speed/2;aq.currentIndex=0;if(aq.direction==av.leftToRight){aq.currentIndex=0}else{if(aq.direction==av.rightToLeft){aq.currentIndex=aq.pageTotal-2}}if(!isNaN(aq.startingPage)&&aq.startingPage<=aq.pageTotal&&aq.startingPage>0){if((aq.startingPage%2)!=0){aq.startingPage--}aq.currentIndex=aq.startingPage}if(aq.closed&&aq.autoCenter){if(aq.currentIndex==0){ao.width(C)}else{if(aq.currentIndex>=aq.pageTotal-2){ao.width(C)}}}if(aq.name){document.title=aq.name}else{aq.name=document.title}if(aq.shadows){aq.shadowTopFwdWidth="-"+aq.shadowTopFwdWidth+"px";aq.shadowTopBackWidth="-"+aq.shadowTopBackWidth+"px"}}af();var aW,aU,a0,aY,aT,i,h,aZ,j,aV,aX,a1,aS;if(aq.menu){q=a(aq.menu).addClass("b-menu");if(aq.pageSelector){aW=a('<div class="b-selector b-selector-page"><span class="b-current">'+(aq.currentIndex+1)+" - "+(aq.currentIndex+2)+"</span></div>").appendTo(q);aU=a("<ul></ul>").appendTo(aW).empty().css("height","auto");for(N=0;N<aq.pageTotal;N+=2){L=N;a0=(L+1)+"-"+(L+2);if(aq.closed){L--;if(N==0){a0="1"}else{if(N==aq.pageTotal-2){a0=aq.pageTotal-2}else{a0=(L+1)+"-"+(L+2)}}if(aq.covers){L--;if(N==0){a0=""}else{if(N==aq.pageTotal-2){a0=""}else{a0=(L+1)+"-"+(L+2)}}}}if(N==0){aW.find(".b-current").text(a0)}aY=p[N].title;if(aY==""){aY=p[N+1].title}if(aq.direction==av.rightToLeft){aY=p[Math.abs(N-aq.pageTotal)-1].title;if(aY==""){aY=p[Math.abs(N-aq.pageTotal)-2].title}}aT=a('<li><a href="#'+ah+(N+1)+'" id="selector-page-'+N+'"><span class="b-text">'+aY+'</span><span class="b-num">'+a0+"</span></a></li>").appendTo(aU);if(!aq.hash){aT.find("a").click(function(){if(aq.direction==av.rightToLeft){aW.find(".b-current").text(a(this).find(".b-num").text());z(Math.abs(parseInt(a(this).attr("id").replace("selector-page-",""))-aq.pageTotal)-2)}else{z(parseInt(a(this).attr("id").replace("selector-page-","")))}return false})}}i=aU.height();aU.css({height:0,"padding-bottom":0});aW.unbind("hover").hover(function(){aU.stop().animate({height:i,paddingBottom:10},500)},function(){aU.stop().animate({height:0,paddingBottom:0},500)})}if(aq.chapterSelector){h=p[aq.currentIndex].chapter;if(h==""){h=p[aq.currentIndex+1].chapter}aZ=a('<div class="b-selector b-selector-chapter"><span class="b-current">'+h+"</span></div>").appendTo(q);j=a("<ul></ul>").appendTo(aZ).empty().css("height","auto");for(N=0;N<aq.pageTotal;N+=1){aV;if(p[N].chapter!=""&&typeof p[N].chapter!="undefined"){if(aq.direction==av.rightToLeft){L=N;if(L%2!=0){L--}aZ.find(".b-current").text(p[N].chapter);aV=a('<li><a href="#'+ah+(L+1)+'" id="selector-page-'+(L)+'"><span class="b-text">'+p[N].chapter+"</span></a></li>").prependTo(j)}else{aV=a('<li><a href="#'+ah+(N+1)+'" id="selector-page-'+N+'"><span class="b-text">'+p[N].chapter+"</span></a></li>").appendTo(j)}if(!aq.hash){aV.find("a").click(function(){if(aq.direction==av.rightToLeft){aZ.find(".b-current").text(a(this).find(".b-text").text());z(Math.abs(parseInt(a(this).attr("id").replace("selector-page-",""))-aq.pageTotal)-2)}else{z(parseInt(a(this).attr("id").replace("selector-page-","")))}return false})}}}aX=j.height();j.css({height:0,"padding-bottom":0});aZ.unbind("hover").hover(function(){j.stop().animate({height:aX,paddingBottom:10},500)},function(){j.stop().animate({height:0,paddingBottom:0},500)})}}aB=a('<div class="b-controls"></div>').appendTo(ao);if(!Z){if(aq.manual&&a.ui){aq.overlays=false}if(aq.next){F=a(aq.next);F.click(function(a2){a2.preventDefault();at()})}if(aq.prev){E=a(aq.prev);E.click(function(a2){a2.preventDefault();D()})}}if(aq.overlays){aF=a('<div class="b-overlay b-overlay-prev b-prev" title="'+aq.previousControlTitle+'"></div>').appendTo(aB);aG=a('<div class="b-overlay b-overlay-next b-next" title="'+aq.nextControlTitle+'"></div>').appendTo(aB);w=ao.find(".b-overlay");if(a.browser.msie){w.css({background:"#fff",filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=0) !important"})}}if(aq.tabs){aC=a('<div class="b-tab b-tab-prev b-prev" title="'+aq.previousControlTitle+'">'+aq.previousControlText+"</div>").appendTo(aB);aD=a('<div class="b-tab b-tab-next b-next" title="'+aq.nextControlTitle+'">'+aq.nextControlText+"</div>").appendTo(aB);V=ao.find(".b-tab");if(aq.tabWidth){V.width(aq.tabWidth)}if(aq.tabHeight){V.height(aq.tabHeight)}V.css({top:"-"+aD.outerHeight()+"px"});ao.css({marginTop:aD.outerHeight()});if(aq.direction==av.rightToLeft){aD.html(aq.previousControlText).attr("title",aq.previousControlTitle);aC.html(aq.nextControlText).attr("title",aq.nextControlTitle)}}else{ao.css({marginTop:0})}if(aq.arrows){G=a('<div class="b-arrow b-arrow-prev b-prev" title="'+aq.previousControlTitle+'"><div>'+aq.previousControlText+"</div></div>").appendTo(aB);H=a('<div class="b-arrow b-arrow-next b-next" title="'+aq.nextControlTitle+'"><div>'+aq.nextControlText+"</div></div>").appendTo(aB);r=ao.find(".b-arrow");if(aq.direction==av.rightToLeft){H.html("<div>"+aq.previousControlText+"</div>").attr("title",aq.previousControlTitle);G.html("<div>"+aq.nextControlText+"</div>").attr("title",aq.nextControlTitle)}}g=aB.find(".b-next");f=aB.find(".b-prev");g.bind("click",function(a2){a2.preventDefault();at()});f.bind("click",function(a2){a2.preventDefault();D()});if(aq.overlays&&aq.hovers){g.unbind("mouseover mouseout").bind("mouseover",function(){aa(true)}).bind("mouseout",function(){aJ(true)});f.unbind("mouseover mouseout").bind("mouseover",function(){aa(false)}).bind("mouseout",function(){aJ(false)})}if(aq.arrows){if(aq.arrowsHide){if(a.support.opacity){g.hover(function(){H.find("div").stop().fadeTo("fast",1)},function(){H.find("div").stop().fadeTo("fast",0)});f.hover(function(){G.find("div").stop().fadeTo("fast",1)},function(){G.find("div").stop().fadeTo("fast",0)})}else{g.hover(function(){H.find("div").show()},function(){H.find("div").hide()});f.hover(function(){G.find("div").show()},function(){G.find("div").hide()})}}else{H.find("div").show();G.find("div").show()}}if(!Z){if(aq.keyboard){a(document).keyup(function(a2){if(a2.keyCode==37&&aq.keyboard){D()}else{if(a2.keyCode==39&&aq.keyboard){at()}}})}if(aq.hash){l();clearInterval(P);P=setInterval(function(){ai()},250)}if(K||ad){a(window).resize(function(){ac()})}if(aq.auto&&aq.delay){clearTimeout(Y);Y=setTimeout(function(){if(aq.direction==av.leftToRight){at()}else{D()}},aq.delay);az=true;if(aq.pause){a1=a(aq.pause);a1.click(function(a2){a2.preventDefault();if(az){clearTimeout(Y);az=false}})}if(aq.play){aS=a(aq.play);aS.click(function(a2){a2.preventDefault();if(!az){clearTimeout(Y);Y=setTimeout(function(){if(aq.direction==av.leftToRight){at()}else{D()}},aq.delay);az=true}})}}}},ac=function(){if(K){aq.width=(U.replace("%","")/100)*parseFloat(ao.parent().css("width"));ao.width(aq.width);C=aq.width/2;X="-"+(C)+"px";ab=C/2}if(ad){aq.height=(A.replace("%","")/100)*parseFloat(ao.parent().css("height"));ao.height(aq.height);s=aq.height}af();m()},ap=function(){if(aq.overlays||aq.tabs||aq.arrows){if(a.support.opacity){if(aq.currentIndex>=2&&aq.currentIndex!=0){f.fadeIn("fast").css("cursor",aq.cursor)}else{f.fadeOut("fast").css("cursor","default")}if(aq.currentIndex<aq.pageTotal-2){g.fadeIn("fast").css("cursor",aq.cursor)}else{g.fadeOut("fast").css("cursor","default")}}else{if(aq.currentIndex>=2&&aq.currentIndex!=0){f.show().css("cursor",aq.cursor)}else{f.hide().css("cursor","default")}if(aq.currentIndex<aq.pageTotal-2){g.show().css("cursor",aq.cursor)}else{g.hide().css("cursor","default")}}}},aN=function(){if(aq.pageSelector){var h="";if(aq.direction==av.rightToLeft){h=(Math.abs(aq.currentIndex-aq.pageTotal)-1)+" - "+((Math.abs(aq.currentIndex-aq.pageTotal)));if(aq.closed){if(aq.currentIndex==aq.pageTotal-2){h="1"}else{if(aq.currentIndex==0){h=aq.pageTotal-2}else{h=(Math.abs(aq.currentIndex-aq.pageTotal)-2)+" - "+((Math.abs(aq.currentIndex-aq.pageTotal)-1))}}if(aq.covers){if(aq.currentIndex==aq.pageTotal-2){h=""}else{if(aq.currentIndex==0){h=""}else{h=(Math.abs(aq.currentIndex-aq.pageTotal)-3)+" - "+((Math.abs(aq.currentIndex-aq.pageTotal)-2))}}}}}else{h=(aq.currentIndex+1)+" - "+(aq.currentIndex+2);if(aq.closed){if(aq.currentIndex==0){h="1"}else{if(aq.currentIndex==aq.pageTotal-2){h=aq.pageTotal-2}else{h=(aq.currentIndex)+"-"+(aq.currentIndex+1)}}if(aq.covers){if(aq.currentIndex==0){h=""}else{if(aq.currentIndex==aq.pageTotal-2){h=""}else{h=(aq.currentIndex-1)+"-"+(aq.currentIndex)}}}}}a(aq.menu+" .b-selector-page .b-current").text(h)}if(aq.chapterSelector){if(p[aq.currentIndex].chapter!=""){a(aq.menu+" .b-selector-chapter .b-current").text(p[aq.currentIndex].chapter)}else{if(p[aq.currentIndex+1].chapter!=""){a(aq.menu+" .b-selector-chapter .b-current").text(p[aq.currentIndex+1].chapter)}}if(aq.direction==av.rightToLeft&&p[aq.currentIndex+1].chapter!=""){a(aq.menu+" .b-selector-chapter .b-current").text(p[aq.currentIndex+1].chapter)}else{if(p[aq.currentIndex]!=""){a(aq.menu+" .b-selector-chapter .b-current").text(p[aq.currentIndex].chapter)}}}},l=function(){R=B();if(!isNaN(R)&&R<=aq.pageTotal-1&&R>=0&&R!=""){if((R%2)!=0){R--}aq.currentIndex=R}else{O(aq.currentIndex+1,aq)}T=R},ai=function(){R=B();if(!isNaN(R)&&R<=aq.pageTotal-1&&R>=0){if(R!=aq.currentIndex&&R.toString()!=T){if((R%2)!=0){R--}document.title=aq.name+aq.hashTitleText+(R+1);if(!Q){z(R);T=R}}}},B=function(){var i,h;i=window.location.hash.split("/");if(i.length>1){h=parseInt(i[2])-1;if(aq.direction==av.rightToLeft){h=Math.abs(h+1-aq.pageTotal)}return h}else{return""}},O=function(i,h){if(h.hash){if(h.direction==av.rightToLeft){i=Math.abs(i-h.pageTotal)}window.location.hash=ah+i}},u=function(h,i){if(h=="start"){h=0}else{if(h=="end"){h=ao.data("total")}else{if(typeof h=="number"){if(h<0||h>ao.data("total")){return}}else{if(typeof h=="undefined"){return}}}}if(typeof i=="undefined"||i==""){return}ao.find(".b-wrap").unwrap();ao.find(".b-wrap").children().unwrap();ao.find(".b-counter, .b-page-blank, .b-page-empty, .b-shadow-f, .b-shadow-b").remove();aB.remove();aB=null;if(aq.menu){aq.menu.removeClass("b-menu").children().remove()}if(aq.direction==av.rightToLeft){a(ao.children().get().reverse()).each(function(){a(this).appendTo(ao)})}if(aq.closed&&aq.covers&&h==ao.data("total")){ao.children(":eq("+(h-1)+")").before(i)}else{if(aq.closed&&aq.covers&&h==0){ao.children(":eq("+h+")").after(i)}else{if(h==ao.data("total")){ao.children(":eq("+(h-1)+")").after(i)}else{ao.children(":eq("+h+")").before(i)}}}ao.data("total",ao.children().length);n()};return{init:ax,next:at,prev:D,goToPage:function(h){if(h%2!=0){h-=1}if(aq.direction==av.rightToLeft){h=Math.abs(h-aq.pageTotal)-2}z(h)},addPage:u,options:aq}}a.fn.booklet.defaults={name:null,width:600,height:400,speed:1000,direction:"LTR",startingPage:0,easing:"easeInOutQuad",easeIn:"easeInQuad",easeOut:"easeOutQuad",closed:false,closedFrontTitle:"Beginning",closedFrontChapter:"Beginning of Book",closedBackTitle:"End",closedBackChapter:"End of Book",covers:false,autoCenter:false,pagePadding:10,pageNumbers:true,pageBorder:0,manual:true,hovers:true,hoverWidth:50,hoverSpeed:500,hoverThreshold:0.25,overlays:true,tabs:false,tabWidth:60,tabHeight:20,nextControlText:"Next",previousControlText:"Previous",nextControlTitle:"Next Page",previousControlTitle:"Previous Page",arrows:false,arrowsHide:false,cursor:"pointer",hash:false,hashTitleText:" - Page ",keyboard:true,next:null,prev:null,auto:false,delay:5000,pause:null,play:null,menu:null,pageSelector:false,chapterSelector:false,shadows:true,shadowTopFwdWidth:166,shadowTopBackWidth:166,shadowBtmWidth:50,before:function(){},after:function(){}}})(jQuery);