jQuery(function(b){var a={active:false,init:function(){a.images=b(".flickr_badge_image a");a.images.click(function(){a.current_idx=a.images.index(this);b(a.create()).modal({closeHTML:"",overlayId:"gallery-overlay",containerId:"gallery-container",containerCss:{left:0,width:"100%"},opacity:80,position:["10%",null],onOpen:a.open,onClose:a.close});return false})},create:function(){return b("<div id='gallery'> 					<div id='gallery-image-container'> 						<div id='gallery-controls'> 							<div id='gallery-previous'> 								<a href='#' id='gallery-previous-link'>&laquo; <u>P</u>rev</a> 							</div> 							<div id='gallery-next'> 								<a href='#' id='gallery-next-link'><u>N</u>ext &raquo;</a> 							</div> 						</div> 					</div> 					<div id='gallery-meta-container'> 						<div id='gallery-meta'> 							<div id='gallery-info'><span id='gallery-title'></span><span id='gallery-pages'></span></div> 							<div id='gallery-close'><a href='#' class='simplemodal-close'>X</a></div> 						</div> 					</div> 				</div>")},open:function(c){a.container=c.container[0];a.gallery=b("#gallery",a.container);a.image_container=b("#gallery-image-container",a.container);a.controls=b("#gallery-controls",a.container);a.next=b("#gallery-next-link",a.container);a.previous=b("#gallery-previous-link",a.container);a.meta_container=b("#gallery-meta-container",a.container);a.meta=b("#gallery-meta",a.container);a.title=b("#gallery-title",a.container);a.pages=b("#gallery-pages",a.container);c.overlay.slideDown(300,function(){c.container.css({height:0}).show(function(){c.data.slideDown(300,function(){a.display()})})})},close:function(e){var c=this;a.meta.slideUp(function(){a.image_container.fadeOut("fast",function(){e.data.slideUp(500,function(){e.container.fadeOut(500,function(){e.overlay.slideUp(500,function(){c.close()})})});a.unbind()})})},browse:function(c){a.current_idx=b(c).parent().is("#gallery-next")?(a.current_idx+1):(a.current_idx-1);a.display()},display:function(){a.controls.hide();a.meta.slideUp(300,function(){a.meta_container.hide();a.image_container.fadeOut("fast",function(){b("#gallery-image",a.container).remove();var c=new Image();c.onload=function(){a.load(c)};c.src=a.images.eq(a.current_idx).find("img").attr("src").replace(/_(s|t|m)\.jpg$/,".jpg");if(a.current_idx!==0){var d=new Image();d.src=a.images.eq(a.current_idx-1).find("img").attr("src").replace(/_(s|t|m)\.jpg$/,".jpg")}if(a.current_idx!==(a.images.length-1)){var e=new Image();e.src=a.images.eq(a.current_idx+1).find("img").attr("src").replace(/_(s|t|m)\.jpg$/,".jpg")}})})},load:function(d){var e=b(d);e.attr("id","gallery-image").hide().appendTo("body");var f=e.outerHeight(true),c=e.outerWidth(true);if(a.gallery.height()!==f||a.gallery.width()!==c){a.gallery.animate({height:f},300,function(){a.gallery.animate({width:c},300,function(){a.show(e)})})}else{a.show(e)}},show:function(c){c.show();a.image_container.prepend(c).fadeIn("slow",function(){a.showControls();a.showMeta()})},showControls:function(){a.next.hide().removeClass("disabled");a.previous.hide().removeClass("disabled");a.unbind();if(a.current_idx===0){a.previous.addClass("disabled")}if(a.current_idx===(a.images.length-1)){a.next.addClass("disabled")}a.controls.show();b("a",a.controls[0]).bind("click.gallery",function(){a.browse(this);return false});b(document).bind("keydown.gallery",function(c){if(!a.active){if((c.keyCode===37||c.keyCode===80)&&a.current_idx!==0){a.active=true;a.previous.trigger("click.gallery")}else{if((c.keyCode===39||c.keyCode===78)&&a.current_idx!==(a.images.length-1)){a.active=true;a.next.trigger("click.gallery")}}}});b("div",a.controls[0]).hover(function(){var d=this,c=b(d).find("a:not(.disabled)");if(c.length>0){c.show()}},function(){b(this).find("a").hide()})},showMeta:function(){var c=a.images.eq(a.current_idx).clone(),d=c.find("img").attr("title");a.title.html(c.attr("title","View on Flickr").html(d));a.pages.html("Image "+(a.current_idx+1)+" of "+a.images.length);a.meta_container.show();a.meta.slideDown(function(){a.active=false})},unbind:function(){b("a",a.controls[0]).unbind("click.gallery");b(document).unbind("keydown.gallery");b("div",a.controls[0]).unbind("mouseenter mouseleave")}};a.init()});
