albums={load:function(){lychee.animate(".album, .photo","contentZoomOut");lychee.content.attr("data-search","");lychee.animate(".divider","fadeOut");startTime=(new Date).getTime();lychee.api("getAlbums","json",function(e){durationTime=(new Date).getTime()-startTime;if(durationTime>300)waitTime=0;else waitTime=300-durationTime;$.timer(waitTime,function(){$("#tools_album, #tools_photo").hide();$("#tools_albums").show();unsortedAlbum=new Object;unsortedAlbum.id=0;unsortedAlbum.title="Unsorted";unsortedAlbum.sysdate=e.unsortNum+" photos";unsortedAlbum.unsorted=1;if(e.unsortThumb0)unsortedAlbum.thumb0=lychee.upload_path+e.unsortThumb0;else unsortedAlbum.thumb0="";if(e.unsortThumb1)unsortedAlbum.thumb1=lychee.upload_path+e.unsortThumb1;else unsortedAlbum.thumb1="";if(e.unsortThumb2)unsortedAlbum.thumb2=lychee.upload_path+e.unsortThumb2;else unsortedAlbum.thumb2="";starredAlbum=new Object;starredAlbum.id="f";starredAlbum.title="Starred";starredAlbum.sysdate=e.starredNum+" photos";starredAlbum.star=1;if(e.starredThumb0)starredAlbum.thumb0=lychee.upload_path+e.starredThumb0;else starredAlbum.thumb0="";if(e.starredThumb1)starredAlbum.thumb1=lychee.upload_path+e.starredThumb1;else starredAlbum.thumb1="";if(e.starredThumb2)starredAlbum.thumb2=lychee.upload_path+e.starredThumb2;else starredAlbum.thumb2="";publicAlbum=new Object;publicAlbum.id="s";publicAlbum.title="Public";publicAlbum.sysdate=e.publicNum+" photos";publicAlbum.public=1;if(e.publicThumb0)publicAlbum.thumb0=lychee.upload_path+e.publicThumb0;else publicAlbum.thumb0="";if(e.publicThumb1)publicAlbum.thumb1=lychee.upload_path+e.publicThumb1;else publicAlbum.thumb1="";if(e.publicThumb2)publicAlbum.thumb2=lychee.upload_path+e.publicThumb2;else publicAlbum.thumb2="";if(lychee.publicMode)smartData="";else smartData=build.divider("Smart Albums")+build.album(unsortedAlbum)+build.album(starredAlbum)+build.album(publicAlbum);if(e.albums){albumsData=build.divider("Albums");$.each(e.album,function(){albumsData+=build.album(this)})}else albumsData="";if(smartData==""&&albumsData=="")$("body").append(build.no_content("picture"));else{lychee.content.html(smartData+albumsData);lychee.animate(".album, .photo","contentZoomIn")}document.title="Lychee";lychee.headerTitle.html("Albums").removeClass("editable");$("img").retina()})})},loadInfo:function(e,t){if(e=="f"||e=="s"||e==0){lychee.headerTitle.removeClass("editable");$("#button_edit_album, #button_trash_album, #button_share_album").hide();lychee.api("getSmartInfo","json",function(t){switch(e){case"f":document.title="Lychee - Starred";lychee.headerTitle.html("Starred - "+t.starredNum+" photos");break;case"s":document.title="Lychee - Public";lychee.headerTitle.html("Public - "+t.publicNum+" photos");break;case"0":document.title="Lychee - Unsorted";lychee.headerTitle.html("Unsorted - "+t.unsortNum+" photos");$("#button_trash_album").show();break}})}else{t="";$("#button_edit_album, #button_trash_album, #button_share_album, .button_divider").show();params="getAlbumInfo&albumID="+e+"&password="+t;lychee.api(params,"json",function(e){if(!e.title)e.title="Untitled";document.title="Lychee - "+e.title;lychee.headerTitle.html(e.title+" - "+e.num+" photos").addClass("editable");if(e.public=="1"){$("#button_share_album a").addClass("active");$("#button_share_album").attr("title","Share Album")}else{$("#button_share_album a").removeClass("active");$("#button_share_album").attr("title","Make Public")}})}},add:function(){title=prompt("Please enter a title for this album:","Untitled");lychee.closeModal();if(title.length>0&&title.length<31){params="addAlbum&title="+escape(title);lychee.api(params,"text",function(e){if(e)lychee.goto("a"+e);else loadingBar.show("error")})}else if(title.length>0)loadingBar.show("error","Error","Title to short or too long. Please try another one!")},hide:function(e){$(".album[data-id='"+e+"']").css("opacity",0).animate({width:0,marginLeft:0},300,function(){$(this).remove()})},"delete":function(e,t){params="deleteAlbum&albumID="+e+"&delAll="+t;lychee.api(params,"text",function(t){if(t){if(visible.albums())albums.hide(e);else lychee.goto("")}else loadingBar.show("error")})},deleteDialog:function(e){if(e==0){f1="albums.delete(0, true);";f2="";modal=build.modal("Clear Unsorted","Are you sure you want to delete all photos from 'Unsorted'?
This action can't be undone!",["Clear Unsorted","Keep Photos"],[f1,f2]);$("body").append(modal)}else{if(visible.albums())albumTitle=$(".album[data-id='"+e+"'] .overlay h1").html();else albumTitle=lychee.title();f1="albums.delete("+e+", true);";f2="albums.delete("+e+", false);";modal=build.modal("Delete Album","Are you sure you want to delete the album '"+albumTitle+"' and all of the photos it contains? This action can't be undone!",["Delete Album and Photos","Keep Photos"],[f1,f2]);$("body").append(modal)}},setTitle:function(e){if(!e)oldTitle=lychee.title();else oldTitle="";if(!e)e=lychee.content.attr("data-id");newTitle=prompt("Please enter a new title for this album:",oldTitle);if(e!=""&&e!=null&&e&&newTitle.length>0&&newTitle.length<31){params="setAlbumTitle&albumID="+e+"&title="+encodeURI(newTitle);lychee.api(params,"text",function(t){if(t){if(visible.albums())$(".album[data-id='"+e+"'] .overlay h1").html(newTitle);else{lychee.headerTitle.html(newTitle+""+$("#title span").html()+"");document.title="Lychee - "+newTitle}}else loadingBar.show("error")})}else if(newTitle.length>0)loadingBar.show("error","Error","New title to short or too long. Please try another one!")},setPublic:function(e){albumID=lychee.content.attr("data-id");params="setAlbumPublic&albumID="+albumID;lychee.api(params,"text",function(t){if(t){if($("#button_share_album a.active").length){$("#button_share_album a").removeClass("active");$("#button_share_album").attr("title","Make Public")}else{$("#button_share_album a").addClass("active");$("#button_share_album").attr("title","Share Album");contextMenu.share_album(albumID,e.pageX,e.pageY)}}else loadingBar.show("error")})},setPassword:function(e,t){if(!e)e=lychee.content.attr("data-id");if(!t)t=prompt("Please enter a password for this album:","");if(t!="")t=hex_md5(t);params="setAlbumPassword&albumID="+e+"&password="+t;lychee.api(params,"text",function(e){if(!e)loadingBar.show("error")})},share:function(e,t){link="";url=location.href;switch(e){case 0:link="https://twitter.com/share?url="+encodeURI(url);break;case 1:link="http://www.facebook.com/sharer.php?u="+encodeURI(url)+"&t="+encodeURI(lychee.title());break;case 2:link="mailto:?subject="+encodeURI(lychee.title())+"&body="+encodeURI("Hi! Check this out: "+url);break;case 3:modal=build.modal("Copy Link","Everyone can view your public albums, but only you can edit them. Use this link to share your album with others: ",["Close"],[""]);$("body").append(modal);$(".copylink").focus();break;default:link="";break}if(link.length>5)location.href=link},getArchive:function(){albumID=lychee.content.attr("data-id");if(location.href.indexOf("index.html")>0)link=location.href.replace(location.hash,"").replace("index.html","php/api.php?function=getAlbumArchive&albumID="+albumID);else link=location.href.replace(location.hash,"")+"php/api.php?function=getAlbumArchive&albumID="+albumID;location.href=link}};build={divider:function(e){return"

"+e+"

"},album:function(e){var t="";if(!e)return"";if(e.password&&lychee.publicMode){e.thumb0="img/password.png";e.thumb1="img/password.png";e.thumb2="img/password.png"}else{if(!e.thumb0)e.thumb0="img/no_images.png";if(!e.thumb1)e.thumb1="img/no_images.png";if(!e.thumb2)e.thumb2="img/no_images.png"}if(!e.title)e.title="Untitled";if(e.title.length>18)e.title=e.title.substr(0,18)+"...";t+="
";t+="thumb";t+="thumb";t+="thumb";t+="
";if(e.password&&!lychee.publicMode)t+="

"+e.title+"

";else t+="

"+e.title+"

";t+=""+e.sysdate+"";t+="
";if(!lychee.publicMode&&e.star=="1")t+="";if(!lychee.publicMode&&e.public=="1")t+="";if(!lychee.publicMode&&e.unsorted=="1")t+="";t+="
";return t},photo:function(e){var t="";if(e=="")return"";if(!e.title)e.title="";if(!e.thumbUrl)e.thumbUrl="img/no_image.png";if(e.title.length>18)e.title=e.title.substr(0,18)+"...";t+="
";t+="thumb";t+="
";t+="

"+e.title+"

";t+=""+e.sysdate+"";t+="
";if(e.star=="1")t+="";if(!lychee.publicMode&&e.public=="1")t+="";t+="
";return t},no_content:function(e){var t="";t+="
";t+="";if(e=="search")t+="

No results

";else if(e=="picture")t+="

No public albums

";t+="
";return t},modal:function(e,t,n,r){var i="";i+="
";i+="
";i+="

"+e+"

";i+="";i+="

"+t+"

";$.each(n,function(e){if(e==0)i+=""+this+"";else i+=""+this+""});i+="
";i+="";i+="
";return i},addModal:function(){var e="";e+="
";e+="
";e+="

Add Album or Photo

";e+="";e+="
";e+="
";e+="New Album";e+="
";e+="";e+="
";e+="
";e+="Upload Photo";e+="
";e+="
";e+="
";return e},signInModal:function(){var e="";e+="
";e+="
";e+="

Sign In

";e+="";e+="
Version "+lychee.version+"Update available!
";e+="Sign in";e+="
";e+="
";return e},uploadModal:function(){var e="";e+="
";e+="
";e+="";e+="
";e+="
";e+="
";return e},contextMenu:function(e){var t="";t+="
";t+="
";t+="";t+="";$.each(e,function(n){if(e[n][0]=="separator"&&e[n][1].length==0)t+="";else if(e[n][1].length!=0)t+=""});t+="";t+="
"+e[n][0]+"
";t+="
";return t},infobox:function(e,t){var n="";n+="

About

";n+="
";if(e.public==1)e.public="Public";else e.public="Private";if(t==true||lychee.publicMode)editTitleHTML="";else editTitleHTML="
";if(t==true||lychee.publicMode)editDescriptionHTML="";else editDescriptionHTML="
";infos=[["","Basics"],["Name",e.title+editTitleHTML],["Uploaded",e.sysdate],["Description",e.description+editDescriptionHTML],["","Image"],["Size",e.size],["Format",e.type],["Resolution",e.width+" x "+e.height],["","Camera"],["Captured",e.takedate],["Make",e.make],["Type/Model",e.model],["Shutter Speed",e.shutter],["Aperture",e.aperture],["Focal Length",e.focal],["ISO",e.iso],["","Share"],["Visibility",e.public],["Short Link",e.shortlink]];$.each(infos,function(e){if(infos[e][1]==""||infos[e][1]==undefined||infos[e][1]==null)infos[e][1]="-";if(infos[e][0]==""){n+="";n+="

"+infos[e][1]+"

";n+=""}else{n+="";n+="";n+="";n+=""}});n+="
"+infos[e][0]+""+infos[e][1]+"
";n+="
";n+="
";return n}};contextMenu={album:function(e){e.preventDefault();mouse_x=e.pageX;mouse_y=e.pageY;albumID=$(this).attr("data-id");if(albumID=="0"||albumID=="f"||albumID=="s")return false;mouse_y-=$(document).scrollTop();items=[["Rename","albums.setTitle("+albumID+")"],["Delete","albums.deleteDialog("+albumID+")"]];contextMenu.close();$("body").css("overflow","hidden");$(".album[data-id='"+albumID+"']").addClass("active");$("body").append(build.contextMenu(items));$(".contextmenu").css({top:mouse_y,left:mouse_x})},photo:function(e){e.preventDefault();mouse_x=e.pageX;mouse_y=e.pageY;photoID=$(this).attr("data-id");mouse_y-=$(document).scrollTop();items=[["Rename","photos.setTitle("+photoID+")"],["Move to Album","contextMenu.move("+photoID+", "+(mouse_x+150)+", "+(mouse_y+$(document).scrollTop())+")"],["Delete","photos.deleteDialog("+photoID+")"]];contextMenu.close();$("body").css("overflow","hidden");$(".photo[data-id='"+photoID+"']").addClass("active");$("body").append(build.contextMenu(items));$(".contextmenu").css({top:mouse_y,left:mouse_x})},move:function(e,t,n){n-=$(document).scrollTop();if(!t||!n){t="10px";n="10px"}lychee.api("getAlbums","json",function(r){if(lychee.content.attr("data-id")==0){items=[]}else{items=[["Unsorted","photos.setAlbum("+e+", 0)"]]}if(!r.albums){items=[["New Album","albums.add()"]]}else{$.each(r.album,function(t){if(this.id!=lychee.content.attr("data-id")){if(!this.title)this.title="Untitled";items[items.length]=new Array(this.title,"photos.setAlbum("+e+", "+this.id+")")}else{items[items.length]=new Array("","")}})}contextMenu.close();$("body").css("overflow","hidden");$(".photo[data-id='"+e+"']").addClass("active");$("body").append(build.contextMenu(items));$(".contextmenu").css({top:n,left:t-$(".contextmenu").width()})})},share:function(e,t,n){n-=$(document).scrollTop();if(!t||!n){t="10px";n="10px"}items=[[" Make Private","photos.setPublic()"],["separator",""],[" Twitter","photos.share(0, "+e+")"],[" Facebook","photos.share(1, "+e+")"],[" Mail","photos.share(2, "+e+")"],[" Copy Link","photos.share(3, "+e+")"]];if(lychee.bitlyUsername!="")items.push([" Copy Shortlink","photos.share(4, "+e+")"]);contextMenu.close();$("body").css("overflow","hidden").append(build.contextMenu(items));$(".photo[data-id='"+e+"']").addClass("active");$(".contextmenu").css({top:n,left:t})},share_album:function(e,t,n){n-=$(document).scrollTop();if(!t||!n){t="10px";n="10px"}items=[[" Make Private","albums.setPublic()"],["separator",""],[" Twitter","albums.share(0, "+e+")"],[" Facebook","albums.share(1, "+e+")"],[" Mail","albums.share(2, "+e+")"],[" Copy Link","albums.share(3, "+e+")"]];contextMenu.close();$("body").css("overflow","hidden").append(build.contextMenu(items));$(".contextmenu").css({top:n,left:t})},close:function(){$(".contextmenu_bg, .contextmenu").remove();$(".photo.active, .album.active").removeClass("active");$("body").css("overflow","scroll")}};loadingBar={status:null,show:function(e,t,n){clearTimeout(lychee.loadingBar.data("timeout"));if(e=="error"&&loadingBar.status!="error"){loadingBar.status="error";if(!t)t="Error";if(!n)n="Whoops, it looks like something went wrong. Please reload the site and try again!";lychee.loadingBar.removeClass("loading uploading error").addClass(e).html("

"+t+": "+n+"

").show().css("height","40px");if(visible.controls())lychee.header.css("margin-Top","40px");lychee.loadingBar.data("timeout",setTimeout(function(){loadingBar.hide(true)},3e3))}else if(loadingBar.status==null){loadingBar.status="loading";lychee.loadingBar.data("timeout",setTimeout(function(){lychee.loadingBar.show().removeClass("loading uploading error").addClass("loading");if(visible.controls())lychee.header.css("margin-Top","3px")},1e3))}},hide:function(e){if(loadingBar.status!="error"&&loadingBar.status!=null||e){loadingBar.status=null;clearTimeout(lychee.loadingBar.data("timeout"));lychee.loadingBar.html("").css("height","3px");if(visible.controls())lychee.header.css("marginTop","0px");$.timer(300,function(){lychee.loadingBar.hide()})}}};lychee={init:function(e,t){this.version="1.2";this.api_path=e;this.upload_path=t;this.update_path="http://lychee.electerious.com/version/index.php";this.updateURL="https://github.com/electerious/Lychee";this.publicMode=false;this.checkForUpdates=false;this.bitlyUsername="";this.loadingBar=$("#loading");this.header=$("header");this.headerTitle=$("#title");this.content=$("#content");this.image_view=$("#image_view");this.infobox=$("#infobox")},ready:function(){if(!mobileBrowser())$(".tools").tipsy({gravity:"n"});if(window.webkitNotifications)window.webkitNotifications.requestPermission();lychee.api("init","json",function(e){lychee.checkForUpdates=e.config.checkForUpdates;lychee.bitlyUsername=e.config.bitlyUsername;if(!e.loggedIn)lychee.setPublicMode();$(window).bind("popstate",lychee.load);lychee.load()})},setPublicMode:function(){this.publicMode=true;$("#button_signout, #search, #button_trash_album, #button_share_album, #button_edit_album, .button_add, #button_archive, .button_divider").remove();$("#button_trash, #button_move, #button_edit, #button_share, #button_star").remove();$(document).on("mouseenter","#title.editable",function(){$(this).removeClass("editable")}).off(event_name,"#title.editable").off("contextmenu",".photo").off("contextmenu",".album").off("drop");$("#button_signin").show()},api:function(e,t,n,r){if(r==undefined)loadingBar.show();$.ajax({type:"POST",url:lychee.api_path,data:"function="+e,dataType:t,success:function(e){$.timer(100,function(){loadingBar.hide()});n(e)},error:lychee.error})},showLogin:function(){$("body").append(build.signInModal());$("#username").focus();if(localStorage){local_username=localStorage.getItem("username");if(local_username==null)return false;if(local_username.length>0)$("#username").val(local_username);$("#password").focus()}if(lychee.checkForUpdates)lychee.update()},login:function(){user=$("input#username").val();password=hex_md5($("input#password").val());params="login&user="+user+"&password="+password;lychee.api(params,"text",function(e){if(e){localStorage.setItem("username",user);window.location.reload()}else{$("#password").val("").addClass("error");$(".message .button.active").removeClass("pressed")}})},logout:function(){lychee.api("logout","text",function(e){window.location.reload()})},update:function(){$.ajax({url:lychee.update_path,success:function(e){if(e!=lychee.version)$("#version span").show()}})},upload:function(e){pre_progress=0;$(".upload_overlay").remove();$("body").append(build.uploadModal());var t=new FormData;for(var n=0;npre_progress){$(".progressbar div").css("width",t+"%");pre_progress=t}if(t>=100)$(".progressbar div").css("opacity",.2)}};$("#upload_files").val("");r.send(t)},importUrl:function(){link=prompt("Please enter the direct link to a photo to import it:","");if(lychee.content.attr("data-id")=="")albumID=0;else albumID=lychee.content.attr("data-id");lychee.closeModal();if(link.length>3){params="importUrl&url="+escape(link)+"&albumID="+albumID;lychee.api(params,"text",function(e){if(e){if(lychee.content.attr("data-id")=="")lychee.goto("a0");else photos.load(lychee.content.attr("data-id"))}else loadingBar.show("error")})}else if(link.length>0)loadingBar.show("error","Error","Link to short or too long. Please try another one!")},load:function(){contextMenu.close();hash=document.location.hash.replace("#","");albumID="";photoID="";if(hash.indexOf("a")!=-1)albumID=hash.split("p")[0].replace("a","");else albumID="";if(hash.indexOf("p")!=-1)photoID=hash.split("p")[1];else photoID="";lychee.content.attr("data-id",albumID);lychee.image_view.attr("data-id",photoID);if(albumID&&photoID){if(lychee.content.html()==""||$("#search").length&&$("#search").val().length!=0){lychee.content.hide();photos.load(albumID,true)}photos.loadInfo(photoID,albumID)}else if(albumID){if(visible.infobox)photos.hideInfobox();if(!visible.controls())lychee.showControls();if(visible.imageview())photos.hideView();else photos.load(albumID,false)}else{if(visible.infobox)photos.hideInfobox();if(!visible.controls())lychee.showControls();if(visible.imageview())photos.hideView();albums.load()}},"goto":function(e){document.location.hash=e},title:function(){return lychee.headerTitle.html().replace($("#title span").html(),"").replace("","")},showControls:function(){clearTimeout($(window).data("timeout"));if(visible.imageview()){lychee.image_view.removeClass("full");lychee.loadingBar.css("opacity",1);lychee.header.css("margin-Top","0px");if($("#image_view #image.small").length>0){$("#image_view #image").css({marginTop:-1*($("#image_view #image").height()/2)+20})}else{$("#image_view #image").css({top:70,right:30,bottom:30,left:30})}}},hideControls:function(){if(visible.imageview()&&!visible.infobox()){clearTimeout($(window).data("timeout"));$(window).data("timeout",setTimeout(function(){lychee.image_view.addClass("full");lychee.loadingBar.css("opacity",0);lychee.header.css("margin-Top","-45px");if($("#image_view #image.small").length>0){$("#image_view #image").css({marginTop:-1*($("#image_view #image").height()/2)})}else{$("#image_view #image").css({top:0,right:0,bottom:0,left:0})}},500))}},closeModal:function(){$(".message_overlay").removeClass("fadeIn").css("opacity",0);$.timer(300,function(){$(".message_overlay").remove()})},animate:function(e,t){animations=[["fadeIn","fadeOut"],["contentZoomIn","contentZoomOut"]];if(!e.jQuery)e=$(e);for(i=0;i300)waitTime=0;else if(t)waitTime=0;else waitTime=300-durationTime;$.timer(waitTime,function(){photosData="";$.each(n,function(){photosData+=build.photo(this)});lychee.content.html(photosData);if(!t){lychee.animate(".album, .photo","contentZoomIn");$("#tools_albums, #tools_photo").hide();$("#tools_album").show();$("img").retina();albums.loadInfo(e,password)}},false)})},loadInfo:function(e,t){password="";photos.showView();params="getPhotoInfo&photoID="+e+"&password="+password;lychee.api(params,"json",function(n){if(n=="HTTP/1.1 403 Wrong password!"){localStorage.removeItem("album"+t);photos.loadInfo(e,t);return false}if(!n.title)n.title="Untitled";document.title="Lychee - "+n.title;lychee.headerTitle.html(n.title).addClass("editable");$("#button_star a").removeClass("icon-star-empty icon-star");if(n.star=="1"){$("#button_star a").addClass("icon-star");$("#button_star").attr("title","Unstar Photo")}else{$("#button_star a").addClass("icon-star-empty");$("#button_star").attr("title","Star Photo")}if(n.public=="1"){$("#button_share a").addClass("active");$("#button_share").attr("title","Share Photo")}else{$("#button_share a").removeClass("active");$("#button_share").attr("title","Make Public")}n.url=lychee.upload_path+n.url;if(visible.controls()&&photos.isSmall(n))lychee.image_view.html("
");else if(visible.controls())lychee.image_view.html("
");else if(photos.isSmall(n))lychee.image_view.html("
");else lychee.image_view.html("
");lychee.animate(image_view,"fadeIn");lychee.image_view.show();if(!visible.controls())lychee.hideControls();lychee.infobox.html(build.infobox(n)).show();$.timer(300,function(){lychee.content.show()})})},isSmall:function(e){size=[["width",false],["height",false]];if(e.width<$(window).width()-60)size["width"]=true;if(e.height<$(window).height()-100)size["height"]=true;if(size["width"]&&size["height"])return true;else return false},showView:function(){$("#tools_albums, #tools_album").hide();$("#tools_photo").show();$("body").css("overflow","hidden")},hideView:function(){$("#tools_photo, #tools_albums").hide();$("#tools_album").show();$("body").css("overflow","scroll");albums.loadInfo(lychee.content.attr("data-id"));lychee.animate(image_view,"fadeOut");$.timer(300,function(){lychee.image_view.hide()})},showInfobox:function(){if(!visible.infobox())$("body").append("
");lychee.infobox.css("right","0px")},hideInfobox:function(){$("#infobox_overlay").remove();lychee.infobox.css("right","-320px")},hide:function(e){$(".photo[data-id='"+e+"']").css("opacity",0).animate({width:0,marginLeft:0},300,function(){$(this).remove();if(!visible.imageview()){imgNum=parseInt($("#title span").html().replace("- ","").replace(" photos",""))-1;$("#title span").html(" - "+imgNum+" photos")}})},"delete":function(e){params="deletePhoto&photoID="+e;lychee.api(params,"text",function(t){if(t){photos.hide(e);lychee.goto("a"+lychee.content.attr("data-id"))}else loadingBar.show("error")})},deleteDialog:function(e){if(!e)e=lychee.image_view.attr("data-id");if(visible.imageview())photoTitle=lychee.title();else photoTitle=$(".photo[data-id='"+e+"'] .overlay h1").html();if(photoTitle=="")photoTitle="Untitled";f1="photos.delete("+e+");";f2="";modal=build.modal("Delete Photo","Are you sure you want to delete the photo '"+photoTitle+"'?
This action can't be undone!",["Delete Photo","Keep Photo"],[f1,f2]);$("body").append(modal)},setTitle:function(e){if(!e)oldTitle=lychee.title();else oldTitle="";if(!e)e=lychee.image_view.attr("data-id");newTitle=prompt("Please enter a new title for this photo:",oldTitle);if(e!=null&&e&&newTitle.length<31){if(newTitle=="")newTitle="Untitled";params="setPhotoTitle&photoID="+e+"&title="+encodeURI(newTitle);lychee.api(params,"text",function(t){if(t){if(visible.imageview()){$("#infobox .attr_name").html($("#infobox .attr_name").html().replace(lychee.title(),newTitle));lychee.headerTitle.html(newTitle);document.title="Lychee - "+newTitle}$(".photo[data-id='"+e+"'] .overlay h1").html(newTitle)}else loadingBar.show("error")})}else if(newTitle.length>0)loadingBar.show("error","Error","New title to short or too long. Please try another one!")},setAlbum:function(e,t){if(t>=0){params="setAlbum&photoID="+e+"&albumID="+t;lychee.api(params,"text",function(t){if(t){photos.hide(e);lychee.goto("a"+lychee.content.attr("data-id"))}else loadingBar.show("error")})}},setStar:function(){photoID=lychee.image_view.attr("data-id");params="setPhotoStar&photoID="+photoID;lychee.api(params,"text",function(e){if(e){if($("#button_star a.icon-star-empty").length){$("#button_star a").removeClass("icon-star-empty icon-star").addClass("icon-star");$("#button_star").attr("title","Unstar Photo")}else{$("#button_star a").removeClass("icon-star-empty icon-star").addClass("icon-star-empty");$("#button_star").attr("title","Star Photo")}photos.load(lychee.content.attr("data-id"),true)}else loadingBar.show("error")})},setPublic:function(e){photoID=lychee.image_view.attr("data-id");params="setPhotoPublic&photoID="+photoID+"&url="+photos.getViewLink(photoID);lychee.api(params,"text",function(t){if(t){if($("#button_share a.active").length){$("#button_share a").removeClass("active");$("#button_share").attr("title","Make Public");$("#infobox .attr_visibility").html("Private")}else{$("#button_share a").addClass("active");$("#button_share").attr("title","Share Photo");$("#infobox .attr_visibility").html("Public");contextMenu.share(photoID,e.pageX,e.pageY)}photos.load(lychee.content.attr("data-id"),true)}else loadingBar.show("error")})},setDescription:function(){description=prompt("Please enter a description for this photo:","");photoID=lychee.image_view.attr("data-id");if(description.length>0&&description.length<160){params="setPhotoDescription&photoID="+photoID+"&description="+escape(description);lychee.api(params,"text",function(e){if(e){$("#infobox .attr_description").html(description+"
")}else loadingBar.show("error")})}else if(description.length>0)loadingBar.show("error","Error","Description to short or too long. Please try another one!")},share:function(e,t){link="";url=photos.getViewLink(t);switch(e){case 0:link="https://twitter.com/share?url="+encodeURI(url);break;case 1:link="http://www.facebook.com/sharer.php?u="+encodeURI(url)+"&t="+encodeURI(lychee.title());break;case 2:link="mailto:?subject="+encodeURI(lychee.title())+"&body="+encodeURI("Hi! Check this out: "+url);break;case 3:modal=build.modal("Copy Link","Everyone can view your public photos, but only you can edit them. Use this link to share your photo with others: ",["Close"],[""]);$("body").append(modal);$(".copylink").focus();break;case 4:params="getShortlink&photoID="+t;lychee.api(params,"text",function(e){if(e=="")e="Something went wrong!";modal=build.modal("Copy Shortlink","Everyone can view your public photos, but only you can edit them. Use this link to share your photo with others: ",["Close"],[""]);$("body").append(modal);$(".copylink").focus()});break;default:link="";break}if(link.length>5)location.href=link},getViewLink:function(e){if(location.href.indexOf("index.html")>0)return location.href.replace("index.html"+location.hash,"view.php?p="+e);else return location.href.replace(location.hash,"view.php?p="+e)},previous:function(){albumID=lychee.content.attr("data-id");photoID=lychee.image_view.attr("data-id");params="previousPhoto&photoID="+photoID+"&albumID="+albumID;lychee.api(params,"json",function(e){if(e!=false)lychee.goto("a"+albumID+"p"+e.id)})},next:function(){albumID=lychee.content.attr("data-id");photoID=lychee.image_view.attr("data-id");params="nextPhoto&photoID="+photoID+"&albumID="+albumID;lychee.api(params,"json",function(e){if(e)lychee.goto("a"+albumID+"p"+e.id)})}};search={find:function(e){clearTimeout($(window).data("timeout"));$(window).data("timeout",setTimeout(function(){if($("#search").val().length!=0){params="search&term="+e;lychee.api(params,"json",function(e){albumsData="";if(e&&e.albums)$.each(e.albums,function(){albumsData+=build.album(this)});photosData="";if(e&&e.photos)$.each(e.photos,function(){photosData+=build.photo(this)});if(albumsData==""&&photosData=="")code="error";else if(albumsData=="")code=build.divider("Photos")+photosData;else if(photosData=="")code=build.divider("Albums")+albumsData;else code=build.divider("Photos")+photosData+build.divider("Albums")+albumsData;if(lychee.content.attr("data-search")!=code){$(".no_content").remove();lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut");$.timer(300,function(){lychee.content.attr("data-search",code);if(code=="error")$("body").append(build.no_content("search"));else{lychee.content.html(code);lychee.animate(".album, .photo","contentZoomIn")}})}})}else search.reset()},250))},reset:function(){$("#search").val("");$(".no_content").remove();if(lychee.content.attr("data-search")!=""){lychee.content.attr("data-search","");lychee.animate(".divider","fadeOut");albums.load()}}};visible={albums:function(){if($("#tools_albums").css("display")=="block")return true;else return false},imageview:function(){if($("#image_view.fadeIn").length>0)return true;else return false},infobox:function(){if(parseInt(lychee.infobox.css("right").replace("px",""))==-320)return false;else return true},controls:function(){if(lychee.loadingBar.css("opacity")>0)return true;else return false}}