function getPlaylistIndex(b){if(b==undefined){return 0}var a;jQuery.each(jsPlaylist.photos,function(c){if(this.id==b){a=c}});return a}function nextPhoto(b){var a=0;if(b!=undefined){a=getPlaylistIndex(b.id)}else{a=jsPlaylist.currentPlaylistIndex+1;if(a>=jsPlaylist.photos.length){a=0}}return jsPlaylist.photos[a]}function prevPhoto(b){var a=0;if(b!=undefined){a=getPlaylistIndex(b.id)}else{a=jsPlaylist.currentPlaylistIndex-1;if(a<0){a=jsPlaylist.photos.length-1}}return jsPlaylist.photos[a]}function currentPhoto(b){var a=jsPlaylist.currentPlaylistIndex;if(b!=undefined){a=getPlaylistIndex(b.id);urlPhotoId(b.id)}if(a==undefined){a=getPlaylistIndex(urlPhotoId())}jsPlaylist.currentPlaylistIndex=a;return jsPlaylist.photos[a]}function urlPhotoId(a){if(a==undefined){var b=document.location.href;if(b.match("#")&&b.split("#")[1].match("photoid=")){b=b.split("#")[1];if(b.match("&")){b=b.split("&")[0]}return b.split("=")[1]}}else{document.location=document.location.href.split("#")[0]+"#photoid="+a}}function initGallery(){if(typeof(jQuery.isArray)=="undefined"){jQuery.extend({isArray:function(a){return a.constructor==Array}})}displayViewport();displayPhoto(currentPhoto())}function displayViewport(){var f=jQuery("#cGallery .photoViewport");f.unbind();f.hover(function(){jQuery("#cGallery .photoAction").fadeIn("fast")},function(){jQuery("#cGallery .photoAction").fadeOut("fast")});var c=jQuery("#cGallery .photoDisplay");c.css("height",Math.floor(c.width()*0.8/16*12));var e=jQuery("#cGallery .photoLoad");e.css({top:Math.floor((c.height()/2)-(e.height()/2)),left:Math.floor((c.width()/2)-(e.width()/2))});var d=jQuery("#cGallery .photoActions");d.css({width:c.width(),height:0,top:0,left:0});var g=jQuery("#cGallery .photoAction._next");g.css({top:Math.floor((c.height()/2)-(g.height()/2)),right:0});var a=jQuery("#cGallery .photoAction._prev");a.css({top:Math.floor((c.height()/2)-(a.height()/2)),left:0});var b=jQuery("#cGallery .photoTags");b.css({width:c.width(),height:0,top:0,left:0})}function displayPhoto(b){var c=jQuery("#cGallery .photoLoad");c.show();currentPhoto(b);updatePhotoActionThumbnail();displayPhotoCaption(b.caption);var a=jQuery('<img class="photoImage"/>');a.load(function(){var e=jQuery("#cGallery .photoDisplay");var d=jQuery("#cGallery .photoImage");d.fadeOut("fast",function(){d.remove();e.empty();a.data("photo",b).attr("alt",b.caption).attr("title","").appendTo(e).css({top:Math.floor((e.height()-a[0].height)/2),left:Math.floor((e.width()-a[0].width)/2),visibility:"visible",display:"none"}).fadeIn("fast",function(){displayPhotoWalls(b.id);displayPhotoTags(b.tags)});c.hide()})}).attr("src",getResizedPhotoUrl(b));prefetchPhoto([prevPhoto(),nextPhoto()])}function prefetchPhoto(a){if(!jQuery.isArray(a)){a=[a]}jQuery.each(a,function(){jQuery(new Image()).load(function(){}).attr("src",getResizedPhotoUrl(this))})}function getResizedPhotoUrl(b){var a=jQuery("#cGallery .photoDisplay");return b.url+"&"+jQuery.param({maxW:a.width(),maxH:a.height()})}function updatePhotoActionThumbnail(){jQuery("#cGallery .photoAction._next img").attr("src",nextPhoto().thumbnail);jQuery("#cGallery .photoAction._prev img").attr("src",prevPhoto().thumbnail)}function displayPhotoCaption(a){var b=jQuery("#cGallery .photoCaptionText");b.text((a!="")?a:jsPlaylist.language.CC_NO_PHOTO_CAPTION_YET)}function editPhotoCaption(){var b=jQuery("#cGallery .photoCaption");b.addClass("editMode");var c=jQuery("#cGallery .photoCaptionText");var a=jQuery("#cGallery .photoCaptionInput");a.val(jQuery.trim(c.text()))}function cancelPhotoCaption(){var b=jQuery("#cGallery .photoCaption");b.removeClass("editMode");var a=jQuery("#cGallery .photoCaptionInput");a.val("")}function savePhotoCaption(){var d=jQuery("#cGallery .photoCaptionText");var b=jQuery("#cGallery .photoCaptionInput");var c=jQuery.trim(d.text());var a=jQuery.trim(b.val());if(a==""||a==c){cancelPhotoCaption()}else{jax.call("community","photos,ajaxSaveCaption",currentPhoto().id,a)}}function updatePhotoCaption(a,b){var c=jQuery("#cGallery .photoCaptionText");c.text(b);jsPlaylist.photos[getPlaylistIndex(a)].caption=b;cancelPhotoCaption()}function displayPhotoWalls(a){jax.call("community","photos,ajaxSwitchPhotoTrigger",a)}function setPhotoAsDefault(){if(confirm(jsPlaylist.language.CC_SET_PHOTO_AS_DEFAULT_DIALOG)){jax.call("community","photos,ajaxSetDefaultPhoto",jsPlaylist.album,currentPhoto().id)}}function removePhoto(){if(confirm(jsPlaylist.language.CC_REMOVE_PHOTO_DIALOG)){var c=jsPlaylist.photos;var b=currentPhoto();c.splice(getPlaylistIndex(b.id),1);var a=(jsPlaylist.photos.length<1)?1:0;jax.call("community","photos,ajaxRemovePhoto",b.id,a);if(!a){displayPhoto(nextPhoto())}}}function newPhotoTag(b){var a={id:null,userId:null,photoId:null,displayName:null,profileUrl:null,top:null,left:null,width:null,height:null,displayTop:null,displayLeft:null,displayWidth:null,displayHeight:null,"canRemove:":null};jQuery.extend(a,b);return a}function createPhotoTag(tag){var photo=jQuery("#cGallery .photoImage");var photoTags=jQuery("#cGallery .photoTags");if(typeof(tag)=="string"){tag=eval("("+tag+")")}var singleTag=false;if(!jQuery.isArray(tag)){tag=[tag];singleTag=true}var newPhotoTags=new Array();jQuery.each(tag,function(i,tag){var photoTag=drawPhotoTag(tag,photo);photoTag.data("tag",tag).attr("id","photoTag-"+tag.id).hover(function(){showPhotoTag(tag.id,"Label")},function(){hidePhotoTag(tag.id)}).appendTo(photoTags);var photoTagLabel=jQuery('<div class="photoTagLabel">');photoTagLabel.html(tag.displayName);photoTagLabel.wrapInner("<span></span>").appendTo(photoTag);newPhotoTags.push(photoTag)});if(singleTag){return newPhotoTags[0]}else{return newPhotoTags}}function drawPhotoTag(b,c){var a=(b.displayWidth!=b.width*c.width());if(a){b.displayWidth=b.width*c.width();b.displayHeight=b.height*c.height();b.displayTop=(b.top*c.height())-(b.displayHeight/2);if(b.displayTop<0){b.displayTop=0}maxTop=c.height()-b.displayHeight;if(b.displayTop>maxTop){b.displayTop=maxTop}b.displayLeft=(b.left*c.width())-(b.displayWidth/2);if(b.displayLeft<0){b.displayLeft=0}maxLeft=c.width()-b.displayWidth;if(b.displayLeft>maxLeft){b.displayLeft=maxLeft}}var d=jQuery('<div class="photoTag">');d.css({width:b.displayWidth,height:b.displayHeight,top:b.displayTop,left:b.displayLeft});var e=jQuery('<div class="photoTagBorder">');e.css({width:b.displayWidth-4,height:b.displayHeight-4,border:"2px solid #222"}).appendTo(d);if(b.id!=null){updatePlaylistTag(b)}return d}function updatePlaylistTag(a){var c;var b=jsPlaylist.photos[getPlaylistIndex(a.photoId)].tags;jQuery.each(b,function(){if(this.id==a.id){c=this}});if(c==undefined){c=b[b.push(newPhotoTag())-1]}jQuery.extend(c,a)}function displayPhotoTags(c){clearPhotoTag();clearPhotoTextTag();var b=jQuery("#cGallery .photoImage");var a=jQuery("#cGallery .photoTags");a.css({width:b.width(),height:b.height(),top:b.position().top,left:b.position().left});createPhotoTag(c);createPhotoTextTag(c)}function addPhotoTag(b){var a=jQuery("#cGallery .photoTag.new").data("tag");jax.call("community","photos,ajaxAddPhotoTag",a.photoId,b,a.top,a.left,a.width,a.height);cancelNewPhotoTag()}function removePhotoTag(a){jax.call("community","photos,ajaxRemovePhotoTag",a.photoId,a.userId);clearPhotoTag(a);clearPhotoTextTag(a);var b=jsPlaylist.photos[getPlaylistIndex(a.photoId)].tags;jQuery.each(b,function(c){if(this.id==a.id){b.splice(c,1)}})}function clearPhotoTag(a){if(a==undefined){jQuery("#cGallery .photoTag").remove()}else{jQuery("#photoTag-"+a.id).remove()}}function showPhotoTag(b,a){jQuery("#photoTag-"+b).addClass("show"+a)}function hidePhotoTag(a){jQuery("#photoTag-"+a).removeClass("show showLabel showForce")}function createPhotoTextTag(tags){var photoTextTags=jQuery("#cGallery .photoTextTags");if(typeof(tags)=="string"){tags=eval("("+tags+")")}var singleTag=false;if(!jQuery.isArray(tags)){tags=[tags];singleTag=true}var newPhotoTextTags=new Array();jQuery.each(tags,function(i,tag){if(tag.id==undefined){return}var photoTextTag=jQuery('<span class="photoTextTag"></span>');photoTextTag.data("tag",tag).attr("id","photoTextTag-"+tag.id).hover(function(){showPhotoTag(tag.id,"Force")},function(){hidePhotoTag(tag.id)}).appendTo(photoTextTags);var photoTextTagLink=jQuery("<a>");photoTextTagLink.attr("href",tag.profileUrl).html(tag.displayName).prependTo(photoTextTag);if(tag.canRemove){var photoTextTagActions=jQuery('<span class="photoTextTagActions"></span>');photoTextTagActions.appendTo(photoTextTag);var photoTextTagAction_remove=jQuery('<a class="photoTextTagAction" href="javascript: void(0);"></a>');photoTextTagAction_remove.addClass("_remove").html(jsPlaylist.language.CC_REMOVE).click(function(){removePhotoTag(tag)}).appendTo(photoTextTagActions);photoTextTagActions.before(" ").prepend("(").append(")")}newPhotoTextTags.push(photoTextTag)});commifyTextTags();return newPhotoTextTags}function commifyTextTags(){jQuery("#cGallery .photoTextTags .comma").remove();photoTextTag=jQuery("#cGallery .photoTextTag");photoTextTag.each(function(b){if(b==0){return}var a=jQuery('<span class="comma"></span>');a.html(", ").prependTo(this)})}function clearPhotoTextTag(a){if(a==undefined){jQuery("#cGallery .photoTextTag").remove()}else{jQuery("#photoTextTag-"+a.id).remove();commifyTextTags()}}function startTagMode(){jQuery("#cGallery .photoTagInstructions").slideDown("fast");var d=jQuery("#cGallery .photoViewport");d.addClass("tagMode");var c=jQuery("#cGallery .photoImage");var b=c;var a=jQuery("#cGallery .photoTags");a.click(function(h){jQuery(".photoTag.new").remove();var g=createPhotoTag(newPhotoTag({photoId:currentPhoto().id,top:(h.pageY-jQuery(this).offset().top)/c.height(),left:(h.pageX-jQuery(this).offset().left)/c.width(),width:jsPlaylist.config.defaultTagWidth/c.width(),height:jsPlaylist.config.defaultTagHeight/c.height()}));g.addClass("new");var f=jQuery("#cGallery .photoTagActions");f.css({top:g.position().top+g.outerHeight(true),left:g.position().left}).show();f.children("*").click(function(e){e.stopPropagation()})})}function stopTagMode(){cancelNewPhotoTag();var b=jQuery("#cGallery .photoViewport");b.removeClass("tagMode");var a=jQuery("#cGallery .photoTags");a.unbind("click");jQuery("#cGallery .photoTagInstructions").hide();cWindowHide()}function selectNewPhotoTagFriend(){cWindowShow("showPhotoTagFriends();",jsPlaylist.language.CC_SELECT_FRIEND,300,280);cWindowActions('<button class="button" onclick="confirmPhotoTagFriend();">'+jsPlaylist.language.CC_CONFIRM+"</button>")}function confirmPhotoTagFriend(){jQuery("#cWindow .js-system-message").hide();var a=jQuery("#cWindow .photoTagFriend input:checked");if(a.length>0){addPhotoTag(a.val())}else{jQuery("#cWindow .js-system-message").show();jQuery("#cWindow .js-system-message").fadeOut(5000)}}function showPhotoTagFriends(){jQuery("#cWindowContent").empty();var a=jQuery("#cGallery .photoTagFriend");if(a.length<1){jQuery("#cWindowContent").html(jsPlaylist.language.CC_PHOTO_TAG_NO_FRIEND);return}jQuery("#cGallery .photoTagSelectFriend").clone().appendTo("#cWindowContent");var b=new Array();jQuery.each(currentPhoto().tags,function(){b.push(this.userId)});filterPhotoTagFriend(b);setTimeout("jQuery('#cWindowContent .photoTagFriendFilter').focus()",300)}function filterPhotoTagFriend(b){var a=jQuery("#cWindow .photoTagFriend");var c=jQuery("#cWindow .photoTagFriendFilter");var d=jQuery.trim(c.val());if(b!=undefined){jQuery.each(b,function(f,e){a.filter(function(){return jQuery(this).attr("id")=="photoTagFriend-"+e}).addClass("tagged")});if(a.not(".tagged").length<1){jQuery("#cWindowContent").html(jsPlaylist.language.CC_PHOTO_TAG_ALL_TAGGED)}return}if(d==""){a.not(".tagged").removeClass("hide");return}a.not(".tagged").addClass("hide").filter(function(){return(this.textContent||this.innerText||"").toUpperCase().indexOf(d.toUpperCase())>=0}).removeClass("hide")}function cancelNewPhotoTag(){var a=jQuery(".photoTag.new");a.remove();var b=jQuery("#cGallery .photoTagActions");b.hide()};
