var copperPlatePress;copperPlatePress=copperPlatePress?copperPlatePress:{};copperPlatePress.ImageLibrary=function(a){this.items=[];this._eventBroadcaster=$(this);this._randomize=!!a};
copperPlatePress.ImageLibrary.prototype.loadLibrary=function(a){$.ajax({url:a,dataType:"xml",success:$.proxy(function(b){var d=[];$(b).find("item").each(function(e,c){d.push(new copperPlatePress.ImageLibraryItem($(c).find("image").first().text(),$(c).find("thumbnail").first().text(),copperPlatePress.ImageLibrary.createHtmlNodes($(c).find("description > *"))))});this.items=this.items.concat(this.items,d);this._randomize&&this.items.sort(function(){return 0.5-Math.random()});this._eventBroadcaster.trigger("load")},
this)})};
copperPlatePress.ImageLibrary.createHtmlNodes=function(a){for(var b=[],d=function(c){var f=null;if(c.nodeType==1){f=document.createElement(c.nodeName);for(var g=0;g<c.attributes.length;g++)$(f).attr(c.attributes[g].name,c.attributes[g].value);for(g=0;g<c.childNodes.length;g++){var h=c.childNodes[g];h&&f.appendChild(d(h))}}else if(c.nodeType==3)f=document.createTextNode(c.nodeValue);else if(c.nodeType==5){f=document.createElement("span");f.innerHTML="&"+c.nodeName+";";f=f.firstChild}return f},e=0;e<
a.length;e++)b.push(d(a[e]));return b};copperPlatePress=copperPlatePress?copperPlatePress:{};copperPlatePress.ImageLibraryItem=function(a,b,d){this.imageSrc=a?a:"";this.thumbnailSrc=b?b:"";this.descriptionNodes=d?d:[]};copperPlatePress.ImageLibraryItem.prototype.getImageSrc=function(){return this.imageSrc};copperPlatePress.ImageLibraryItem.prototype.getThumbnailSrc=function(){return this.thumbnailSrc};
copperPlatePress.ImageLibraryItem.prototype.getDescriptionNodes=function(){for(var a=[],b=0;b<this.descriptionNodes.length;b++)a.push(this.descriptionNodes[b].cloneNode(true));return a};copperPlatePress=copperPlatePress?copperPlatePress:{};copperPlatePress.GalleryImage=function(){this.node=this.build();this.src=null;this.isLoaded=false};
copperPlatePress.GalleryImage.prototype.build=function(){var a=document.createElement("div");$(a).addClass("copperPlatePress-GalleryImage");$(document.createElement("div")).appendTo(a);$(document.createElement("span")).appendTo(a);return a};
copperPlatePress.GalleryImage.prototype.loadImage=function(a){if(this.src!=a){this.src=a;this.isLoaded=false;this.clearLoadEffect();this.clearImage();this.setLoadingIndicator(true);var b=$(document.createElement("img"));b.load(jQuery.proxy(this._onLoad,this));b.error(function(d){d&&d.target&&$(d.target).unbind()});b.attr("src",a);b.complete&&!this.isLoaded&&b.trigger("load")}};
copperPlatePress.GalleryImage.prototype.setLoadingIndicator=function(a){a?$(this.node).addClass("copperPlatePress-GalleryImage-loading"):$(this.node).removeClass("copperPlatePress-GalleryImage-loading")};copperPlatePress.GalleryImage.prototype.setSelectedIndicator=function(a){a?$(this.node).addClass("copperPlatePress-GalleryImage-selected"):$(this.node).removeClass("copperPlatePress-GalleryImage-selected")};
copperPlatePress.GalleryImage.prototype._onLoad=function(a){$(a.target).unbind();this.isLoaded=true;this.onLoadImage(this.src);this.onLoadEffect(this.src)};copperPlatePress.GalleryImage.prototype.onLoadImage=function(a){this.setLoadingIndicator(false);$(this.node.firstChild).css({backgroundImage:"url("+a+")"})};copperPlatePress.GalleryImage.prototype.clearImage=function(){$(this.node.firstChild).css({backgroundImage:"none"})};copperPlatePress.GalleryImage.prototype.onLoadEffect=function(){$(this.node.firstChild).css({opacity:0}).animate({opacity:1})};
copperPlatePress.GalleryImage.prototype.clearLoadEffect=function(){$(this.node.firstChild).stop(true,false)};copperPlatePress=copperPlatePress?copperPlatePress:{};copperPlatePress.GalleryThumbnails=function(a,b,d){this.containerNode=a;this.imageLibrary=b;this.thumbnails=[];this.selectedIndex=-1;this.size=d;this.page=-1;this.pageLength=Math.ceil(this.imageLibrary.items.length/this.size);this._eventBroadcaster=$(this);this.openPage(0)};copperPlatePress.GalleryThumbnails.THUMBNAIL_SELECTED="thumbnailselected";
copperPlatePress.GalleryThumbnails.prototype.openPage=function(a){a=a<this.pageLength?a:this.pageLength-1;a=a>=0?a:0;if(this.page!=a){var b=a>this.page?1:-1,d=this.thumbnails;this.thumbnails=[];for(var e=[],c=a*this.size;c<this.imageLibrary.items.length&&c<a*this.size+this.size;c++){var f=new copperPlatePress.GalleryImage;$(f.node).click($.proxy(this.onThumbnailClick,this));this.thumbnails.push(f);e.push(this.imageLibrary.items[c])}this.page=a;this.doTransition(this.thumbnails,d,e,b);this.updateSelectedIndicator()}};
copperPlatePress.GalleryThumbnails.prototype.openNextPage=function(){this.openPage(this.page+1)};copperPlatePress.GalleryThumbnails.prototype.openPreviousPage=function(){this.openPage(this.page-1)};copperPlatePress.GalleryThumbnails.prototype.onThumbnailClick=function(a){for(var b=0;b<this.thumbnails.length;b++)a.currentTarget==this.thumbnails[b].node&&this.setSelected(this.page*this.size+b)};
copperPlatePress.GalleryThumbnails.prototype.setSelected=function(a){if(a>=0&&a<this.imageLibrary.items.length){this.selectedIndex=a;this._eventBroadcaster.trigger(copperPlatePress.GalleryThumbnails.THUMBNAIL_SELECTED,[this.imageLibrary.items[this.selectedIndex]]);this.updateSelectedIndicator()}};copperPlatePress.GalleryThumbnails.prototype.updateSelectedIndicator=function(){for(var a=0;a<this.thumbnails.length;a++)this.thumbnails[a].setSelectedIndicator(this.page*this.size+a==this.selectedIndex)};
copperPlatePress.GalleryThumbnails.prototype.doTransition=function(a,b,d){this.clearTransition();for(var e=0;e<b.length;e++)this.containerNode.removeChild(b[e].node);for(e=0;e<a.length;e++){this.containerNode.appendChild(a[e].node);a[e].loadImage(d[e].thumbnailSrc)}};copperPlatePress.GalleryThumbnails.prototype.clearTransition=function(){};copperPlatePress=copperPlatePress?copperPlatePress:{};
copperPlatePress.Gallery=function(a,b,d,e,c){this.descriptionContainer=b;this.imageContainer=a;this.image=new copperPlatePress.GalleryImage;$(this.imageContainer).append(this.image.node);this.galleryThumbnails=d;$(this.galleryThumbnails).bind(copperPlatePress.GalleryThumbnails.THUMBNAIL_SELECTED,$.proxy(this.onThumbnailSelected,this));e&&$(e).click(function(f){f.preventDefault();d.openNextPage()});c&&$(c).click(function(f){f.preventDefault();d.openPreviousPage()})};
copperPlatePress.Gallery.prototype.onThumbnailSelected=function(a,b){this.setImage(b.getImageSrc());this.positionImage();this.setDescription(b.getDescriptionNodes());this.positionDescription()};copperPlatePress.Gallery.prototype.setDescription=function(a){$(this.descriptionContainer).empty().append(a)};
copperPlatePress.Gallery.prototype.positionDescription=function(){if(this.descriptionContainer&&this.descriptionContainer.parentNode){var a=$(this.descriptionContainer),b=$(this.descriptionContainer.parentNode);a.css("top",(b.height()-a.height())*0.3+"px")}};copperPlatePress.Gallery.prototype.setImage=function(a){this.image.loadImage(a)};copperPlatePress.Gallery.prototype.positionImage=function(){};

