(function(a){var b=function(c,b){var a=this;this.file=c;this.callback=b;this.loaded=false;this.aborted=false;this.error=false;this.image=new Image;this.cancelEvent=function(){if(this.image&&this.image.onload)this.image.onload=null;if(this.image&&this.image.onabort)this.image.onabort=null;if(this.image&&this.image.onerror)this.image.onerror=null};this.on_load=function(){a.loaded=true;a.callback&&typeof a.callback=="function"&&a.callback.apply(a,["loaded"]);a.cancelEvent()};this.on_error=function(){a.error=true;a.callback&&typeof a.callback=="function"&&a.callback.apply(a,["error"]);a.cancelEvent()};this.on_abort=function(){a.aborted=true;a.callback&&typeof a.callback=="function"&&a.callback.apply(a,["aborted"]);a.cancelEvent()};this.image.src=this.file;this.autoCheckIntervalId=0;this.autoCheck=function(){if(a.loaded||a.aborted||a.error){window.clearInterval(a.autoCheckIntervalId);return}if(a.image&&a.image.complete){window.clearInterval(a.autoCheckIntervalId);a.loaded=true;a.callback&&typeof a.callback=="function"&&a.callback.apply(a,["loaded"]);a.cancelEvent();return}if(a.image&&(a.image.width||a.image.height)){window.clearInterval(a.autoCheckIntervalId);a.loaded=true;a.callback&&typeof a.callback=="function"&&a.callback.apply(a,["loaded"]);a.cancelEvent();return}};this.autoCheckIntervalId=window.setInterval(a.autoCheck,500)};a.preloadImages=function(d,f){if(typeof d=="string")return new a.preloadImage(d,f);var c=this;this.images=d;this.callback=f;this.all_complete=false;this.preloader=[];this.checkComplete=function(){if(c.preloader.length<c.images.length)return;if(this.all_complete)return;for(var b=true,d=0,a=0,e=c.preloader.length;a<e;a++)if(c.preloader[a]&&c.preloader[a].loaded)d++;else b=false;if(b){this.all_complete=true;c.callback&&typeof c.callback=="function"&&c.callback.apply(c)}};for(var e=0,g=d.length;e<g;e++)this.preloader[e]=new b(this.images[e],function(){c.checkComplete()});this.autoCheckIntervalId=0;this.autoCheck=function(){this.all_complete&&window.clearInterval(c.autoCheckIntervalId);c.checkComplete()};this.autoCheckIntervalId=window.setInterval(c.autoCheck,500)};var c=0;a.fn.gallery=function(b){var c=typeof b=="string"||false,d=arguments;if(!c)var b=a.extend({},b,{});a(this).each(function(){var e=a(this).data("gallery");if(c&&e){e[b]&&typeof e[b]=="function"&&e[b].apply(e,a.makeArray(d).slice(1));return}else{e=new a.gallery(this,b);a(this).data("gallery",e)}});return this};a.gallery=function(c,b){this.elem=c;this.options=a.extend({},b,a.gallery.defaults);this.init()};a.extend(a.gallery,{defaults:{loadingImage:"/images/ajax-loader.gif",selectedClass:"selected",slideLoader:function(c){if(c.loaded||c.loading)return;c.loading=true;new b(c.href,function(){a(".loading",c.elem).fadeOut(800,function(){a(this).remove()});c.elem.append(a("<img />").attr("src",c.href).fadeIn(1e3));c.loaded=true})}},prototype:{init:function(){var c=a("img",this.elem).map(function(){return this.src}),b=this;new a.preloadImages(c,function(){b.alignItems.call(b)});this.initCarousel()},alignItems:function(){for(var d=a(".gallery_items",this.elem),c=a(".gallery_item",d),l=d.innerWidth(),j=a(c[0]).outerWidth(true),d=Math.floor(l/j),k=Math.ceil(c.length/d),b=0,i=0,e=0,h=0,i=0;i<k;i++){var f=0,g=0;for(b=0;b<d;b++)if(f<a(c[e+b]).outerHeight())f=a(c[e+b]).outerHeight();for(b=0;b<d;b++){g=parseInt(a(c[e+b]).css("paddingTop"))||0;g+=parseInt(a(c[e+b]).css("paddingBottom"))||0;a(c[e+b]).css({height:f-g+"px"});a(">a",c[e+b]).css({height:f-g+"px"})}h+=f;e+=d}a(a(".gallery_items",this.elem).parents(".wrapper")[0]).css({height:h-4+"px",width:d*j-4+"px"});a(this.elem).after("<div style='clear:both;height:0;line-height:0;font-size:0;overflow:hidden'></div>")},moveCarousel:function(a,c){if(this.currentIndex==a)return;var b;b=this.carouselSlideWidth*a*-1;if(c){this.carouselSlides.stop();this.carouselSlides.animate({left:b+"px"},{queue:false,easing:"easeInOutExpo"})}else this.carouselSlides.css({left:b+"px"});this.currentIndex=a;this.updateCarouselTitle();!this.carouselItems[this.currentIndex].loaded&&!this.carouselItems[this.currentIndex].loading&&this.options.slideLoader.apply(this,[this.carouselItems[this.currentIndex]]);this.initCarouselState()},updateCarouselTitle:function(){var a;a=this.carouselItems[this.currentIndex].title||"";this.carouselSlideTitle.html(a)},showCarousel:function(g){var b=this,c,h,d=this.getPageSize(),f=this.getPageScroll();if(this.carouselHeight>d.windowHeight)c=0;else c=(d.windowHeight-this.carouselHeight)/2;c+=f.yScroll;this.carouselOverlay.stop();this.carouselOverlay.css({width:d.largestWidth+"px",height:d.largestHeight+"px",opacity:0,display:"block"}).animate({opacity:.75},{queue:false,duration:300,complete:function(){b.carousel.css({top:c+"px",opacity:"",display:"block"})}});this.moveCarousel(g,false);var e=0;a(window).bind("scroll.galleryCarousel",function(){e>0&&window.clearTimeout(e);e=window.setTimeout(function(){var a=b.getPageSize(),d=b.getPageScroll();if(b.carouselHeight>a.windowHeight)c=0;else c=(a.windowHeight-b.carouselHeight)/2;c+=d.yScroll;b.carousel.stop();b.carousel.animate({top:c+"px"},{queue:false,duration:800,easing:"easeOutExpo"})},100)});a(this.carouselOverlay).bind("click.galleryCarousel",function(){b.hideCarousel.apply(b,[])});a(this.carousel).bind("click.galleryCarousel",function(c){c.target==a(b.carousel)[0]&&b.hideCarousel.apply(b,[])})},hideCarousel:function(){var b=this;a(this.carouselOverlay).unbind("click.galleryCarousel");a(this.carousel).unbind("click.galleryCarousel");a(window).unbind("scroll.galleryCarousel");b.carousel.css({display:"none",opacity:""});this.carouselOverlay.stop();this.carouselOverlay.animate({opacity:0},{queue:false,duration:300,complete:function(){a(this).css({display:"none",opacity:""})}})},initCarouselState:function(){if(this.currentIndex<=0)this.carouselArrow.prev.addClass("galleryCarouselArrow_prev_disabled");else this.carouselArrow.prev.removeClass("galleryCarouselArrow_prev_disabled");if(this.currentIndex>=this.carouselItems.length-1)this.carouselArrow.next.addClass("galleryCarouselArrow_next_disabled");else this.carouselArrow.next.removeClass("galleryCarouselArrow_next_disabled")},initCarousel:function(){var b=this;this.carouselItems=[];a(".gallery_item>a",this.elem).each(function(){b.carouselItems.push({ref:this,title:a(this).attr("title")||"",href:this.href})});this.carouselID=++c;this.carousel=a("<div />").addClass("galleryCarousel").attr("id","galleryCarousel_"+this.carouselID);this.carousel.appendTo("body");this.carouselContainer=a("<div />").addClass("galleryCarouselContainer");this.carouselContainer.appendTo(this.carousel);if(a.browser.msie&&a.browser.version<7&&a.fn.pngfix);this.carouselWrapper=a("<div />").addClass("galleryCarouselWrapper");this.carouselWrapper.appendTo(this.carouselContainer);this.carouselArrow={next:a("<a />").addClass("galleryCarouselArrow_next"),prev:a("<a />").addClass("galleryCarouselArrow_prev")};this.carouselArrow.next.appendTo(this.carouselContainer);this.carouselArrow.prev.appendTo(this.carouselContainer);this.carouselOverlay=a(".galleryCarouselOverlay");if(this.carouselOverlay.length<1){this.carouselOverlay=a("<div />").addClass("galleryCarouselOverlay");this.carouselOverlay.appendTo("body")}this.carouselSlidesContainer=a("<div />").addClass("galleryCarouselSlidesContainer");this.carouselSlidesContainer.appendTo(this.carouselWrapper);this.carouselSlides=a("<div />").addClass("galleryCarouselSlides");this.carouselSlides.appendTo(this.carouselSlidesContainer);for(var d=0;d<this.carouselItems.length;d++){a.extend(this.carouselItems[d],{elem:a("<div />").addClass("galleryCarouselSlide"),loaded:false,loading:false});this.carouselItems[d].elem.appendTo(this.carouselSlides);this.carouselItems[d].elem.append(a("<img />").attr("src",this.options.loadingImage).addClass("loading"));a(this.carouselItems[d].ref).bind("click",function(){var c=a(".gallery_item>a",b.elem).index(this);try{b.showCarousel(c)}catch(d){console.debug(b.carouselItems);console.debug(c);console.debug(d)}return false})}this.carouselSlideWidth=a(this.carouselItems[0].elem).outerWidth(true);this.carouselSlides.css({width:this.carouselSlideWidth*this.carouselItems.length+"px"});this.carouselBottom=a("<div />").addClass("galleryCarouselBottom");this.carouselBottom.appendTo(this.carouselWrapper);this.carouselSlideTitle=a("<div />").addClass("galleryCarouselSlideTitle");this.carouselSlideTitle.appendTo(this.carouselBottom);this.carouselClose=a("<a />").addClass("galleryCarouselClose").html("close window");this.carouselClose.appendTo(this.carouselBottom);this.carouselClose.bind("click",function(){b.hideCarousel.apply(b,[]);this.blur();return false});this.currentIndex=-1;this.moveCarousel(0,false);this.carouselArrow.next.bind("click",function(){b.currentIndex<b.carouselItems.length-1&&b.moveCarousel.apply(b,[b.currentIndex+1,true]);this.blur();return false});this.carouselArrow.prev.bind("click",function(){b.currentIndex>0&&b.moveCarousel(b.currentIndex-1,true);this.blur();return false});this.carouselHeight=this.carouselContainer.outerHeight();this.carouselOverlay.hide();this.carousel.hide()},getPageSize:function(){var c,d;if(window.innerHeight&&window.scrollMaxY){c=window.innerWidth+window.scrollMaxX;d=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){c=document.body.scrollWidth;d=document.body.scrollHeight}else{c=document.body.offsetWidth;d=document.body.offsetHeight}var a,b;if(self.innerHeight){if(document.documentElement.clientWidth)a=document.documentElement.clientWidth;else a=self.innerWidth;b=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){a=document.documentElement.clientWidth;b=document.documentElement.clientHeight}else if(document.body){a=document.body.clientWidth;b=document.body.clientHeight}if(d<b)pageHeight=b;else pageHeight=d;if(c<a)pageWidth=c;else pageWidth=a;var f,e,h,g;if(pageWidth>=a){f=pageWidth;h=a}else{f=a;h=pageWidth}if(pageHeight>=b){e=pageHeight;g=b}else{e=b;g=pageHeight}var i={pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:a,windowHeight:b,largestWidth:f,largestHeight:e};return i},getPageScroll:function(){var a,b;if(self.pageYOffset){b=self.pageYOffset;a=self.pageXOffset}else if(document.documentElement&&document.documentElement.scrollTop){b=document.documentElement.scrollTop;a=document.documentElement.scrollLeft}else if(document.body){b=document.body.scrollTop;a=document.body.scrollLeft}var c={xScroll:a,yScroll:b};return c}}})})(jQuery);