/**
* @author Philipp Maurer
* @author Tobias Reich
* @copyright 2013 by Philipp Maurer, Tobias Reich
*/
album={json:null,getID:function(){var e;if(photo.json)e=photo.json.album;else if(album.json)e=album.json.id;else e=$(".album:hover, .album.active").attr("data-id");if(!e)e=$(".photo:hover, .photo.active").attr("data-album-id");if(e)return e;else return false},load:function(e,t){var n,r,i,s,o="";password.get(e,function(){if(!t){loadingBar.show();lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut")}n=(new Date).getTime();r="getAlbum&albumID="+e+"&password="+password.value;lychee.api(r,"json",function(r){if(r=="HTTP/1.1 403 Album private!"){lychee.setMode("view");return false}if(r=="HTTP/1.1 403 Wrong password!"){album.load(e,t);return false}album.json=r;i=(new Date).getTime()-n;if(i>300)s=0;else if(t)s=0;else s=300-i;if(!visible.albums()&&!visible.photo()&&!visible.album())s=0;$.timer(s,function(){view.album.init();if(!t){lychee.animate(".album, .photo","contentZoomIn");view.header.mode("album")}},false)})})},parse:function(e){if(e&&e.thumbUrl)e.thumbUrl=lychee.upload_path_thumb+e.thumbUrl;else if(!album.json.title)album.json.title="Untitled"},add:function(){var e=prompt("Please enter a title for this album:","Untitled"),t;if(e.length>0&&e.length<31){modal.close();t="addAlbum&title="+escape(encodeURI(e));lychee.api(t,"text",function(e){if(e)lychee.goto("a"+e);else loadingBar.show("error")})}else if(e.length>0)loadingBar.show("error","Error","Title to short or too long. Please try another one!")},"delete":function(e){var t,n,r;n=[["Delete Album and Photos",function(){t="deleteAlbum&albumID="+e+"&delAll=true";lychee.api(t,"text",function(t){if(visible.albums())view.albums.content.delete(e);else lychee.goto("");if(!t)loadingBar.show("error")})}],["Keep Album",function(){}]];if(e==0){n[0][0]="Clear Unsorted";modal.show("Clear Unsorted","Are you sure you want to delete all photos from 'Unsorted'? This action can't be undone!",n)}else{if(album.json)r=album.json.title;else if(albums.json)r=albums.json.content[e].title;modal.show("Delete Album","Are you sure you want to delete the album '"+r+"' and all of the photos it contains? This action can't be undone!",n)}},setTitle:function(e){var t="",n,r;if(!e)e=album.getID();if(album.json)t=album.json.title;else if(albums.json)t=albums.json.content[e].title;n=prompt("Please enter a new title for this album:",t);if(e!=""&&e!=null&&e&&n.length>0&&n.length<31){if(visible.album()){album.json.title=n;view.album.title()}else if(visible.albums()){albums.json.content[e].title=n;view.albums.content.title(e)}r="setAlbumTitle&albumID="+e+"&title="+escape(encodeURI(n));lychee.api(r,"text",function(e){if(!e)loadingBar.show("error")})}else if(n.length>0)loadingBar.show("error","Error","New title to short or too long. Please try another one!")},setPublic:function(e,t){var n;if(visible.album()){album.json.public=album.json.public==0?1:0;album.json.password=album.json.public==false?true:false;view.album.public();if(album.json.public==1)contextMenu.shareAlbum(e,t)}n="setAlbumPublic&albumID="+e;lychee.api(n,"text",function(e){if(!e)loadingBar.show("error")})},share:function(e){var t="",n=location.href;switch(e){case 0:t="https://twitter.com/share?url="+encodeURI(n);break;case 1:t="http://www.facebook.com/sharer.php?u="+encodeURI(n)+"&t="+encodeURI(album.json.title);break;case 2:t="mailto:?subject="+encodeURI(album.json.title)+"&body="+encodeURI("Hi! Check this out: "+n);break;default:t="";break}if(t.length>5)location.href=t},getArchive:function(e){var t;if(location.href.indexOf("index.html")>0)t=location.href.replace(location.hash,"").replace("index.html","php/api.php?function=getAlbumArchive&albumID="+e);else t=location.href.replace(location.hash,"")+"php/api.php?function=getAlbumArchive&albumID="+e;location.href=t}};albums={json:null,load:function(){var e,t,n,r,i,s="",o="";lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut");e=(new Date).getTime();lychee.api("getAlbums","json",function(n){n.unsortedAlbum={id:0,title:"Unsorted",sysdate:n.unsortedNum+" photos",unsorted:1,thumb0:n.unsortedThumb0,thumb1:n.unsortedThumb1,thumb2:n.unsortedThumb2};n.starredAlbum={id:"f",title:"Starred",sysdate:n.starredNum+" photos",star:1,thumb0:n.starredThumb0,thumb1:n.starredThumb1,thumb2:n.starredThumb2};n.publicAlbum={id:"s",title:"Public",sysdate:n.publicNum+" photos","public":1,thumb0:n.publicThumb0,thumb1:n.publicThumb1,thumb2:n.publicThumb2};albums.json=n;t=(new Date).getTime()-e;if(t>300)waitTime=0;else waitTime=300-t;if(!visible.albums()&&!visible.photo()&&!visible.album())waitTime=0;$.timer(waitTime,function(){view.header.mode("albums");view.albums.init();lychee.animate(".album, .photo","contentZoomIn")})})},parse:function(e){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=lychee.upload_path_thumb+e.thumb0;else e.thumb0="img/no_images.png";if(e.thumb1)e.thumb1=lychee.upload_path_thumb+e.thumb1;else e.thumb1="img/no_images.png";if(e.thumb2)e.thumb2=lychee.upload_path_thumb+e.thumb2;else e.thumb2="img/no_images.png"}}};build={divider:function(e){return"
";o=[["","Basics"],["Name",e.title+i],["Uploaded",e.sysdate],["Description",e.description+s],["","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",r]];$.each(o,function(e){if(o[e][1]==""||o[e][1]==undefined||o[e][1]==null)o[e][1]="-";if(o[e][0]==""){n+="";n+="
"+o[e][1]+"
";n+="
"}else{n+="
";n+="
"+o[e][0]+"
";n+="
"+o[e][1]+"
";n+="
"}});n+="
";n+="";n+="
";return n}};contextMenu={fns:null,album:function(e){e.preventDefault();var t=e.pageX,n=e.pageY,r=album.getID(),i;if(r=="0"||r=="f"||r=="s")return false;n-=$(document).scrollTop();contextMenu.fns=[function(){album.setTitle(r)},function(){album.delete(r)}];i=[[" Rename",0],[" Delete",1]];contextMenu.close();$(".album[data-id='"+r+"']").addClass("active");$("body").css("overflow","hidden").append(build.contextMenu(i));$(".contextmenu").css({top:n,left:t})},photo:function(e){e.preventDefault();var t=e.pageX,n=e.pageY,r=photo.getID(),i;n-=$(document).scrollTop();contextMenu.fns=[function(){photo.setStar(r)},function(){photo.setTitle(r)},function(){contextMenu.move(r,e)},function(){photo.delete(r)}];i=[[" Star",0],["separator",-1],[" Rename",1],[" Move",2],[" Delete",3]];contextMenu.close();$(".photo[data-id='"+r+"']").addClass("active");$("body").css("overflow","hidden").append(build.contextMenu(i));$(".contextmenu").css({top:n,left:t})},move:function(e,t){var n=t.pageX,r=t.pageY,i=[],s;contextMenu.fns=[];r-=$(document).scrollTop();if(!n||!r){n="10px";r="10px"}if(album.getID()!=0){i=[["Unsorted",0,"photo.setAlbum(0, "+e+")"],["separator",-1]]}lychee.api("getAlbums","json",function(t){if(!t.albums){i=[["New Album",0,"album.add()"]]}else{$.each(t.content,function(t){if(this.id!=album.getID())i.push([this.title,0,"photo.setAlbum("+this.id+", "+e+")"])})}contextMenu.close();$(".photo[data-id='"+e+"']").addClass("active");$("body").css("overflow","hidden").append(build.contextMenu(i));if(!visible.photo())n+=$(".contextmenu").width();$(".contextmenu").css({top:r,left:n-$(".contextmenu").width()})})},sharePhoto:function(e,t){var n=t.pageX,r=t.pageY,i;r-=$(document).scrollTop();if(!n||!r){n="10px";r="10px"}contextMenu.fns=[function(){photo.setPublic(e)},function(){photo.share(e,0)},function(){photo.share(e,1)},function(){photo.share(e,2)},function(){photo.share(e,3)}];if(document.location.hostname!="localhost"){i=[["",-1],["separator",-1],[" Make Private",0],["separator",-1],[" Twitter",1],[" Facebook",2],[" Mail",3],[" Dropbox",4]]}else{i=[["",-1],["separator",-1],[" Make Private",0],["separator",-1],[" Mail",3]]}contextMenu.close();$("body").css("overflow","hidden").append(build.contextMenu(i));$(".contextmenu").css({top:r,left:n+20-$(".contextmenu").width()});$(".contextmenu input").focus()},shareAlbum:function(e,t){var n=t.pageX,r=t.pageY,i;r-=$(document).scrollTop();if(!n||!r){n="10px";r="10px"}contextMenu.fns=[function(){album.setPublic(e)},function(){password.set(e)},function(){album.share(0)},function(){album.share(1)},function(){album.share(2)},function(){password.remove(e)}];if(document.location.hostname!="localhost"){i=[["",-1],["separator",-1],[" Make Private",0],[" Set Password",1],["separator",-1],[" Twitter",2],[" Facebook",3],[" Mail",4]]}else{i=[["",-1],["separator",-1],[" Make Private",0],[" Set Password",1],["separator",-1],[" Mail",4]]}if(album.json.password==true)i[3]=[" Remove Password",5];contextMenu.close();$("body").css("overflow","hidden").append(build.contextMenu(i));$(".contextmenu").css({top:r,left:n+20-$(".contextmenu").width()});$(".contextmenu input").focus()},close:function(){contextMenu.js=null;$(".contextmenu_bg, .contextmenu").remove();$(".photo.active, .album.active").removeClass("active");$("body").css("overflow","scroll")}};loadingBar={status:null,show:function(e,t,n){if(e=="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");clearTimeout(lychee.loadingBar.data("timeout"));lychee.loadingBar.data("timeout",setTimeout(function(){loadingBar.hide(true)},3e3))}else if(loadingBar.status==null){loadingBar.status="loading";clearTimeout(lychee.loadingBar.data("timeout"));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()})}}};var lychee={init:function(){this.version="1.3";this.api_path="php/api.php";this.update_path="http://lychee.electerious.com/version/index.php";this.updateURL="https://github.com/electerious/Lychee";this.upload_path_thumb="uploads/thumb/";this.upload_path_big="uploads/big/";this.publicMode=false;this.viewMode=false;this.checkForUpdates=false;this.dropbox=false;this.loadingBar=$("#loading");this.header=$("header");this.content=$("#content");this.imageview=$("#imageview");this.infobox=$("#infobox")},run:function(){lychee.api("init","json",function(e){lychee.checkForUpdates=e.config.checkForUpdates;if(!e.loggedIn)lychee.setMode("public");$(window).bind("popstate",lychee.load);lychee.load()})},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})},login:function(){var e=$("input#username").val(),t=hex_md5($("input#password").val()),n;n="login&user="+e+"&password="+t;lychee.api(n,"text",function(t){if(t){localStorage.setItem("username",e);window.location.reload()}else{$("#password").val("").addClass("error");$(".message .button.active").removeClass("pressed")}})},loginDialog:function(){$("body").append(build.signInModal());$("#username").focus();if(localStorage){local_username=localStorage.getItem("username");if(local_username!=null){if(local_username.length>0)$("#username").val(local_username);$("#password").focus()}}if(lychee.checkForUpdates)lychee.getUpdate()},logout:function(){lychee.api("logout","text",function(e){window.location.reload()})},"goto":function(e){if(e==undefined)e="";document.location.hash=e},load:function(){var e="",t="",n=document.location.hash.replace("#","");contextMenu.close();if(n.indexOf("a")!=-1)e=n.split("p")[0].replace("a","");if(n.indexOf("p")!=-1)t=n.split("p")[1];if(e&&t){albums.json=null;photo.json=null;if(lychee.content.html()==""||$("#search").length&&$("#search").val().length!=0){lychee.content.hide();album.load(e,true)}if(!visible.photo())view.photo.show();photo.load(t,e)}else if(e){albums.json=null;photo.json=null;if(visible.photo())view.photo.hide();if(album.json&&e==album.json.id)view.album.title();else album.load(e)}else{albums.json=null;album.json=null;photo.json=null;search.code="";if(visible.photo())view.photo.hide();albums.load()}},getUpdate:function(){$.ajax({url:lychee.update_path,success:function(e){if(e!=lychee.version)$("#version span").show()}})},setTitle:function(e,t,n){if(e=="Albums")document.title="Lychee";else document.title="Lychee - "+e;if(t)e+=" - "+t+" photos";if(n)$("#title").addClass("editable");else $("#title").removeClass("editable");$("#title").html(e)},setMode:function(e){$("#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("click","#title.editable").off("touchend","#title.editable").off("contextmenu",".photo").off("contextmenu",".album").off("drop");Mousetrap.unbind("n").unbind("u").unbind("s").unbind("backspace");if(e=="public"){$("#button_signin").show();lychee.publicMode=true}else if(e=="view"){Mousetrap.unbind("esc");$("#button_back, a#next, a#previous").remove();lychee.publicMode=true;lychee.viewMode=true}},animate:function(e,t){var n=[["fadeIn","fadeOut"],["contentZoomIn","contentZoomOut"]];if(!e.jQuery)e=$(e);for(var r=0;r",t)},get:function(e,t){var n=$("input.password").val(),r;if(!lychee.publicMode)t();else if(album.json&&album.json.password==false)t();else if(albums.json&&albums.json.content[e].password==false)t();else if(!albums.json&&!album.json){album.json={password:true};t("")}else if(n==undefined){password.getDialog(e,t)}else{r="checkAlbumAccess&albumID="+e+"&password="+hex_md5(n);lychee.api(r,"text",function(e){if(e){password.value=hex_md5(n);t()}else{lychee.goto("");loadingBar.show("error","Error","Access denied. Wrong password!")}})}},getDialog:function(e,t){var n;n=[["Enter",function(){password.get(e,t)}],["Cancel",lychee.goto]];modal.show(" Enter Password","This album is protected with a password. Enter the password below to view the photos of this album: ",n)},remove:function(e){var t;if(visible.album())album.json.password=false;t="setAlbumPassword&albumID="+e+"&password=";lychee.api(t,"text",function(e){if(!e)loadingBar.show("error")})}};photo={json:null,getID:function(){var e;if(photo.json)e=photo.json.id;else e=$(".photo:hover, .photo.active").attr("data-id");if(e)return e;else return false},load:function(e,t){var n,r;n="getPhoto&photoID="+e+"&albumID="+t+"&password="+password.value;lychee.api(n,"json",function(n){if(n=="HTTP/1.1 403 Wrong password!"){r=function(){if(password.value!="")photo.load(e,t);else setTimeout(r,250)};r();return false}photo.json=n;view.photo.init();lychee.imageview.show();$.timer(300,function(){lychee.content.show()})})},parse:function(){if(!photo.json.title)photo.json.title="Untitled";photo.json.url=lychee.upload_path_big+photo.json.url},add:{files:function(e){var t=0,n=new FormData,r=new XMLHttpRequest,i,s;$(".upload_overlay").remove();$("body").append(build.uploadModal());window.onbeforeunload=function(){return"Lychee is currently uploading!"};for(var o=0;ot){$(".progressbar div").css("width",s+"%");t=s}if(s>=100)$(".progressbar div").css("opacity",.2)}};$("#upload_files").val("");r.send(n)},url:function(e){var t=album.getID();if(!e)e=prompt("Please enter the direct link to a photo to import it:","");if(album.getID()=="")t=0;if(e&&e.length>3){modal.close();$(".upload_overlay").remove();$("body").append(build.uploadModal());$(".progressbar div").css({opacity:.2,width:"100%"});params="importUrl&url="+escape(e)+"&albumID="+t;lychee.api(params,"text",function(e){$(".upload_overlay").removeClass("fadeIn").css("opacity",0);$.timer(300,function(){$(".upload_overlay").remove()});if(e){if(album.getID()=="")lychee.goto("a0");else album.load(album.getID())}else loadingBar.show("error")})}else if(e.length>0)loadingBar.show("error","Error","Link to short or too long. Please try another one!")},dropbox:function(){lychee.loadDropbox(function(){Dropbox.choose({linkType:"direct",multiselect:false,success:function(e){photo.add.url(e[0].link)}})})}},"delete":function(e){var t,n,r;if(!e)e=photo.getID();if(visible.photo())r=photo.json.title;else r=album.json.content[e].title;if(r=="")r="Untitled";n=[["Delete Photo",function(){album.json.content[e]=null;view.album.content.delete(e);if(!visible.albums())lychee.goto("a"+album.getID());t="deletePhoto&photoID="+e;lychee.api(t,"text",function(e){if(!e)loadingBar.show("error")})}],["Keep Photo",function(){}]];modal.show("Delete Photo","Are you sure you want to delete the photo '"+r+"'? This action can't be undone!",n)},setTitle:function(e){var t="",n,r;if(!e)e=photo.getID();if(photo.json)t=photo.json.title;else if(album.json)t=album.json.content[e].title;n=prompt("Please enter a new title for this photo:",t);if(e!=null&&e&&n.length<31){if(visible.photo()){photo.json.title=n==""?"Untitled":n;view.photo.title(t)}album.json.content[e].title=n;view.album.content.title(e);r="setPhotoTitle&photoID="+e+"&title="+escape(encodeURI(n));lychee.api(r,"text",function(e){if(!e)loadingBar.show("error")})}else if(n.length>0)loadingBar.show("error","Error","New title to short or too long. Please try another one!")},setAlbum:function(e,t){var n;if(e>=0){if(visible.photo)lychee.goto("a"+album.getID());album.json.content[t]=null;view.album.content.delete(t);n="setAlbum&photoID="+t+"&albumID="+e;lychee.api(n,"text",function(e){if(!e)loadingBar.show("error")})}},setStar:function(e){var t;if(visible.photo()){photo.json.star=photo.json.star==0?1:0;view.photo.star()}album.json.content[e].star=album.json.content[e].star==0?1:0;view.album.content.star(e);t="setPhotoStar&photoID="+e;lychee.api(t,"text",function(e){if(!e)loadingBar.show("error")})},setPublic:function(e,t){var n;if(photo.json.public==2){modal.show("Public Album","This photo is located in a public album. To make this photo private or public, edit the visibility of the associated album.",[["Show Album",function(){lychee.goto("a"+photo.json.original_album)}],["Close",function(){}]]);return false}if(visible.photo()){photo.json.public=photo.json.public==0?1:0;view.photo.public();if(photo.json.public==1)contextMenu.sharePhoto(e,t)}album.json.content[e].public=album.json.content[e].public==0?1:0;view.album.content.public(e);n="setPhotoPublic&photoID="+e+"&url="+photo.getViewLink(e);lychee.api(n,"text",function(e){if(!e)loadingBar.show("error")})},setDescription:function(e){var t=photo.json.description,n=prompt("Please enter a description for this photo:",t),r;if(n.length>0&&n.length<160){if(visible.photo()){photo.json.description=n;view.photo.description(t)}r="setPhotoDescription&photoID="+e+"&description="+escape(n);lychee.api(r,"text",function(e){if(!e)loadingBar.show("error")})}else if(n.length>0)loadingBar.show("error","Error","Description to short or too long. Please try another one!")},share:function(e,t){var n="",r=photo.getViewLink(e),i,s="unknown";switch(t){case 0:n="https://twitter.com/share?url="+encodeURI(r);break;case 1:n="http://www.facebook.com/sharer.php?u="+encodeURI(r)+"&t="+encodeURI(photo.json.title);break;case 2:n="mailto:?subject="+encodeURI(photo.json.title)+"&body="+encodeURI(r);break;case 3:lychee.loadDropbox(function(){s=photo.json.title+"."+photo.getDirectLink().split(".").pop();Dropbox.save(photo.getDirectLink(),s)});break;default:n="";break}if(n.length>5)location.href=n},isSmall:function(){var e=[["width",false],["height",false]];if(photo.json.width<$(window).width()-60)e["width"]=true;if(photo.json.height<$(window).height()-100)e["height"]=true;if(e["width"]&&e["height"])return true;else return false},getDirectLink:function(){return $("#imageview #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig,"")},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)}};search={code:null,find:function(e){var t,n="",r="",i;clearTimeout($(window).data("timeout"));$(window).data("timeout",setTimeout(function(){if($("#search").val().length!=0){t="search&term="+e;lychee.api(t,"json",function(e){if(e&&e.albums){albums.json={content:e.albums};$.each(albums.json.content,function(){albums.parse(this);n+=build.album(this)})}if(e&&e.photos){album.json={content:e.photos};$.each(album.json.content,function(){album.parse(this);r+=build.photo(this)})}if(n==""&&r=="")i="error";else if(n=="")i=build.divider("Photos")+r;else if(r=="")i=build.divider("Albums")+n;else i=build.divider("Photos")+r+build.divider("Albums")+n;if(search.code!=hex_md5(i)){$(".no_content").remove();lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut");search.code=hex_md5(i);$.timer(300,function(){if(i=="error")$("body").append(build.no_content("search"));else{lychee.content.html(i);lychee.animate(".album, .photo","contentZoomIn")}})}})}else search.reset()},250))},reset:function(){$("#search").val("");$(".no_content").remove();if(search.code!=""){search.code="";lychee.animate(".divider","fadeOut");albums.load()}}};view={header:{show:function(){clearTimeout($(window).data("timeout"));if(visible.photo()){lychee.imageview.removeClass("full");lychee.loadingBar.css("opacity",1);lychee.header.css("margin-Top","0px");if($("#imageview #image.small").length>0){$("#imageview #image").css({marginTop:-1*($("#imageview #image").height()/2)+20})}else{$("#imageview #image").css({top:70,right:30,bottom:30,left:30})}}},hide:function(){if(visible.photo()&&!visible.infobox()){clearTimeout($(window).data("timeout"));$(window).data("timeout",setTimeout(function(){lychee.imageview.addClass("full");lychee.loadingBar.css("opacity",0);lychee.header.css("margin-Top","-45px");if($("#imageview #image.small").length>0){$("#imageview #image").css({marginTop:-1*($("#imageview #image").height()/2)})}else{$("#imageview #image").css({top:0,right:0,bottom:0,left:0})}},500))}},mode:function(e){var t;switch(e){case"albums":$("#tools_album, #tools_photo").hide();$("#tools_albums").show();break;case"album":$("#tools_albums, #tools_photo").hide();$("#tools_album").show();t=album.getID();if(t=="s"||t=="f")$("#button_edit_album, #button_trash_album, #button_share_album").hide();else if(t==0)$("#button_edit_album, #button_share_album").hide();else $("#button_edit_album, #button_trash_album, #button_share_album").show();break;case"photo":$("#tools_albums, #tools_album").hide();$("#tools_photo").show();break}}},albums:{init:function(){view.albums.title();view.albums.content.init()},title:function(){lychee.setTitle("Albums",null,false)},content:{init:function(){var e="",t="";albums.parse(albums.json.unsortedAlbum);albums.parse(albums.json.publicAlbum);albums.parse(albums.json.starredAlbum);if(!lychee.publicMode)e=build.divider("Smart Albums")+build.album(albums.json.unsortedAlbum)+build.album(albums.json.starredAlbum)+build.album(albums.json.publicAlbum);if(albums.json.content){if(!lychee.publicMode)t=build.divider("Albums");$.each(albums.json.content,function(){albums.parse(this);t+=build.album(this)})}if(e==""&&t=="")$("body").append(build.no_content("picture"));else lychee.content.html(e+t);$("img").retina()},title:function(e){var t="",n=albums.json.content[e].title;if(albums.json.content[e].password)t=" ";if(n.length>18)n=n.substr(0,18)+"...";$(".album[data-id='"+e+"'] .overlay h1").html(t+n)},"delete":function(e){$(".album[data-id='"+e+"']").css("opacity",0).animate({width:0,marginLeft:0},300,function(){$(this).remove()})}}},album:{init:function(){album.parse();view.album.title();view.album.public();view.album.content.init();album.json.init=1},title:function(){if((visible.album()||!album.json.init)&&!visible.photo()){switch(album.getID()){case"f":lychee.setTitle("Starred",album.json.num,false);break;case"s":lychee.setTitle("Public",album.json.num,false);break;case"0":lychee.setTitle("Unsorted",album.json.num,false);break;default:lychee.setTitle(album.json.title,album.json.num,true);break}}},content:{init:function(){var e="";$.each(album.json.content,function(){album.parse(this);e+=build.photo(this)});lychee.content.html(e);$("img").retina()},title:function(e){var t=album.json.content[e].title;if(t.length>18)t=t.substr(0,18)+"...";$(".photo[data-id='"+e+"'] .overlay h1").html(t)},star:function(e){$(".photo[data-id='"+e+"'] .icon-star").remove();if(album.json.content[e].star==1)$(".photo[data-id='"+e+"']").append("")},"public":function(e){$(".photo[data-id='"+e+"'] .icon-share").remove();if(album.json.content[e].public==1)$(".photo[data-id='"+e+"']").append("")},"delete":function(e){$(".photo[data-id='"+e+"']").css("opacity",0).animate({width:0,marginLeft:0},300,function(){$(this).remove();if(!visible.albums()){album.json.num--;view.album.title()}})}},"public":function(){if(album.json.public==1){$("#button_share_album a").addClass("active");$("#button_share_album").attr("title","Share Album");$(".photo .icon-share").remove()}else{$("#button_share_album a").removeClass("active");$("#button_share_album").attr("title","Make Public")}}},photo:{init:function(){photo.parse();view.photo.infobox();view.photo.title();view.photo.star();view.photo.public();view.photo.photo();photo.json.init=1},show:function(){view.header.mode("photo");$("body").css("overflow","hidden");lychee.animate(lychee.imageview,"fadeIn")},hide:function(){if(!visible.controls())view.header.show();if(visible.infobox)view.photo.hideInfobox();view.header.mode("album");$("body").css("overflow","scroll");lychee.animate(lychee.imageview,"fadeOut");$.timer(300,function(){lychee.imageview.hide()})},showInfobox:function(){if(!visible.infobox())$("body").append("");lychee.infobox.css("right","0px")},hideInfobox:function(){$("#infobox_overlay").remove();lychee.infobox.css("right","-320px")},title:function(e){if(photo.json.init)$("#infobox .attr_name").html($("#infobox .attr_name").html().replace(e,photo.json.title));lychee.setTitle(photo.json.title,null,true)},description:function(e){if(photo.json.init)$("#infobox .attr_description").html($("#infobox .attr_description").html().replace(e,photo.json.description))},star:function(){$("#button_star a").removeClass("icon-star-empty icon-star");if(photo.json.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")}},"public":function(){if(photo.json.public==1||photo.json.public==2){$("#button_share a").addClass("active");$("#button_share").attr("title","Share Photo");if(photo.json.init)$("#infobox .attr_visibility").html("Public")}else{$("#button_share a").removeClass("active");$("#button_share").attr("title","Make Public");if(photo.json.init)$("#infobox .attr_visibility").html("Private")}},photo:function(){if(visible.controls()&&photo.isSmall())lychee.imageview.html("");else if(visible.controls())lychee.imageview.html("");else if(photo.isSmall())lychee.imageview.html("");else lychee.imageview.html("");if(!photo.json.nextPhoto||lychee.viewMode)$("a#next").hide();if(!photo.json.previousPhoto||lychee.viewMode)$("a#previous").hide()},infobox:function(){lychee.infobox.html(build.infobox(photo.json)).show()}}};visible={albums:function(){if($("#tools_albums").css("display")=="block")return true;else return false},album:function(){if($("#tools_album").css("display")=="block")return true;else return false},photo:function(){if($("#imageview.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")<1)return false;else return true},message:function(){if($(".message").length>0)return true;else return false},contextMenu:function(){if($(".contextmenu").length>0)return true;else return false}}