(function(a){var g;g=a.fn.galleria=function(n){if(!g.hasCSS()){return false}a.historyInit(g.onPageLoad);var o={insert:'.galleria_container',history:true,clickNext:true,onImage:function(b,e,d){},onThumb:function(b){}};var j=a.extend(o,n);for(var m in j){if(m){a.galleria[m]=j[m]}}var p=(a(j.insert).is(j.insert))?a(j.insert):jQuery(document.createElement('div')).insertBefore(this);var q=a(document.createElement('div')).addClass('galleria_wrapper');var r=a(document.createElement('span')).addClass('caption');p.addClass('galleria_container').append(q).append(r);return this.each(function(){a(this).addClass('galleria');a(this).children('li').each(function(f){var c=a(this);var k=a.meta?a.extend({},j,c.data()):j;k.clickNext=a(this).is(':only-child')?false:k.clickNext;var i=a(this).find('a').is('a')?a(this).find('a'):false;var h=a(this).children('img').css('display','none');var l=i?i.attr('href'):h.attr('src');var s=i?i.attr('title'):h.attr('title');var t=new Image();if(k.history&&(window.location.hash&&window.location.hash.replace(/\#/,'')==l)){c.siblings('.active').removeClass('active');c.addClass('active')}a(t).load(function(){a(this).attr('alt',h.attr('alt'));var b=i?i.find('img').addClass('thumb noscale').css('display','none'):h.clone(true).addClass('thumb').css('display','none');if(i){i.replaceWith(b)}if(!b.hasClass('noscale')){var e=Math.ceil(h.width()/h.height()*c.height());var d=Math.ceil(h.height()/h.width()*c.width());if(e<d){b.css({height:'auto',width:c.width(),marginTop:-(d-c.height())/2})}else{b.css({width:'auto',height:c.height(),marginLeft:-(e-c.width())/2})}}else{window.setTimeout(function(){b.css({marginLeft:-(b.width()-c.width())/2,marginTop:-(b.height()-c.height())/2})},1)}b.attr('rel',l);b.attr('title',s);b.click(function(){a.galleria.activate(l)});b.hover(function(){a(this).addClass('hover')},function(){a(this).removeClass('hover')});c.hover(function(){c.addClass('hover')},function(){c.removeClass('hover')});c.prepend(b);b.css('display','block');k.onThumb(jQuery(b));if(c.hasClass('active')){a.galleria.activate(l)}h.remove()}).error(function(){c.html('<span class="error" style="color:red">Error loading image: '+l+'</span>')}).attr('src',l)})})};g.nextSelector=function(b){return a(b).is(':last-child')?a(b).siblings(':first-child'):a(b).next()};g.previousSelector=function(b){return a(b).is(':first-child')?a(b).siblings(':last-child'):a(b).prev()};g.hasCSS=function(){a('body').append(a(document.createElement('div')).attr('id','css_test').css({width:'1px',height:'1px',display:'none'}));var b=(a('#css_test').width()!=1)?false:true;a('#css_test').remove();return b};g.onPageLoad=function(b){var e=a('.galleria_wrapper');var d=a('.galleria img[rel="'+b+'"]');if(b){if(a.galleria.history){window.location=window.location.href.replace(/\#.*/,'')+'#'+b}d.parents('li').siblings('.active').removeClass('active');d.parents('li').addClass('active');var f=a(new Image()).attr('src',b).addClass('replaced');e.empty().append(f);e.siblings('.caption').text(d.attr('title'));a.galleria.onImage(f,e.siblings('.caption'),d);if(a.galleria.clickNext){f.css('cursor','pointer').click(function(){a.galleria.next()})}}else{e.siblings().andSelf().empty();a('.galleria li.active').removeClass('active')}a.galleria.current=b};a.extend({galleria:{current:'',onImage:function(){},activate:function(b){if(a.galleria.history){a.historyLoad(b)}else{g.onPageLoad(b)}},next:function(){var b=a(g.nextSelector(a('.galleria img[rel="'+a.galleria.current+'"]').parents('li'))).find('img').attr('rel');a.galleria.activate(b)},prev:function(){var b=a(g.previousSelector(a('.galleria img[rel="'+a.galleria.current+'"]').parents('li'))).find('img').attr('rel');a.galleria.activate(b)}}})})(jQuery);jQuery.extend({historyCurrentHash:undefined,historyCallback:undefined,historyInit:function(b){jQuery.historyCallback=b;var e=location.hash;jQuery.historyCurrentHash=e;if(jQuery.browser.msie){if(jQuery.historyCurrentHash===''){jQuery.historyCurrentHash='#'}$("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');var d=$("#jQuery_history")[0];var f=d.contentWindow.document;f.open();f.close();f.location.hash=e}else if($.browser.safari){jQuery.historyBackStack=[];jQuery.historyBackStack.length=history.length;jQuery.historyForwardStack=[];jQuery.isFirst=true}jQuery.historyCallback(e.replace(/^#/,''));setInterval(jQuery.historyCheck,100)},historyAddHistory:function(b){jQuery.historyBackStack.push(b);jQuery.historyForwardStack.length=0;this.isFirst=true},historyCheck:function(){if(jQuery.browser.msie){var b=$("#jQuery_history")[0];var e=b.contentDocument||b.contentWindow.document;var d=e.location.hash;if(d!=jQuery.historyCurrentHash){location.hash=d;jQuery.historyCurrentHash=d;jQuery.historyCallback(d.replace(/^#/,''))}}else if($.browser.safari){if(!jQuery.dontCheck){var f=history.length-jQuery.historyBackStack.length;if(f){jQuery.isFirst=false;var c;if(f<0){for(c=0;c<Math.abs(f);c++){jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())}}else{for(c=0;c<f;c++){jQuery.historyBackStack.push(jQuery.historyForwardStack.shift())}}var k=jQuery.historyBackStack[jQuery.historyBackStack.length-1];if(k!==undefined){jQuery.historyCurrentHash=location.hash;jQuery.historyCallback(k)}}else if(jQuery.historyBackStack[jQuery.historyBackStack.length-1]===undefined&&!jQuery.isFirst){if(document.URL.indexOf('#')>=0){jQuery.historyCallback(document.URL.split('#')[1])}else{d=location.hash;jQuery.historyCallback('')}jQuery.isFirst=true}}}else{d=location.hash;if(d!=jQuery.historyCurrentHash){jQuery.historyCurrentHash=d;jQuery.historyCallback(d.replace(/^#/,''))}}},historyLoad:function(b){var e;if(jQuery.browser.safari){e=b}else{e='#'+b;location.hash=e}jQuery.historyCurrentHash=e;if(jQuery.browser.msie){var d=$("#jQuery_history")[0];var f=d.contentWindow.document;f.open();f.close();f.location.hash=e;jQuery.historyCallback(b)}else if(jQuery.browser.safari){jQuery.dontCheck=true;this.historyAddHistory(b);var c=function(){jQuery.dontCheck=false};window.setTimeout(c,200);jQuery.historyCallback(b);location.hash=e}else{jQuery.historyCallback(b)}}});