/*
 MegaZine3 jQuery Plugin v0.1
 This file is part of the MegaZine3 engine.
 Copyright (C) 2007-2011, VservU GmbH (Florian Nuecke and Hans J. Nuecke)
 License: http://www.megazine3.de/license
*/
var h=null;function i(){return function(){}}function l(b){return function(){return b}}
(function(b){function o(a,b){return typeof a==="undefined"||a===h?b:typeof a==="string"?a:String(a)}function q(a,b){return typeof a==="undefined"||a===h?b:typeof a==="boolean"?a:a.toLowerCase()==="true"||a.toLowerCase()==="yes"||a==="1"}function F(a,b){return typeof a==="undefined"||a===h?b:typeof a==="number"?a:Number(a)}function G(a,b){return typeof a==="undefined"||a===h?b:typeof a==="object"?a:a.split(",")}function y(a,b){return!a?b:b.match(/^(?:([^:\/?\#]+):)?(?:\/\/([^\/?\#]*))?([^?\#]*)(?:\?([^\#]*))?(?:\#(.*))?/)[1]?
b:a.charAt(a.length-1)!=="/"&&b.charAt(0)!=="/"?a+"/"+b:a+b}function H(b){var f=[];if(b)for(var p in b.attributes)isNaN(p)||f.push(b.attributes[p].name);return f}function I(a,f,p,z,r){function B(){if(r){b("head > meta[name=viewport]").attr("content","width=device-width,minimum-scale=1.0,maximum-scale=1.0");var w=c.get("pagewidth"),a=c.get("pageheight"),w=f.width()/(k?w*2:w),a=f.height()/a,a=Math.min(1,w,a);b("head > meta[name=viewport]").attr("content","width=device-width,maximum-scale="+a+",minimum-scale="+
a)}}var m=h,e=[],k="invalid",j=h,c={a:function(b,a,c){c||(c=typeof a==="number"?F:typeof a==="boolean"?q:o);this[b]={value:a,g:c}},set:function(b,a){if(typeof this[b]!=="undefined")this[b].value=this[b].g?this[b].g(a,this[b].value):a},get:function(b){return this[b].value}};this.f=function(b){if(Boolean(b)!==k){var a=this.getCurrentPage();j.stop();k=Boolean(b);b=c.get("pagewidth");k?(m.css("width",b*2+"px"),m.css("margin-left","-"+b+"px"),m.find(".mz3-page-container").css("width",e.length*b+"px"),
m.find(".mz3-page-spread:first-child,.mz3-page-spread:last-child").css("width",b*2),j.options.snap=".mz3-pageside-odd",a+=a%2):(m.css("width",b+"px"),m.css("margin-left","-"+b/2+"px"),m.find(".mz3-page-container").css("width",(e.length-1)*b+"px"),m.find(".mz3-page-spread:first-child,.mz3-page-spread:last-child").css("width",b),j.options.snap=".mz3-pageside");B();var f=this;setTimeout(function(){j.refresh();f.gotoPage(a,!0)},0)}};this.gotoPage=function(b,a){console.log("goto "+b);b<0?b=0:b>e.length-
2&&(b=e.length-2);b=(b+(k?b%2:0))/(k?2:1);a?j.scrollToPage(b,0,1):j.scrollToPage(b,0,c.get("dragspeed")*1E3)};this.gotoPreviousPage=function(b){this.gotoPage(this.getCurrentPage()-(k?2:1),b)};this.gotoNextPage=function(b){this.gotoPage(this.getCurrentPage()+(k?2:1),b)};this.gotoFirstPage=function(b){this.gotoPage(0,b)};this.gotoLastPage=function(b){this.gotoPage(e.length,b)};this.getCurrentPage=function(){return k?j.currPageX*2:j.currPageX};this.getPageCount=function(){return e.length};this.getPageHeight=
function(){return c.get("pageheight")};this.getPageWidth=function(){return c.get("pagewidth")};this.getFlipState=l("megazine_flip_state_ready");this.getLoadState=l("megazine_load_state_loaded");this.gotoNextChapter=i();this.gotoPreviousChapter=i();this.hasShadows=l(!1);this.hasReflection=l(!1);this.isCornerHintingEnabled=l(!1);this.getInstantJumpCount=l(0);this.isDraggingEnabled=l(!0);this.isTurningEnabled=l(!0);this.isMuted=l(!1);this.setCornerHintingEnabled=i();this.setDraggingEnabled=i();this.setTurningEnabled=
i();this.setInstantJumpCount=i();this.setMuted=i();this.setShadows=i();this.setReflection=i();this.getRotation=l(0);this.setRotation=i();this.getZoom=l(1);this.setZoom=i();this.getLiquidScaling=l(!1);this.setLiquidScaling=i();this.zoomIn=i();this.zoomOut=i();this.zoomFit=i();this.addChapter=i();this.addChapterAt=i();this.addPage=i();this.addPageIn=i();this.addPageAt=i();this.removeChapter=i();this.removePage=i();this.getLanguage=l("en");this.setLanguage=i();this.getAllLanguages=function(){return["en"]};
(function(k){function s(a){function c(b,a){if(typeof b.attr(a)==="undefined"){var e=b.find(a+"[lang=en],"+a+":not([lang])");return e.length>0?e[0].textContent:h}else return b.attr(a)}function k(a,d){c(a,"width")!==h&&d.css("width",c(a,"width")+"px");c(a,"height")!==h&&d.css("height",c(a,"height")+"px");var e=c(a,"url");e!==h&&(e=y(p,e),$a=b("<a/>"),$a.css("width",d.css("width")),$a.css("height",d.css("height")),$a.attr("href",e),d.wrap($a),d=$a);d.css("position","absolute");d.css("left",0);d.css("top",
0);c(a,"position")!==h&&c(a,"position").split(" ").forEach(function(b){switch(b){case "center":d.css("left","50%");d.css("margin-left","-"+d.width()/2+"px");break;case "right":d.css("right",0);break;case "middle":d.css("top","50%");d.css("margin-top","-"+d.height()/2+"px");break;case "bottom":d.css("bottom",0)}});c(a,"left")!==h&&(d.css("margin-left",""),d.css("right",""),d.css("left",c(a,"left")+"px"));c(a,"top")!==h&&(d.css("margin-top",""),d.css("bottom",""),d.css("top",c(a,"top")+"px"));return d}
var e=x;typeof a.attr("bgcolor")!=="undefined"&&(e=Number(a.attr("bgcolor")),e=e.toString(16),e="#"+e.substring(e.length-6));var g=a[0].tagName.toLowerCase()==="spreadpage",f=b("<div/>");f.css({position:"absolute",overflow:"hidden","background-color":e,height:A+"px",width:(g?t*2:t)+"px"});f.addClass("mz3-pageside");C%2&&f.addClass("mz3-pageside-odd");var j={area:function(a){if(c(a,"url")===h)return h;if(!(c(a,"width")===h||c(a,"height")===h)){var d=b("<div/>");return k(a,d)}},img:function(a){var d=
c(a,"src-alt")||c(a,"src");if(d)d=y(p,d);else return h;var e=b("<img/>");e.load(function(){e.css("width",this.naturalWidth+"px");e.css("height",this.naturalHeight+"px");k(a,e)});e.attr("src",d);return e},vid:function(a){var d={b:c(a,"src"),c:c(a,"src-alt-h264"),d:c(a,"src-alt-ogg"),e:c(a,"src-alt-webm")},e={c:'video/mp4; codecs="avc1.42E01E, mp4a.40.2"',d:'video/ogg; codecs="theora, vorbis"',e:'video/webm; codecs="vp8, vorbis"'};if(!d.b&&!d.c&&!d.d&&!d.e)return h;else for(var f in d)d[f]&&(d[f]=y(p,
d[f]));var j=b("<div/>"),g=b("<video/>");g.css("width","100%");g.css("height","100%");j.append(g);q(c(a,"loop"),!0)&&g.attr("loop","loop");q(c(a,"autoplay"),!0)&&!c(a,"preview")&&g.attr("autoplay","autoplay");(window.orientation||c(a,"gui"))&&g.attr("controls","controls");g.one("loadedmetadata",function(){j.css("width",this.videoWidth+"px");j.css("height",this.videoHeight+"px");var c=!1;b(this).click(function(){c?this.pause():this.play();c=!c});j.parent()[0].tagName.toLowerCase()==="a"&&j.unwrap();
k(a,j)});g.one("error",i());$element=k(a,j);for(f in d)f==="flash"?d.b&&!d.c&&!d.d&&!d.e&&g.attr("src",d.b):d[f]&&($source=b("<source/>"),$source.attr("src",d[f]),$source.attr("type",e[f]),g.append($source));g[0].load();return $element}};a.children().each(function(){var a=this.tagName.toLowerCase();j[a]?f.append(j[a](b(this))):console.log('Unknown element of type "'+a+'".')});++C;return f}function o(){var a=b("<div/>");a.css("position","absolute");a.css("width",t*2+"px");a.css("height",A+"px");var c=
b("<div/>");c.css("position","relative");c.css("width","100%");c.css("height","100%");a.append(c);c.append(g[0]).append(g[1]);e.push(g[0]);e.push(g[1]);g=[h,h]}c.a("startpage",0);c.a("pageoffset",0);c.a("dragspeed",0.3);c.a("clickrange",0);c.a("ignoresides",!1);c.a("dragarea",["top","middle","bottom"],G);c.a("loop",!1);c.a("centercovers",!0);c.a("rotate",0);c.a("zoommaxscale",1);c.a("zoomminscale",1);c.a("ltr",!0);c.a("bgcolor",4291611852);c.a("pageheight",400);c.a("pagewidth",275);H(a[0]).forEach(function(b){c.set(b,
a.attr(b))});var t=c.get("pagewidth"),A=c.get("pageheight"),x=c.get("bgcolor"),x=x.toString(16),x="#"+x.substring(x.length-6),g=[h,h],C=0;a.find("page, spreadpage").each(function(){if(this.tagName.toLowerCase()==="spreadpage")C%2===0&&(g[1]=s(b("<page/>")),o()),g[0]=s(b(this)),g[1]=s(b("<page/>")),g[1].css("visibility","hidden");else if(C%2===0)g[1]=s(b(this));else{g[0]=s(b(this));return}o()});(g[0]||g[1])&&o();var u=b("<div/>");u.css({position:"absolute",width:t+"px",height:A+"px",left:"50%",top:"50%",
"margin-left":"-"+t/2+"px","margin-top":"-"+A/2+"px"});f.append(u);var D=b("<div/>");D.css({position:"relative",overflow:"hidden",width:"100%",height:"100%"});u.append(D);var n=b("<div/>");n.css({position:"absolute",height:A+"px",width:(e.length-1)*t+"px"});n.addClass("mz3-page-container");D.append(n);var v=b("<div/>");v.css({position:"relative",height:"100%",width:"100%"});n.append(v);v.append(b("<div/>").addClass("mz3-pageside-odd").css({width:"1px",height:"1px"}));for(n=0;n<e.length;n+=1)e[n]&&
(e[n].css("left",n*t+"px"),v.append(e[n]));v="mz3pc"+Math.floor(Math.random()*1E9);D.attr("id",v);j=new iScroll(v,{zoom:!0,zoomMax:c.get("zoommaxscale")});m=u;k.gotoPage(0,!0);r&&(b("head > meta[name=viewport]").length===0&&b("head").append(b('<meta name="viewport" content="" />')),B());if(z){var E;"onorientationchange"in window?(E=function(){return(window.orientation+360)%360%180},u="orientationchange"):(E=function(){return b(window).width()>b(window).height()},u="resize");b(window).bind(u,function(){k.f(E())});
k.f(E())}window.MegaZine&&(MegaZine.getMovie=function(){return k})})(this)}b.fn.mz3js=function(){if(this&&this.length!==0){var a=this,f=this.attr("id"),p=o(this.attr("data-mz3-swf"),"megazine/preloader.swf"),z=o(this.attr("data-mz3-xml"),"megazine.mz3"),r=o(this.attr("data-mz3-basepath"),""),B=q(this.attr("data-mz3-autoadjust"),!0),m=q(this.attr("data-mz3-viewport"),!0),e=q(this.attr("data-mz3-logtojs"),!1),k=o(this.attr("data-mz3-wmode"),""),j=o(this.attr("data-mz3-bgcolor"),"#33333"),c=q(this.attr("data-mz3-forcejs"),
!1),w=q(this.attr("data-mz3-nojs"),!1);if(z){try{if(!window.swfobject)throw"MegaZine3 requires swfobject to initialize Flash.";if(!c&&swfobject.hasFlashPlayerVersion("10.0.0")){swfobject.embedSWF(p,f,"100%","100%","10.0.0","js/expressInstall.swf",{basePath:r,xmlFile:z,logToJsConsole:String(e)},{wmode:k,menu:"false",scale:"noScale",allowFullscreen:"true",allowScriptAccess:"always",bgcolor:j},{id:f});window.MegaZine&&(MegaZine.megazine=f);return}}catch(s){console.warn("Could not embed Flash: "+s)}if(!w||
c)r=y(p.substring(0,p.lastIndexOf("/")+1),r),b.ajax({url:y(r,z),dataType:"xml",success:function(c){a.empty();a.css({position:"relative","background-color":j});a.addClass("mz3");new I(b(c.documentElement),a,r,B,m)}})}}}})(jQuery);

