(function(B){var A;A=B.fn.galleria=function(E){if(!A.hasCSS()){return false}B.historyInit(A.onPageLoad);var I={insert:".galleria_container",history:true,clickNext:true,onImage:function(L,K,J){},onThumb:function(J){}};var F=B.extend(I,E);for(var H in F){if(H){B.galleria[H]=F[H]}}var D=(B(F.insert).is(F.insert))?B(F.insert):jQuery(document.createElement("div")).insertBefore(this);var C=B(document.createElement("div")).addClass("galleria_wrapper");var G=B(document.createElement("span")).addClass("caption");D.addClass("galleria_container").append(C).append(G);return this.each(function(){B(this).addClass("galleria");B(this).children("li").each(function(P){var L=B(this);var J=B.meta?B.extend({},F,L.data()):F;J.clickNext=B(this).is(":only-child")?false:J.clickNext;var O=B(this).find("a").is("a")?B(this).find("a"):false;var K=B(this).children("img").css("display","none");var Q=O?O.attr("href"):K.attr("src");var N=O?O.attr("title"):K.attr("title");var M=new Image();if(J.history&&(window.location.hash&&window.location.hash.replace(/\#/,"")==Q)){L.siblings(".active").removeClass("active");L.addClass("active")}B(M).load(function(){B(this).attr("alt",K.attr("alt"));var T=O?O.find("img").addClass("thumb noscale").css("display","none"):K.clone(true).addClass("thumb").css("display","none");if(O){O.replaceWith(T)}if(!T.hasClass("noscale")){var R=Math.ceil(K.width()/K.height()*L.height());var S=Math.ceil(K.height()/K.width()*L.width());if(R<S){T.css({height:"auto",width:L.width(),marginTop:-(S-L.height())/2})}else{T.css({width:"auto",height:L.height(),marginLeft:-(R-L.width())/2})}}else{}T.attr("rel",Q);T.attr("title",N);T.click(function(){B.galleria.activate(Q)});T.hover(function(){B(this).addClass("hover")},function(){B(this).removeClass("hover")});L.hover(function(){L.addClass("hover")},function(){L.removeClass("hover")});L.prepend(T);T.css("display","block");J.onThumb(jQuery(T));if(L.hasClass("active")){B.galleria.activate(Q)}K.remove()}).error(function(){L.html('<span class="error" style="color:red">Error loading image: '+Q+"</span>")}).attr("src",Q)})})};A.nextSelector=function(C){return B(C).is(":last-child")?B(C).siblings(":first-child"):B(C).next()};A.previousSelector=function(C){return B(C).is(":first-child")?B(C).siblings(":last-child"):B(C).prev()};A.hasCSS=function(){B("body").append(B(document.createElement("div")).attr("id","css_test").css({width:"1px",height:"1px",display:"none"}));var C=(B("#css_test").width()!=1)?false:true;B("#css_test").remove();return C};A.onPageLoad=function(F){var D=B(".galleria_wrapper");var E=B('.galleria img[@rel="'+F+'"]');if(F){if(B.galleria.history){window.location=window.location.href.replace(/\#.*/,"")+"#"+F}E.parents("li").siblings(".active").removeClass("active");E.parents("li").addClass("active");var C=B(new Image()).attr("src",F).addClass("replaced");D.empty().append(C);D.siblings(".caption").text(E.attr("title"));B.galleria.onImage(C,D.siblings(".caption"),E);if(B.galleria.clickNext){C.css("cursor","pointer").click(function(){B.galleria.next()})}}else{D.siblings().andSelf().empty();B(".galleria li.active").removeClass("active")}B.galleria.current=F};B.extend({galleria:{current:"",onImage:function(){},activate:function(G){if(B.galleria.history){B.historyLoad(G)}else{A.onPageLoad(G);if(B.curr!=null){var D=B('.galleria img[@rel="'+B.galleria.current+'"]').parents("li");var C=B(D).prevAll().length+1;B.curr.innerHTML=C.toString();var E=D.nextAll(":hidden").length;if(E==0){B(B.nextPage).addClass("disabledLink")}else{B(B.nextPage).removeClass("disabledLink")}var F=D.prevAll(":hidden").length;if(F==0){B(B.prevPage).addClass("disabledLink")}else{B(B.prevPage).removeClass("disabledLink")}if((D.prevAll().length==0)&&(D.nextAll().length==0)){B(B.prev).addClass("disabledLink");B(B.next).addClass("disabledLink")}}}},next:function(){var C=B(A.nextSelector(B('.galleria img[@rel="'+B.galleria.current+'"]').parents("li")));if(C.length==0){return }if(C.is(":hidden")){var F=C.nextAll().length;var E=C.prevAll().length;if(F>7){F=7}E=7-F;if(E<0){E=0}C.nextAll().each(function(G){if(G<F){B(this).show();return }B(this).hide();return });C.prevAll().each(function(G){if(G<E){B(this).show();return }B(this).hide();return });B(C).show()}var D=B(C).find("img").attr("rel");B.galleria.activate(D)},nextPage:function(){var C=B(A.nextSelector(B('.galleria img[@rel="'+B.galleria.current+'"]').parents("li")));var E=B(A.nextSelector(B('.galleria img[@rel="'+B.galleria.current+'"]').parents("li")));C.nextAll().each(function(I){if(I<8){E=B(this);return }});var H=E.nextAll().length;var G=E.prevAll().length;if(H>7){H=7}G=7-H;if(G<0){G=0}E.nextAll().each(function(I){if(I<H){B(this).show();return }B(this).hide();return });E.prevAll().each(function(I){if(I<G){B(this).show();return }B(this).hide();return });B(E).show();var D=E.nextAll(":hidden").length;if(D==0){B(B.nextPage).addClass("disabledLink")}else{B(B.nextPage).removeClass("disabledLink")}var F=E.prevAll(":hidden").length;if(F==0){B(B.prevPage).addClass("disabledLink")}else{B(B.prevPage).removeClass("disabledLink")}},prev:function(){var E=B(A.previousSelector(B('.galleria img[@rel="'+B.galleria.current+'"]').parents("li")));if(E.length==0){return }if(E.is(":hidden")){var D=E.prevAll().length;var F=E.nextAll().length;if(D>7){D=7}F=7-D;if(F<0){F=0}E.prevAll().each(function(G){if(G<D){B(this).show();return }B(this).hide();return });E.nextAll().each(function(G){if(G<F){B(this).show();return }B(this).hide();return });B(E).show()}var C=B(E).find("img").attr("rel");B.galleria.activate(C)},prevPage:function(){var G=B(A.previousSelector(B('.galleria img[@rel="'+B.galleria.current+'"]').parents("li")));var C=B(A.nextSelector(B('.galleria img[@rel="'+B.galleria.current+'"]').parents("li")));G.prevAll().each(function(I){if(I<8){C=B(this);return }});var F=C.prevAll().length;var H=C.nextAll().length;if(F>7){F=7}H=7-F;if(H<0){H=0}C.prevAll().each(function(I){if(I<F){B(this).show();return }B(this).hide();return });C.nextAll().each(function(I){if(I<H){B(this).show();return }B(this).hide();return });B(C).show();var D=C.prevAll(":hidden").length;if(D==0){B(B.prevPage).addClass("disabledLink")}else{B(B.prevPage).removeClass("disabledLink")}var E=C.nextAll(":hidden").length;if(E==0){B(B.nextPage).addClass("disabledLink")}else{B(B.nextPage).removeClass("disabledLink")}},setCurr:function(C){B.curr=document.getElementById(C)},setPrev:function(C){B.prev=document.getElementById(C)},setNext:function(C){B.next=document.getElementById(C)},setPrevPage:function(C){B.prevPage=document.getElementById(C)},setNextPage:function(C){B.nextPage=document.getElementById(C)}}})})(jQuery);jQuery.extend({historyCurrentHash:undefined,historyCallback:undefined,historyInit:function(D){jQuery.historyCallback=D;var C=location.hash;jQuery.historyCurrentHash=C;if(jQuery.browser.msie){if(jQuery.historyCurrentHash===""){jQuery.historyCurrentHash="#"}$("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');var A=$("#jQuery_history")[0];var B=A.contentWindow.document;B.open();B.close();B.location.hash=C}else{if($.browser.safari){jQuery.historyBackStack=[];jQuery.historyBackStack.length=history.length;jQuery.historyForwardStack=[];jQuery.isFirst=true}}jQuery.historyCallback(C.replace(/^#/,""));setInterval(jQuery.historyCheck,100)},historyAddHistory:function(A){jQuery.historyBackStack.push(A);jQuery.historyForwardStack.length=0;this.isFirst=true},historyCheck:function(){if(jQuery.browser.msie){var A=$("#jQuery_history")[0];var D=A.contentDocument||A.contentWindow.document;var F=D.location.hash;if(F!=jQuery.historyCurrentHash){location.hash=F;jQuery.historyCurrentHash=F;jQuery.historyCallback(F.replace(/^#/,""))}}else{if($.browser.safari){if(!jQuery.dontCheck){var B=history.length-jQuery.historyBackStack.length;if(B){jQuery.isFirst=false;var C;if(B<0){for(C=0;C<Math.abs(B);C++){jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())}}else{for(C=0;C<B;C++){jQuery.historyBackStack.push(jQuery.historyForwardStack.shift())}}var E=jQuery.historyBackStack[jQuery.historyBackStack.length-1];if(E!==undefined){jQuery.historyCurrentHash=location.hash;jQuery.historyCallback(E)}}else{if(jQuery.historyBackStack[jQuery.historyBackStack.length-1]===undefined&&!jQuery.isFirst){if(document.URL.indexOf("#")>=0){jQuery.historyCallback(document.URL.split("#")[1])}else{F=location.hash;jQuery.historyCallback("")}jQuery.isFirst=true}}}}else{F=location.hash;if(F!=jQuery.historyCurrentHash){jQuery.historyCurrentHash=F;jQuery.historyCallback(F.replace(/^#/,""))}}}},historyLoad:function(D){var E;if(jQuery.browser.safari){E=D}else{E="#"+D;location.hash=E}jQuery.historyCurrentHash=E;if(jQuery.browser.msie){var A=$("#jQuery_history")[0];var C=A.contentWindow.document;C.open();C.close();C.location.hash=E;jQuery.historyCallback(D)}else{if(jQuery.browser.safari){jQuery.dontCheck=true;this.historyAddHistory(D);var B=function(){jQuery.dontCheck=false};window.setTimeout(B,200);jQuery.historyCallback(D);location.hash=E}else{jQuery.historyCallback(D)}}}});