
Lightboxes.sharedLightboxModalProvider=function(){var that={};that.getContents=function(){var contents=$("#SharedLightbox").replaceWith("");contents.show();return contents;};var showLink=function(lightboxId){$("#SharedLink").val(Lightboxes.sharedBaseUrl+lightboxId);$("#SharedLightbox").show();$("#SharedLinkContainer").show();$("#SharedLink").focus().select();$("#SharedLink").click(function(){this.select();});};var showError=function(){$("#SharedLightbox").show();$("#SharedLightbox #Error").show();};that.init=function(result){$("#LoadingArea").hide();if(result.IsSuccessful){showLink(result.LightboxId);}
else{showError();}
$("#CloseSharedLightbox").click(function(){$(document).trigger("CloseSharedLightbox");});};that.reset=function(){var contents=$("#SharedLightbox").replaceWith("");contents.hide();$("body").append(contents);$("#SharedLightbox #Error").hide();$("#SharedLink").val("");$("#LoadingArea").show();$("#SharedLinkContainer").hide();};return that;};

DeleteLightboxModal=function(successCallback){var width=489;var modal=null;function wrapper(){return $("#DeleteLightboxDialog");}
function find(selector){return wrapper().find(selector);}
var setContent=function(lightboxName){var deleteDialog=wrapper().replaceWith("");deleteDialog.css('display','block');deleteDialog.find('.deleteLightboxName').html(lightboxName);modal.content=deleteDialog.outerHtml();};function readdToDom(){var deleteDialog=wrapper().replaceWith("");deleteDialog.hide();$("body").append(deleteDialog);};function hookUpEvents(modal){find("#Cancel").click(function(){modal.close();});find("#Delete").click(function(){successCallback();modal.close();});};$(document).bind(events.Modal.BeforeClose,readdToDom);return{display:function(lightboxName){modal=new alertWindow(width,0);setContent(lightboxName);modal._show();hookUpEvents(modal);},close:function(){modal.close();}};};

RenameLightboxModal=function(){var width=489;var modal=null;function wrapper(){return $("#RenameLightboxDialog");}
function find(selector){return wrapper().find(selector);}
var setContent=function(lightboxName){var renameDialog=wrapper().replaceWith("");renameDialog.css('display','block');renameDialog.find('.renameLightboxName').text(lightboxName);modal.content=renameDialog.outerHtml();};function readdToDom(){var renameDialog=wrapper().replaceWith("");renameDialog.hide();$("body").append(renameDialog);};function sortDropDownListByText(dropdownlist){var selected=dropdownlist.val();dropdownlist.html($("option",dropdownlist).sort(function(a,b){return a.text.toLowerCase()==b.text.toLowerCase()?0:a.text.toLowerCase()<b.text.toLowerCase()?-1:1}));dropdownlist.val(selected);}
function hookUpEvents(modal){find("#Cancel").click(function(){modal.close();});find("#Rename").click(function(){find("#Cancel").attr('disabled','disabled');find('#Rename').attr('disabled','disabled');var name=$('#NewLightboxName').val();var lightboxId=$('#RenameLightboxSelect').val();$.ajax({url:"/lightboxes/rename",type:"POST",data:{'lightboxid':lightboxId,'newlightboxname':name},success:function(data){if($.isJson(data)){document.location.reload(true);}else{find("#Cancel").removeAttr('disabled');find('#Rename').removeAttr('disabled');wrapper().replaceWith(data);refreshDropDown(lightboxId);hookUpEvents(modal);wrapper().show();modal.border.height(modal.dialog.height()+53);}}});});};$(document).bind(events.Modal.BeforeClose,refreshDialog);$(document).bind(events.Modal.BeforeClose,readdToDom);function refreshDialog(){$.ajax({url:"/lightboxes/rename",type:"GET",success:function(data){wrapper().replaceWith(data);hookUpEvents(modal);}});}
function refreshDropDown(lightboxId){if(document.location.pathname==('/search/'))
$('#RenameLightboxSelect').html($('#ActiveLightbox').html()).val(lightboxId);else{if($('#LightboxSelect').length){$('#RenameLightboxSelect').html($('#LightboxSelect').html()).val(lightboxId);}else if($('#LightboxNameAndCount').length){$('#RenameLightboxSelect').empty().append($("<option></option>").attr("value",$('#LightboxNameAndCount').attr('lightboxid')).text($('#LightboxNameAndCount').text()));}}}
return{display:function(lightboxName){modal=new ModalDialog(width,0);refreshDropDown($('#LightboxSelect option:selected').val());setContent(lightboxName);modal._show();hookUpEvents(modal);},close:function(){modal.close();}};};$(document).ready(function(){$('#NewLightboxName').maxLength(25);});