/**
*
* title: BEFORE/AFTER VIEWER - jQuery plugin
*
* author: Ovidiu Stefancu
* http:www.wpworks.net
*
* info: File available at http://codecanyon.net/user/wickedpixel
*
* ver: 2.0 : 2013-may-07
*/
var WPW=WPW||{};WPW.baViewersCount=0;(function(b){var a=function(m,n){var g=this;g.cfg=b.extend({},b.fn.wpwBAgallery.defaults,n);g.galleryNode=b(m);g.currentIndex=0;g.imageNodes=b("img",g.galleryNode).detach();g.nrItems=g.imageNodes.length;if(!g.nrItems){return}g.galleryNode.addClass("wpw-ba-loading");g.galleryNode.addClass("wpw-ba-viewer-block");g.items=[];g.containerPosition=0;g.moverMargin=0;g.galleryNode.addClass("wpw-ba-viewer");g.mover=b("
");g.galleryWidth=0;g.galleryHeight=0;var f="easeInOutExpo";var k=function(e,p,o){if(g.galleryNode.attr("data-"+e)){g.cfg[e]=g.galleryNode.attr("data-"+e);if(g.cfg[e]==="false"){g.cfg[e]=false}if(g.cfg[e]==="true"){g.cfg[e]=true}if(o){g.cfg[e]=parseFloat(g.cfg[e])}if(p){g.cfg[e]=parseInt(g.cfg[e],10)}}};k("width");k("maxWidth",1);k("maxHeight",1);k("height");k("disableIntro");k("hideTitles");k("lightbox");k("animSpeed",1);k("startPercent",0,1);g.setOption=function(e,o){g.cfg[e]=o};g.lightbox=new function(){var e=this;e.preset=function(){if(e.isPreset){return}e.isPreset=1;e.node=b("");e.bg=b("");e.node.append(e.bg);b(document).keyup(function(o){if(o.keyCode===27||o.keyCode===40||o.keyCode===38){e.hide()}});b(document).keydown(function(p){if(!e.onScreen){return}var o=0;if(p.keyCode===37){o=-1}if(p.keyCode===39){o=1}if(!o){return}g.gotoIndex(o)})};e.show=function(){if(e.onScreen){return}if(WPW.currentBALightbox){return}WPW.currentBALightbox=this;e.preset();g.placeHolder=g.placeHolder||b("");if(!g.onlyLightbox){g.galleryNode.before(g.placeHolder)}b("body").append(e.node);e.node.slideUp(0);e.node.slideDown({duration:400,complete:function(){e.onScreen=1;e.node.append(g.galleryNode);g.galleryNode.addClass("wpw-ba-zoom-mode");g.galleryNode.removeClass("wpw-ba-viewer-block");g.zoomMode=1;g.galleryNode.fadeOut(0);g.galleryNode.fadeIn(500,function(){});g.setSize()},easing:"easeInOutQuart"})};e.hide=function(){if(!e.onScreen){return}g.galleryNode.fadeOut(500,function(){WPW.currentBALightbox=0;g.zoomMode=0;e.onScreen=0;g.galleryNode.detach();g.galleryNode.removeClass("wpw-ba-zoom-mode");g.galleryNode.addClass("wpw-ba-viewer-block");if(!g.onlyLightbox){g.placeHolder.after(g.galleryNode)}g.galleryNode.fadeIn(1);setTimeout(function(){g.animateHeight(1);g.setSize()},100);g.setSize();e.node.slideUp({duration:400,easing:"easeInOutQuart",complete:function(){e.node.detach()}})})};e.toggle=function(o){if(e.onScreen){e.hide()}else{if(o){g.gotoIndex()}e.show()}}};g.updateTitle=function(p,o,e){if(!p){p=""}if(!g.info){return}g.textNode=g.textNode||b(".wpw-ba-info-text",g.galleryNode);if(!p.length){g.info.addClass("wpw-ba-info-hide")}else{g.info.removeClass("wpw-ba-info-hide");if(o){if(!e){e="_self"}p=" » "+p+""}g.textNode.html(p)}};var l=0;g.animateHeight=function(o){l=0;if(g.lightbox.onScreen){return}var e=0;if(!g.mainPic.loaded||!g.mainPic.isLoaded()){e=g.galleryNode.height()}else{e=g.mainPic.pic.height()}if(l===e){return false}l=e;g.aHeight=g.startHeight;var p=300;if(o){p=1}g.galleryNode.stop().animate({height:e},{duration:p,step:function(){},easing:f,complete:function(){}})};var j=function(q,o){var s=this;s.picA={};s.picB={};s.loaded=0;s.percent=1;var r=0;var p=1;s.update=function(){var t=parseInt(s.percent*g.galleryWidth,10);if(s.door){s.door.css("left",t);s.picBox.css("left",-t-1)}};s.introAnimTimer=0;s.introAnim=function(){WPW.baViewersCount+=1;p=0;var t="easeInOutExpo";if(g.cfg.disableIntro===true){b(s).delay(200*WPW.baViewersCount).animate({percent:g.cfg.startPercent},{duration:g.cfg.animSpeed,step:function(){s.update()},easing:t,complete:function(){s.update();WPW.baViewersCount-=1;if(WPW.baViewersCount<0){WPW.baViewersCount=0}}})}else{b(s).delay(300+300*WPW.baViewersCount).animate({percent:0},{duration:g.cfg.animSpeed,step:function(){s.update()},easing:t,complete:function(){s.update()}}).animate({percent:1},{duration:g.cfg.animSpeed,step:function(){s.update()},easing:t,complete:function(){s.update()}}).animate({percent:g.cfg.startPercent},{duration:g.cfg.animSpeed,step:function(){s.update()},easing:t,complete:function(){s.update();WPW.baViewersCount-=1;if(WPW.baViewersCount<0){WPW.baViewersCount=0}}})}g.cfg.disableIntro=true};s.resize=function(){if(!s.onScreen){return}s.update();if(s.picA.pic&&s.picA.isLoaded()){s.picA.resize()}if(s.picB.pic&&s.picB.isLoaded()){s.picB.resize()}};s.showA=function(){if(s.picA.isLoaded()&&!s.picA.onScreen){s.picA.onScreen=1;g.galleryNode.removeClass("wpw-ba-loading");s.node.append(s.picA.pic);s.picA.pic.fadeOut(0);s.picA.pic.fadeIn(300);s.picA.pic.addClass("wpw-ba-pic-a");s.picA.pic.addClass("wpw-ba-pic");if(s.onScreen){g.mainPic=s.picA}g.animateHeight()}};s.showB=function(){if(s.picB.isLoaded()&&!s.picB.onScreen){s.picB.onScreen=1;if(s.picB.none){return}s.door=b("");s.mask=b("");s.picBox=b("");s.wall=b("");s.constroller=b('');s.node.append(s.door);s.door.append(s.mask);s.door.append(s.constroller);s.mask.append(s.picBox);s.picBox.append(s.picB.pic);s.picB.pic.addClass("wpw-ba-pic-b");s.picB.pic.addClass("wpw-ba-pic");s.node.append(s.wall);r=new WPW.DragStuff({theTrigger:s.wall,toDrag:s.door,toDragWidth:function(){return 1},dragWidthLimit:function(){return g.galleryWidth},toDragHeight:function(){return 0},dragHeightLimit:function(){return 0},onStart:function(){b(s).stop();s.update();clearTimeout(s.introAnimTimer)},onStop:function(){if(!r.inertiaAnim){g.galleryNode.removeClass("user-dragging")}},inertiaStop:function(){if(!r.inertiaAnim){g.galleryNode.removeClass("user-dragging")}},onDrag:function(){if(r.hasDrag()){if(!g.galleryNode.hasClass("user-dragging")){g.galleryNode.addClass("user-dragging")}}s.percent=r.percent;s.update()},innerDrag:true,hasInertia:true});s.wall.click(function(t){b(s).stop();if(r.wasDragged){return false}t.preventDefault();t.stopImmediatePropagation();t.stopPropagation();s.gotoPercent(t)});s.introAnimTimer=setTimeout(function(){s.introAnim()},500)}s.update()};s.gotoPercent=function(u){if(!u){return false}var w;if(!u.pageX){w=s.wall.data("dragEndX")-s.node.offset().left}else{w=u.pageX-s.node.offset().left}if(!w){return}var t=w/g.galleryWidth;var v="easeInOutExpo";b(s).stop().delay(200).animate({percent:t},{duration:600,step:function(){s.update()},easing:v,complete:function(){s.percent=t;s.update()}});return false};s.loadPics=function(){if(!s.picA.pic){s.picA.pic=1;s.picA=new e(q.attr("data-src")||q.attr("src"));return false}if(s.picB.pic&&!s.picA.isLoaded()){return}if(!s.picB.pic&&!s.picB.none){s.picB.pic=1;s.picB=new e(q.attr("data-second")||q.attr("data-pic")||q.attr("data-alt")||q.attr("alt"));return false}s.showA();s.showB();if(s.picA.isLoaded()&&s.picB.isLoaded()){if(s.preloader){s.preloader.fadeOut(800,function(){s.preloader.remove();s.preloader=0})}}s.resize();return false};s.preset=function(){if(s.isPreset){return false}s.isPreset=1;s.node=b('');s.preloader=b('');s.node.append(s.preloader);g.mover.append(s.node);if(o){s.node.css("position","absolute");s.node.css("left",(o*100)+"%");s.node.css("top",0)}return false};s.show=function(){if(s.onScreen){return false}s.onScreen=1;g.mainPic=s.picA;s.preset();s.node.addClass("ba-selected-box");s.node.removeClass("ba-unselected-box");setTimeout(function(){s.loadPics();g.animateHeight()},100);g.updateTitle(q.attr("data-info")||q.attr("title"),q.attr("data-url"),q.attr("data-url-target"))};s.hide=function(){if(!s.onScreen){return false}s.node.addClass("ba-unselected-box");s.node.removeClass("ba-selected-box");s.onScreen=0};var e=function(t){var u=this;u.pic=b(new Image());u.isLoaded=function(){return(u.loaded||u.none)};if(!t&&!u.none){u.loaded=true;u.none=true;setTimeout(function(){s.loadPics()},100)}u.pic.load(function(){u.loaded=1;s.loadPics()}).error(function(){u.loaded=1;alert("ERROR: Image not found at path: "+t);s.loadPics()}).attr("src",t);u.resize=function(){if(!u.loaded){return false}var v=10;u.pic.css("width","");u.pic.css("height","");u.pic.css("top","");u.pic.css("left","");if(g.lightbox.onScreen){if(u.pic.width()>WPW.cW-v){u.pic.css("width",WPW.cW-v);u.pic.css("height","auto")}if(u.pic.height()>WPW.cH-v){u.pic.css("height",WPW.cH-v);u.pic.css("width","auto")}u.pic.css("left",parseInt(WPW.cW/2-u.pic.width()/2,10));u.pic.css("top",parseInt(WPW.cH/2-u.pic.height()/2,10))}}};g.items.push(s)};g.oldIndex="none";g.gotoIndex=function(o){if(!o){o=0}g.currentIndex+=o;if(g.currentIndex>=g.nrItems){g.currentIndex=0}if(g.currentIndex<0){g.currentIndex=g.nrItems-1}if(g.oldIndex===g.currentIndex){return false}g.startHeight=g.galleryNode.height();if(g.items[g.currentIndex]){g.items[g.currentIndex].show()}if(g.items[g.oldIndex]){g.items[g.oldIndex].hide()}b(g).stop().animate({containerPosition:-g.currentIndex*100},{duration:600,easing:f,step:function(){g.mover.css("left",g.containerPosition+"%")},complete:function(){g.mover.css("left",g.containerPosition+"%");g.galleryNode.trigger("ItemChanged")}});g.galleryNode.trigger("ItemChange");try{}catch(p){}g.oldIndex=g.currentIndex;return false};g.imageNodes.each(function(e){var o=new j(b(this),e)});var c=0;g.setSize=function(){clearTimeout(c);if(g.onlyLightbox&&!g.lightbox.onScreen){return}if(g.galleryNode.width()<200){c=setTimeout(function(){g.setSize()},500);return false}g.galleryNode.css("max-width","");g.galleryNode.css("max-height","");if(g.lightbox.onScreen){g.galleryNode.css("width","100%");g.galleryNode.css("height","100%");g.galleryWidth=WPW.cW;g.galleryHeight=WPW.cH}else{g.galleryNode.css("width","");g.galleryNode.css("height","");if(g.cfg.width){g.galleryNode.css("width",g.cfg.width)}if(g.cfg.maxWidth){g.galleryNode.css("max-width",g.cfg.maxWidth)}if(g.cfg.maxHeight){g.galleryNode.css("max-height",g.cfg.maxHeight)}if(g.cfg.height){g.galleryNode.css("height",g.cfg.height)}g.galleryWidth=g.galleryNode.width();g.galleryHeight=g.galleryNode.height()}var e=0;for(e=0;e1){g.footer=b("");if(!g.cfg.hideTitles){g.info=b("")}g.galleryNode.append(g.footer);g.footer.append(g.info);g.btnNext=b("");g.btnPrev=b("");g.footer.append(g.btnNext);g.footer.append(g.btnPrev);g.btnNext.click(function(o){o.preventDefault();g.gotoIndex(1);return false});g.btnPrev.click(function(o){o.preventDefault();g.gotoIndex(-1);return false})}b("body").bind("WindowResized",g.setSize);g.galleryNode.append(g.mover);g.gotoIndex();g.setSize();return false};if(g.galleryNode.attr("data-lightbox")){g.btnZoom=b('');g.galleryNode.append(g.btnZoom);g.btnZoom.click(function(){g.lightbox.toggle()});if(g.galleryNode.attr("data-lightbox")==="default+lightbox"||g.galleryNode.attr("data-lightbox")==="simple+lightbox"){}else{var i=g.galleryNode.attr("data-lightbox");g.onlyLightbox=1;var d=b(".lightbox-button",g.galleryNode);if(!d.length){try{d=b(i,g.galleryNode)}catch(h){d=""}}else{g.galleryNode.before(d)}if(!d.length){try{d=b(i)}catch(h){d=""}}else{}if(!d.length){g.btnZoom=b('');d=g.btnZoom.html(i);g.galleryNode.before(g.btnZoom)}else{g.btnZoom=d}g.placeHolder=g.btnZoom;g.galleryNode.detach()}g.btnZoom.unbind();g.btnZoom.each(function(){var e=b(this);e.click(function(){var o=e.attr("href")||e.attr("data-index");g.preset();if(o){var o=parseInt(o.replace("#",""),10)-1;g.currentIndex=o;g.lightbox.toggle(1)}else{g.lightbox.toggle()}return false})})}if(!g.onlyLightbox){g.preset()}};b.fn.wpwBAgallery=function(c){return this.each(function(){var e=b(this);if(e.data("wpwbagallery")){return}var d=new a(this,c);e.data("wpwbagallery",d)})};b.fn.wpwBAgallery.defaults={width:"auto",height:"auto",animSpeed:900,maxWidth:0,maxHeight:0,hideTitles:false,startPercent:0.5,disableIntro:false,lightbox:0,theme:"ba-default"};b.fn._reverse=[].reverse;b(document).ready(function(c){jQuery(".wpw-auto-init-ba").wpwBAgallery();WPW.ResizeEngine()})})(jQuery);WPW.localResizeEngine=function(){var a=this;var b=jQuery;a.resizeTimer=0;if(WPW.ResizeEngineStarter){return}WPW.ResizeEngineStarter=true;a.resizeEvent=function(){clearInterval(a.resizeTimer);a.resizeTimer=setInterval(function(){if(!WPW.body){if(b("body").length){WPW.body=b("body")}}WPW.cW=b(window).width();WPW.cH=b(window).height();WPW.body.trigger("WindowResized");clearInterval(a.resizeTimer)},100)};a.resizeEvent();b(window).resize(function(){a.resizeEvent()})};WPW.ResizeEngine=WPW.ResizeEngine||WPW.localResizeEngine;var WPWmodule={id:"DragStuff",version:1.3,func:function(i){if(i.theTrigger.data("DragStuff")){i.theTrigger.data("DragStuff").reset();return i.theTrigger.data("DragStuff")}var g=jQuery;var j=this;j.inertiaX=0;j.inertiaY=0;var a=0;var q=30;var c=0;var b=0;var n=0;var l=0;var h=0;var f=0;WPW.body=WPW.body||g("body");function k(){if("msMaxTouchPoints" in window.navigator&&window.navigator.msMaxTouchPoints===0){return false}return !!(window.navigator.msMaxTouchPoints)||!!("ontouchstart" in window)||!!("onmsgesturechange" in window)}var s=0;var e=0;var m=false;j.percent=0;j.iX=0;j.iY=0;j.inertiaCalcTimer=0;j.calculateInertia=function(){if(Math.abs(j.inertiaX)>Math.abs(j.iX)){j.iX=j.inertiaX*2}else{j.iX=j.iX*0.6}if(Math.abs(j.inertiaY)>Math.abs(j.iY)){j.iY=j.inertiaY*2}else{j.iY=j.iY*0.6}};var t=function(){i.theTrigger.bind("touchstart",function(w){var v=w.originalEvent.touches[0]||w.originalEvent.changedTouches[0];n=v.pageX;l=v.pageY;m=true;c=i.toDrag.position().left;b=i.toDrag.position().top;r()});WPW.body.bind("touchmove",function(v){if(!i.toDrag.data("dragging")){return}var w=v.originalEvent.touches[0]||v.originalEvent.changedTouches[0];h=-n+w.pageX;f=-l+w.pageY;j.inertiaX=h;j.inertiaY=f;n=w.pageX;l=w.pageY;c=c+h;b=b+f;s+=Math.abs(h);e+=Math.abs(f);d();if(s-e>20){v.preventDefault();return false}});var u=function(v){if(!i.toDrag.data("dragging")){return}o(v)};WPW.body.bind("touchend",function(v){u(v)});WPW.body.bind("touchcancel",function(v){u(v)});i.theTrigger.bind("touchend",function(v){u(v)});i.theTrigger.bind("touchcancel",function(v){u(v)})};j.mouseUp=function(u){i.theTrigger.unbind("mouseup",j.mouseUp);i.theTrigger.unbind("mousemove",j.mouseMove);WPW.body.unbind("mouseup",j.mouseUp);WPW.body.unbind("mousemove",j.mouseMove);o();return false};j.mouseMove=function(u){h=-n+u.pageX;f=-l+u.pageY;j.inertiaX=h;j.inertiaY=f;n=u.pageX;l=u.pageY;c=c+h;b=b+f;s+=Math.abs(h);e+=Math.abs(f);d();if(!k()){return false}};j.mouseDown=function(u){n=u.pageX;l=u.pageY;m=true;r();c=i.toDrag.position().left;b=i.toDrag.position().top;WPW.body.mousemove(j.mouseMove);g("html, body").mouseup(j.mouseUp);i.theTrigger.mouseup(j.mouseUp);return false};if(!k()){i.theTrigger.mousedown(j.mouseDown)}var p=function(){if(i.toDrag.hasClass("fixed-mover")){return}if(i.toDragWidth()>i.dragWidthLimit()||i.innerDrag){if(i.dragWidthLimit()){i.toDrag.css("left",c)}}if(i.dragHeightLimit()){i.toDrag.css("top",b)}j.percent=c/(i.dragWidthLimit()-i.toDragWidth());if(i.onDrag){i.onDrag()}};j.manualRefresh=function(){c=i.toDrag.position().left;b=i.toDrag.position().top;d()};var d=function(){var u={};if(i.innerDrag){if(c<0){c=0;u.maxLeft=true}if(b<0){b=0;u.maxTop=true}if(c>i.dragWidthLimit()-i.toDragWidth()){u.maxRight=true;c=i.dragWidthLimit()-i.toDragWidth()}if(b>i.dragHeightLimit()-i.toDragHeight()){b=i.dragHeightLimit()-i.toDragHeight();u.maxBottom=true}}else{if(c0){c=0;u.maxRight=true}if(b>0){b=0;u.maxTop=true}}j.calculateInertia();p();return u};var r=function(){i.toDrag.data("dragging",true);if(i.onStart){i.onStart()}j.wasDragged=false;j.onDrag=1;s=0;e=0;WPW.dragContainerMoved=false;j.iX=0;j.iY=0;j.inertiaX=0;j.inertiaY=0;clearTimeout(a);clearInterval(j.inertiaCalcTimer);j.inertiaCalcTimer=setInterval(j.calculateInertia,300);i.theTrigger.trigger("wpwDragStart")};j.hasDrag=function(){if(s>10||e>10){j.wasDragged=true}return j.wasDragged};var o=function(w){i.toDrag.data("dragging",false);j.hasDrag();if(k()){var x=w.originalEvent.touches[0]||w.originalEvent.changedTouches[0];var v=x.pageX;var u=x.pageY;i.theTrigger.data("dragEndX",v);i.theTrigger.data("dragEndY",u)}setTimeout(function(){j.wasDragged=false},100);s=0;e=0;i.theTrigger.trigger("wpwDragEnd");j.inertiaX=j.iX;j.inertiaY=j.iY;if(i.hasInertia){j.doInertia()}if(i.onStop){i.onStop()}j.onDrag=0;clearInterval(j.inertiaCalcTimer)};j.inertiaStep=function(){j.inertiaX=WPW.smoothMove(j.inertiaX,0,15);c+=j.inertiaX;var u=d();if(u.maxLeft||u.maxRight){j.inertiaX=j.inertiaX*-1*0.5}clearTimeout(a);if(Math.abs(j.inertiaX)<1){j.inertiaX=0;j.inertiaAnim=0;if(i.inertiaStop){i.inertiaStop()}}else{a=setTimeout(function(){clearTimeout(a);j.inertiaStep()},q)}};j.doInertia=function(){if(Math.abs(j.inertiaX)>2){a=setTimeout(function(){j.inertiaStep()},q);j.inertiaAnim=1}else{j.inertiaAnim=0;if(i.inertiaStop){i.inertiaStop()}}};j.reset=function(){i.theTrigger.bind("RefreshDragger",function(){j.manualRefresh()});j.inertiaX=0;j.inertiaY=0;if(k()){t()}};j.reset();i.theTrigger.data("DragStuff",this);return this}};if(!WPW[WPWmodule.id+"V"]||WPW[WPWmodule.id+"V"]