/**
 * Galleria (http://monc.se/kitchen)
 *
 * Version 1.0
 * Februari 21, 2008
 *
 * Copyright (c) 2008 David Hellsing (http://monc.se)
 * Licensed under the GPL licenses.
 * http://www.gnu.org/licenses/gpl.txt
 **/
(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){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 O=B(this);var J=B.meta?B.extend({},F,O.data()):F;J.clickNext=B(this).is(":only-child")?false:J.clickNext;var N=B(this).find("a").is("a")?B(this).find("a"):false;var L=B(this).children("img").css("display","none");var Q=N?N.attr("href"):L.attr("src");var K=N?N.attr("title"):L.attr("title");var M=new Image();if(J.history&&(window.location.hash&&window.location.hash.replace(/\#/,"")==Q)){O.siblings(".active").removeClass("active");O.addClass("active")}B(M).load(function(){B(this).attr("alt",L.attr("alt"));var T=N?N.find("img").addClass("thumb noscale").css("display","none"):L.clone(true).addClass("thumb").css("display","none");if(N){N.replaceWith(T)}if(!T.hasClass("noscale")){var R=Math.ceil(L.width()/L.height()*O.height());var S=Math.ceil(L.height()/L.width()*O.width());if(R<S){T.css({height:"auto",width:O.width(),marginTop:-(S-O.height())/2})}else{T.css({width:"auto",height:O.height(),marginLeft:-(R-O.width())/2})}}else{window.setTimeout(function(){T.css({marginLeft:-(T.width()-O.width())/2,marginTop:-(T.height()-O.height())/2})},1)}T.attr("rel",Q);T.attr("title",K);T.click(function(){B.galleria.activate(Q)});T.hover(function(){B(this).addClass("hover")},function(){B(this).removeClass("hover")});O.hover(function(){O.addClass("hover")},function(){O.removeClass("hover")});O.prepend(T);T.css("display","block");J.onThumb(jQuery(T));if(O.hasClass("active")){B.galleria.activate(Q)}L.remove()}).error(function(){O.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 C=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 D=B(new Image()).attr("src",F).addClass("replaced");C.empty().append(D);C.siblings(".caption").text(E.attr("title"));B.galleria.onImage(D,C.siblings(".caption"),E);if(B.galleria.clickNext){D.css("cursor","pointer").click(function(){B.galleria.next()})}}else{C.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(C){jQuery.historyCallback=C;var D=location.hash;jQuery.historyCurrentHash=D;if(jQuery.browser.msie){if(jQuery.historyCurrentHash==""){jQuery.historyCurrentHash="#"}$("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');var B=$("#jQuery_history")[0];var A=B.contentWindow.document;A.open();A.close();A.location.hash=D}else{if($.browser.safari){jQuery.historyBackStack=[];jQuery.historyBackStack.length=history.length;jQuery.historyForwardStack=[];jQuery.isFirst=true}}jQuery.historyCallback(D.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 D=$("#jQuery_history")[0];var A=D.contentDocument||D.contentWindow.document;var F=A.location.hash;if(F!=jQuery.historyCurrentHash){location.hash=F;jQuery.historyCurrentHash=F;jQuery.historyCallback(F.replace(/^#/,""))}}else{if($.browser.safari){if(!jQuery.dontCheck){var C=history.length-jQuery.historyBackStack.length;if(C){jQuery.isFirst=false;if(C<0){for(var B=0;B<Math.abs(C);B++){jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())}}else{for(var B=0;B<C;B++){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{var F=location.hash;jQuery.historyCallback("")}jQuery.isFirst=true}}}}else{var 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 C=$("#jQuery_history")[0];var A=C.contentWindow.document;A.open();A.close();A.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)}}}});
