Object.extend(YAHOO.app.gallery,{dialog:null,onModalCancel:function(b){if(b){YAHOO.util.Event.stopEvent(b)}try{var a=YAHOO.app.gallery;if(a.dlg){a.dlg.hide()}}catch(c){YAHOO.app.showException(c)}},onModalSuccess:function(d,a){var b=YAHOO.app.gallery;try{var f=true;if(a){if(a.noUpdate){f=false}}if(f){$("mainContent").update(d.responseText);b.addAlbumCommandEvents();b.addPhotoCommandEvents();b.addUserMenuEvents(true)}YAHOO.app.hideLoading();b.dlg.hide();YAHOO.app.showErrors(a)}catch(c){YAHOO.app.showException(c)}},onModalSubmit:function(c){YAHOO.util.Event.stopEvent(c);try{YAHOO.app.showLoading();var f=Form.serialize("galleryForm");var a=this.action;var b=new Ajax.Request(a,{parameters:f,onSuccess:YAHOO.app.gallery.onModalSuccess,onFailure:YAHOO.app.onFailure})}catch(d){YAHOO.app.showException(d)}},updateGalleryModal:function(d,a){var b=YAHOO.app.gallery;try{YAHOO.app.showErrors(a);if(a){if(a.title){b.dlg.setHeader(a.title)}else{b.dlg.setHeader("Edit")}if(a.width){b.dlg.cfg.queueProperty("width",a.width)}}b.dlg.setBody(d.responseText);YAHOO.app.hideLoading();b.dlg.show()}catch(c){YAHOO.app.showException(c)}},doGalleryModal:function(b){try{YAHOO.app.showLoading();var d=YAHOO.app.gallery;if(!d.dialog){var a={width:400,visible:false,constraintoviewport:true,modal:true,postmethod:"none",context:["bd","tl","tl"]};var h=new YAHOO.widget.Dialog("galleryModalDialog",a);h.setHeader("Edit");h.setBody("");h.render("bd");d.dlg=h;YAHOO.util.Event.addListener("galleryCancelButton","click",d.onModalCancel);YAHOO.util.Event.addListener("galleryForm","submit",d.onModalSubmit)}var c=new Ajax.Request(b,{onSuccess:d.updateGalleryModal,onFailure:YAHOO.app.onFailure})}catch(f){YAHOO.app.showException(f,"gallery->doGalleryModal")}},doGalleryRequest:function(b,a){try{YAHOO.app.showLoading();if(!a){a=YAHOO.app.onFailure}var c={onSuccess:a,onFailure:YAHOO.app.onFailure};var d=new Ajax.Request(b,c)}catch(f){YAHOO.app.showException(f,"gallery->doGalleryRequest")}},onAlbumCommand:function(h){try{var j=this.id.replace("galleryAlbumCommands","");var c=this.value;var b=$("galleryAlbumId"+j).value;var a=false,d;this.value="nothing";if(c==="delete"){a="/gallery/ajaxDeleteAlbum/"+b;YAHOO.app.gallery.deleteAlbum(a);return}else{if(c.match(/^moveto-\d+$/)){var g=c.replace("moveto-","");if(confirm("Are you sure you wish to move this album to page "+g+"?")){a="/gallery/ajaxMoveAlbumToPage/"+b+"/"+g;var i=function(k,e){YAHOO.app.hideLoading();YAHOO.app.showErrors(e);if(window.location.href.match(/\/page-\d+$/)){window.location.href=window.location.href.replace(/\/page-\d+$/,"/page-"+g)}else{window.location.href=window.location.href+"/page-"+g}};YAHOO.app.gallery.doGalleryRequest(a,i);return}}else{if(c==="add"){window.location.href="/gallery/upload/"+b}else{if(c==="edit"){a="/gallery/ajaxEditAlbum/"+b}else{if(c==="move"){a="/gallery/ajaxMoveAlbum/"+b}}}}}if(a){YAHOO.app.gallery.doGalleryModal(a)}}catch(f){YAHOO.app.showException(f,"onAlbumCommand")}},addAlbumCommandEvents:function(){try{var a=Element.select("bd","select.galleryAlbumCommands");for(var d=0,b=a.length;d<b;d++){var c=a[d];YAHOO.util.Event.purgeElement(c.id);YAHOO.util.Event.addListener(c.id,"change",this.onAlbumCommand)}}catch(f){YAHOO.app.showException(f,"gallery->addAlbumCommandEvents")}},onPhotoCommand:function(d){try{var c=this.id.replace("galleryPhotoCommands","");var h=this.value;var i=$("galleryPhotoId"+c).value;var b=false,a;this.value="nothing";if(h==="delete"){b="/gallery/ajaxDeletePhoto/"+i;YAHOO.app.gallery.deletePhoto(b);return}else{if(h==="default"){if(confirm("Are you sure you want to set this as your default photo?")){b="/gallery/ajaxMakeDefaultPhoto/"+i;YAHOO.app.gallery.doGalleryRequest(b)}return}else{if(h==="setpagebg"){if(confirm("Are you sure you want to set this as your profile's inner background?")){b="/gallery/ajaxMakePageBackground/"+i;YAHOO.app.gallery.doGalleryRequest(b)}return}else{if(h==="setbodybg"){if(confirm("Are you sure you want to set this as your profile's outer background?")){b="/gallery/ajaxMakeBodyBackground/"+i;YAHOO.app.gallery.doGalleryRequest(b)}return}else{if(h.match(/^moveto-\d+$/)){var f=h.replace("moveto-","");if(confirm("Are you sure you wish to move this photo to page "+f+"?")){b="/gallery/ajaxMovePhotoToPage/"+i+"/"+f;a=function(e){YAHOO.app.hideLoading();if(window.location.href.match(/\/page-\d+$/)){window.location.href=window.location.href.replace(/\/page-\d+$/,"/page-"+f)}else{window.location.href=window.location.href+"/page-"+f}};YAHOO.app.gallery.doGalleryRequest(b,a);return}}else{if(h==="highlight"){b="/gallery/ajaxMakeHighlight/"+i}else{if(h==="edit"){b="/gallery/ajaxEditPhoto/"+i}else{if(h==="move"){b="/gallery/ajaxMovePhoto/"+i}else{if(h==="copy"){b="/gallery/ajaxCopyPhoto/"+i}}}}}}}}}if(b){YAHOO.app.gallery.doGalleryModal(b)}}catch(g){YAHOO.app.showException(g,"onPhotoCommand")}},addPhotoCommandEvents:function(){try{var a=Element.select("bd","select.galleryPhotoCommands");for(var d=0,b=a.length;d<b;d++){var c=a[d];YAHOO.util.Event.purgeElement(c.id);YAHOO.util.Event.addListener(c.id,"change",this.onPhotoCommand)}}catch(f){YAHOO.app.showException(f,"gallery->addPhotoCommandEvents")}},onMicroSuccess:function(e,b){$("photoData").update(e.responseText);if(b){if(b.scrollTo){YAHOO.app.gallery.microMoveTo(b.scrollTo)}else{YAHOO.app.gallery.microMoveTo(0)}if(b.title){var c=$("galleryPhotoTitle");if(c){c.update(b.title)}}if(b.path){var d=b.path;var a=$("galleryEditPhotoLink");if(a){a.href="/gallery/editPhoto/"+d}a=$("galleryMovePhotoLink");if(a){a.href="/gallery/movePhoto/"+d}a=$("galleryCopyPhotoLink");if(a){a.href="/gallery/copyPhoto/"+d}a=$("galleryDeletePhotoLink");if(a){a.href="/gallery/deletePhoto/"+d}}}YAHOO.app.hideLoading();YAHOO.app.showErrors(b)},onMicroThumb:function(c){try{var a=Event.element(c);if(a.tagName==="IMG"){a=a.up("a")}if(a){Event.stop(c);YAHOO.app.showLoading();var b=new Ajax.Request(a.href,{onSuccess:YAHOO.app.gallery.onMicroSuccess,onFailure:YAHOO.app.showErrors})}}catch(d){YAHOO.app.showException(d,"onMicroThumb")}},addMicroThumbEvents:function(){try{var a=Element.select("bd","a.microThumbLink");for(var d=0,b=a.length;d<b;d++){var c=a[d];Event.observe(c.id,"click",this.onMicroThumb)}}catch(f){YAHOO.app.showException(f,"gallery->addMicroThumbEvents")}},onCommentMessage:function(c){try{var b=Event.element(c);var a=b.href.replace("/emails","/messages");Event.stop(c);YAHOO.app.messagePopup(a,"newMessage")}catch(d){YAHOO.app.showException(d,"onCommentMessage")}},addCommentMessageLinks:function(){try{var a=Element.select("bd","a.commentMessageLink");for(var d=0,b=a.length;d<b;d++){var c=a[d];Event.observe(c.id,"click",this.onCommentMessage)}}catch(f){YAHOO.app.showException(f,"gallery->addCommentMessageLinks")}},onModalLink:function(a){YAHOO.util.Event.stopEvent(a);YAHOO.app.gallery.doGalleryModal(this.href)},onDeleteAlbum:function(a){YAHOO.app.gallery.deleteAlbum(this.href)},onDeletePhoto:function(a){if(!confirm("Are you sure you wish to delete this photo?  This cannot be undone.")){YAHOO.util.Event.stopEvent(a)}},addUserMenuEvents:function(b){try{var a;a=$("galleryDeleteAlbumLink");if(a){a.href=a.href.replace("confirmDeleteAlbum","deleteAlbum")}a=$("galleryAddPhotosLink2");if(a){a.href=a.href.replace("/gallery/add/","/gallery/ajaxAdd/")}a=$("galleryAddPhotosLink");if(a){a.href=a.href.replace("/gallery/add/","/gallery/ajaxAdd/")}a=$("galleryDeletePhotoLink");if(a){a.href=a.href.replace("confirmDeletePhoto","deletePhoto")}if(!b){YAHOO.util.Event.addListener("galleryMoveAlbumLink","click",this.onModalLink);YAHOO.util.Event.addListener("galleryDeleteAlbumLink","click",this.onDeleteAlbum);YAHOO.util.Event.addListener("galleryNewAlbumLink","click",this.onModalLink);YAHOO.util.Event.addListener("galleryEditAlbumLink","click",this.onModalLink);YAHOO.util.Event.addListener("galleryAddPhotosLink","click",this.onModalLink);YAHOO.util.Event.addListener("galleryEditPhotoLink","click",this.onModalLink);YAHOO.util.Event.addListener("galleryCopyPhotoLink","click",this.onModalLink);YAHOO.util.Event.addListener("galleryMovePhotoLink","click",this.onModalLink);YAHOO.util.Event.addListener("galleryAddPhotosLink2","click",this.onModalLink);YAHOO.util.Event.addListener("galleryMovePhotoLink","click",this.onModalLink);YAHOO.util.Event.addListener("galleryDeletePhotoLink","click",this.onDeletePhoto)}}catch(c){YAHOO.app.showException(c,"galleryUserMenuEvents")}},microMoveTo:function(a){try{if(a<350){a=0}else{a=a-305}var b=new YAHOO.util.Scroll("microGalleryContainer",{scroll:{to:[a,0]}},0.5,YAHOO.util.Easing.easeOut);b.animate()}catch(c){YAHOO.app.showException(c)}},onDeleteAlbumSuccess:function(c,a){YAHOO.app.hideLoading();if(a.albumId){var b=$("item_album"+a.albumId);if(b){b.remove()}}YAHOO.app.showErrors(a)},onDeletePhotoSuccess:function(c,a){YAHOO.app.hideLoading();if(a){if(a.photoId){var b=$("item_photo"+a.photoId);if(b){b.remove()}}}YAHOO.app.showErrors(a)},deleteAlbum:function(a){if(confirm("Are you sure you wish to delete this album along with all of its subalbums and photos?  This cannot be undone.")){YAHOO.app.showLoading();var b=new Ajax.Request(a,{onSuccess:YAHOO.app.gallery.onDeleteAlbumSuccess,onFailure:YAHOO.app.onFailure})}},deletePhoto:function(a){if(confirm("Are you sure you wish to delete this image?")){YAHOO.app.showLoading();var b=new Ajax.Request(a,{onSuccess:YAHOO.app.gallery.onDeletePhotoSuccess,onFailure:YAHOO.app.onFailure})}}});