(function(a,c,f){var l="next-click.b2bphotogallery",k="next-click.",j="prev-click.b2bphotogallery",i="prev-click.",d=".b2b-photogallery",b="click",h="b2b-photogallery-item",e="b2b",g={dimensions:{width:960,height:670,minWidth:300,minHeight:225,maxImageW:852,maxImageH:568,overlayWidth:330,verticalExtra:1,fromCss:0},ui:{trigger:["b2b-photogallery-fullscreen-button","b2b-photogallery-image"],closeButton:"b2b-photogallery-fullscreen-close-button",closeBg:"b2b-photogallery-fullscreen-close-bg",closeButtonImage:"/wp-content/themes/tsm-theme-1/img/b2b-close-button.png",wrapper:"b2b-photogallery-fullscreen-wrapper",fullscreenImageWrapper:"b2b-photogallery-image-fullscreen",fullscreenImage:"b2b-photogallery-image-fullscreen-image",galleryItem:h},dl:{dimensions:{fromCss:1},autoScroll:{enabled:0},ui:{nav:{next:{className:"b2b-photogallery-nav-prev",actions:[{event:b,callback:function(b){b.stopPropagation();a(b.target).parents(d).trigger(i+e);a(b.target).parents(d).trigger(j)}}]},prev:{className:"b2b-photogallery-nav-next",actions:[{event:b,callback:function(b){b.stopPropagation();a(b.target).parents(d).trigger(k+e);a(b.target).parents(d).trigger(l)}}]},selector:{className:"b2b-photogallery-nav-item-selector",actions:[{event:b,callback:function(b){b.stopPropagation();a(b.target).parents(d).trigger("selector-click."+e,b)}}]}},navContainer:"b2b-photogallery-nav",item:h,items:"b2b-photogallery-items",overlayItems:"b2b-photogallery-overlays-item",overlayItemsContainer:"b2b-photogallery-overlays-items",overlayWrapper:"b2b-photogallery-overlays",captionToggle:"b2b-photogallery-caption-toggle",urlContainer:"b2b-photogallery-url"}},launchFullScreen:0};a.b2bphotogallery=function(L){var B="openFullscreen.b2b",K="width",J="left",T="currItem",S="dimensions",R="defaultDimensions",p=".",Q='<div class="';if(!L.elem)a.extend(true,g,L);else{var h=a.extend(true,{},g,L),d=a(h.elem),X=a(c),Y=a(f),x=a('<img class="'+h.ui.closeButton+' nav-button" src="'+h.ui.closeButtonImage+'" />'),N=a(Q+h.ui.closeBg+'"></div>'),F=a(Q+h.ui.wrapper+'" />'),hb=h.ui.trigger.join(",."),ib=d.find(p+hb),U="javascript:void(0);",P=d.find(p+h.dl.ui.captionToggle)||0,C=d.find(p+h.dl.ui.items),u=d.find(p+h.dl.ui.overlayItems),jb=d.data(R),w=d.find(p+h.ui.fullscreenImageWrapper),n=w.find("span"),kb=d.find(p+h.ui.fullscreenImage),r=d.find(p+h.dl.ui.item),s=h.dimensions.width,y=h.dimensions.height,cb=h.dimensions.minWidth,bb=h.dimensions.minHeight,E=h.dimensions.maxImageW,D=h.dimensions.maxImageH,O=u.height(),gb=h.dimensions.verticalExtra,eb=s-E,m,q,o,v,t,G,I,H,db,Z,M=function(){var b=0,a=0;if(c.body&&c.body.offsetWidth){b=c.body.offsetWidth;a=c.body.offsetHeight}if(c.compatMode==="CSS1Compat"&&c.documentElement&&c.documentElement.offsetWidth){b=c.documentElement.offsetWidth;a=c.documentElement.offsetHeight}if(f.innerWidth&&f.innerHeight){b=f.innerWidth;a=f.innerHeight}return{w:b,h:a}},V=function(c){var b="href";t=c.find(p+h.ui.fullscreenImageWrapper);G=t.attr(b);o=t.find("span img").get(0);o.onload=function(){v=a(o);v.data(S,{w:o.width,h:o.height}).addClass("loaded");db=o.width/E*100+"%";Z=o.height/D*100+"%";if(o.width>o.height)v.css({width:db});else v.css({height:Z});v.css({"margin-top":(t.find("span").height()-v.height())/2});t.attr(b,U);A()};if(t.length&&typeof G!=="undefined"&&G!==false&&G!==U)o.src=t.attr(b)},A=function(){m=M();fb();d.css({left:(m.w-d.width())/2+"px",top:(m.h-d.height()-O)/2<1?"0px":(m.h-d.height()-O)/2+"px"})},fb=function(){var c="auto";m=M();q=d.data(T)||a(r.get(0));var i=parseInt(C.css(J),10)/parseInt(d.css(K),10),b=q.find(p+h.ui.fullscreenImage+".loaded"),e=b.data(S)||{w:E,h:D},g,f;if(m.w<s&&m.w>cb||m.h<y&&m.h>bb){if(m.w<s&&m.w>cb){d.width(m.w);r.width(m.w);u.width(m.w);n.width(m.w-eb);w.width(m.w)}if(m.h<y&&m.h>bb){d.height(m.h);r.height(m.h);n.outerHeight(m.h-O);w.height(m.h+gb)}g=Math.min(e.w,b.width());f=Math.min(e.h,b.height());d.trigger(B,{currItem:q,moveIndex:i})}else{if(m.w>=s){d.width(s);r.width(s);u.width(s);w.width(s);n.width(E);d.trigger(B,{currItem:q,moveIndex:i})}if(m.h>=y){d.height(y);r.height(y);w.height(D);n.height(D);d.trigger(B,{currItem:q,moveIndex:i})}}if(n.height()<n.width()){b.css({height:n.height(),width:c});g=Math.min(e.w,b.width());g>n.width()&&b.css({width:n.width(),height:c})}if(n.width()<n.height()){b.css({width:n.width(),height:c});f=Math.min(e.h,b.height());f>n.height()&&b.css({height:n.height(),width:c})}b.css({"margin-top":(n.height()-b.height())/2})},z=function(){var a=-1;if(navigator.appName=="Microsoft Internet Explorer"){var c=navigator.userAgent,b=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");if(b.exec(c)!=null)a=parseFloat(RegExp.$1)}return a},W=function(a){switch(a.keyCode){case 39:d.trigger(k+e);break;case 37:d.trigger(i+e);break;case 27:x.click()}},ab=function(){var c="keydown",f="itemChanged.b2b",e="itemChange.b2b";m=M();I=parseInt(d.css(K),10);d.bind(e,function(b,a){V(a.currItem)});q=d.data(T)||a(r.get(0));d.wrap(F);F=d.parent();F.append(x).append(N).css({opacity:0});H=parseInt(C.css(J),10);x.bind(b,function(){if(!C.is(":animated")){var a=d.data(R);I=parseInt(d.css(K),10);H=parseInt(C.css(J),10);x.unbind(b).remove();N.unbind(b).remove();d.unbind(e).unbind(l).unbind(j).unbind(f);d.css({top:"0px",left:"0px"}).unwrap();Y.unbind("resize").unbind(c);(z()===8||z()===7)&&X.unbind(c);r.width(a.width).height(a.height);u.width(a.width);d.width(a.width).height(a.height).trigger("closeFullscreen.b2b",{currItem:q,moveIndex:H/I})}});N.bind(b,function(){x.trigger(b)});r.width(h.dimensions.width);u.width(h.dimensions.width);d.width(h.dimensions.width);d.trigger(B,{currItem:q,moveIndex:H/I});A();V(q);F.animate({opacity:1},{duration:200,queue:false,easing:"easeOutCubic"});Y.bind("resize",A).bind(c,W);(z()===8||z()===7)&&X.bind(c,W);d.bind(f,function(){A()})};P&&P.bind(b,function(){d.trigger("toggleCaption.b2b",{currOverlayItem:u.filter(".selected")})});d.b2bdl(h.dl);if(h.launchFullScreen)ab();else ib.bind(b,ab)}};a.fn.b2bphotogallery=function(b){return this.each(function(){b=b||{};b.elem=this;a.b2bphotogallery(b)})};!a.easing.easeInCubic&&a.extend(a.easing,{easeInCubic:function(e,a,b,c,d){return c*(a/=d)*a*a+b}});!a.easing.easeOutCubic&&a.extend(a.easing,{easeOutCubic:function(e,a,b,c,d){return c*((a=a/d-1)*a*a+1)+b}})})(jQuery,document,window);
