text: $(function(){$.fn.imagesLoaded=function(e){function s(){e.call(r,t)}function o(){if(--n<=0&&this.src!==i){setTimeout(s);t.off("load error",o)}}var t=this.find("img"),n=t.length,r=this,i="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";if(!n){s()}t.on("load error",o).each(function(){if(this.complete||this.complete===undefined){var e=this.src;this.src=i;this.src=e}});return this};var e=$("#rg-gallery"),t=e.find("div.es-carousel-wrapper"),n=t.find("ul > li"),r=n.length;Gallery=function(){var i=0,s="carousel",o=false,u=function(){n.add('<img src="images/ajax-loader.gif"/><img src="images/black.png"/>').imagesLoaded(function(){f();l();h(n.eq(i))});if(s==="carousel")a()},a=function(){t.show().elastislide({imageW:65,onClick:function(e){if(o)return false;o=true;h(e);i=e.index()}});t.elastislide("setCurrent",i)},f=function(){var n=$('<a href="#" class="rg-view-full"></a>'),r=$('<a href="#" class="rg-view-thumbs rg-view-selected"></a>');e.prepend($('<div class="rg-view"/>').append(n).append(r));n.on("click.rgGallery",function(e){if(s==="carousel")t.elastislide("destroy");t.hide();n.addClass("rg-view-selected");r.removeClass("rg-view-selected");s="fullview";return false});r.on("click.rgGallery",function(e){a();r.addClass("rg-view-selected");n.removeClass("rg-view-selected");s="carousel";return false});if(s==="fullview")n.trigger("click")},l=function(){$("#img-wrapper-tmpl").tmpl({itemsCount:r}).appendTo(e);if(r>1){var t=e.find("a.rg-image-nav-prev"),n=e.find("a.rg-image-nav-next"),i=e.find("div.rg-image");t.on("click.rgGallery",function(e){c("left");return false});n.on("click.rgGallery",function(e){c("right");return false});i.touchwipe({wipeLeft:function(){c("right")},wipeRight:function(){c("left")},preventDefaultEvents:false});$(document).on("keyup.rgGallery",function(e){if(e.keyCode==39)c("right");else if(e.keyCode==37)c("left")})}},c=function(e){if(o)return false;o=true;if(e==="right"){if(i+1>=r)i=0;else++i}else if(e==="left"){if(i-1<0)i=r-1;else--i}h(n.eq(i))},h=function(r){var u=e.find("div.rg-loading").show();n.removeClass("selected");r.addClass("selected");var a=r.find("img"),f=a.data("large"),l=a.data("description");$("<img/>").load(function(){e.find("div.rg-image").empty().append('<img src="'+f+'"/>');if(l)e.find("div.rg-caption").show().children("p").empty().text(l);u.hide();if(s==="carousel"){t.elastislide("reload");t.elastislide("setCurrent",i)}o=false}).attr("src",f)},p=function(e){t.find("ul").append(e);n=n.add($(e));r=n.length;t.elastislide("add",e)};return{init:u,addItems:p}}();Gallery.init()})