(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{window.setTimeout(function(){T.css({marginLeft:-(T.width()-L.width())/2,marginTop:-(T.height()-L.height())/2});},1);}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");if(F){var E=jQuery('.galleria img[rel="'+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(C){if(B.galleria.history){B.historyLoad(C);}else{A.onPageLoad(C);}},next:function(){var C=B(A.nextSelector(B('.galleria img[rel="'+B.galleria.current+'"]').parents("li"))).find("img").attr("rel");B.galleria.activate(C);},prev:function(){var C=B(A.previousSelector(B('.galleria img[rel="'+B.galleria.current+'"]').parents("li"))).find("img").attr("rel");B.galleria.activate(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);}}}});
