$(function()
{var albumURL="/photos/"+CP.Photos.collection+"/"+CP.Photos.album+"/";var photoPosition=1;var totalPhotos=$(".photo").length;loadCorrectPhoto();$(".newer").click(nextPhoto);$(".older").click(previousPhoto);$(document).keydown(keyPress);if(!$(".ie").length)
{$(".photo").swipe({preventDefaultEvents:false,swipeLeft:nextPhoto,swipeRight:previousPhoto,threshold:{x:100,y:75}});}
function getKeyCode(event)
{var keyCode=event.keyCode;if(!keyCode)
{keyCode=event.which;}
return keyCode;}
function isDocumentKeyPress(event)
{if($(event.target).closest("form").length==0&&!event.altKey&&!event.ctrlKey&&!event.metaKey&&!event.shiftKey)
{return true;}
return false;}
function keyPress(event)
{if(isDocumentKeyPress(event))
{switch(getKeyCode(event))
{case 37:previousPhoto(event);break;case 39:nextPhoto(event);break;}}}
function loadCorrectPhoto()
{var currentPhotoId=null;if(window.location.hash)
{currentPhotoId=window.location.hash.replace("#","");}
else if(Modernizr.history&&CP.Photos.photo)
{currentPhotoId=CP.Photos.photo;}
if(currentPhotoId)
{var currentPhoto=$("#photo-"+currentPhotoId);if(currentPhoto.length)
{photoPosition=currentPhoto.closest(".photo").prevAll(".photo").length+1;}}
loadPhoto();}
function loadPhoto()
{if(photoPosition>totalPhotos+1)
{photoPosition=1;}
var currentPhoto=$(".photo").eq(photoPosition-1);var currentPhotoId=$("h3",currentPhoto).attr("id").replace("photo-","");currentPhoto.show();$(".photo").not(currentPhoto).hide();$("#page-navigation .current").html(photoPosition);if(Modernizr.history)
{window.history.pushState(null,null,albumURL+currentPhotoId+"/");}
else
{window.location.hash="#"+currentPhotoId;}}
function nextPhoto(event)
{if(photoPosition<totalPhotos)
{photoPosition++;loadPhoto();}
event.preventDefault();}
function previousPhoto(event)
{if(photoPosition>1)
{photoPosition--;loadPhoto();}
event.preventDefault();}});
