var photoId=photoArray[0];var borderSize=30;var photoDir="photos/";var photoNum=photoArray.length;var searchresultdown=false;Object.extend(Element,{getWidth:function(element){element=$(element);return element.offsetWidth;},setWidth:function(element,w){element=$(element);element.style.width=w+"px";},setHeight:function(element,h){element=$(element);element.style.height=h+"px";},setSrc:function(element,src){element=$(element);element.src=src;},setHref:function(element,href){element=$(element);element.href=href;},setInnerHTML:function(element,content){element=$(element);element.innerHTML=content;}});var Slideshow=Class.create();Slideshow.prototype={initialize:function(photoId){this.photoId=photoId;this.photo='Photo';this.photoBox='Container';this.prevLink='PrevLink';this.nextLink='NextLink';this.captionBox='CaptionContainer';this.PostTitle='PostTitle';this.caption='Caption';this.DateStamp='DateStamp';this.loader='Loading';this.CommentsLink='CommentsLink';},getCurrentSize:function(){this.wCur=Element.getWidth(this.photoBox);this.hCur=Element.getHeight(this.photoBox);},getNewSize:function(){this.wNew=photoArray[3];this.hNew=photoArray[4];},getScaleFactor:function(){this.getCurrentSize();this.getNewSize();this.xScale=(this.wNew/this.wCur)*100;this.yScale=(this.hNew/this.hCur)*100;},setNewPhotoParams:function(){Element.setSrc(this.photo,photoDir+photoArray[2]);Element.setHref(this.prevLink,"#"+(photoId));Element.setHref(this.nextLink,"#"+(photoId));},setPhotoCaption:function(){Element.setInnerHTML(this.PostTitle,photoArray[6]);Element.setInnerHTML(this.caption,photoArray[5]);Element.setInnerHTML(this.DateStamp,photoArray[1]);if(photoArray[9]=="CommentsClosed")
Element.hide(this.CommentsLink);else
{Element.show(this.CommentsLink);Element.setInnerHTML(this.CommentsLink,photoArray[9]);}},resizePhotoBox:function(){this.getScaleFactor();new Effect.Scale(this.photoBox,this.yScale,{scaleX:false,duration:0.3,queue:'front'});new Effect.Scale(this.photoBox,this.xScale,{scaleY:false,delay:0.5,duration:0.3});Element.setWidth(this.captionBox,this.wNew-(-borderSize));},showPhoto:function(){new Effect.Fade(this.loader,{delay:0.5,duration:0.3});new Effect.Appear(this.photo,{duration:0.5,queue:'end',afterFinish:function(){Effect.SlideDown('CaptionContainer',{duration:0.2});}});if(photoArray[7]=="true")
Element.show(this.prevLink);else
Element.hide(this.prevLink);if(photoArray[8]=="true")
Element.show(this.nextLink);else
Element.hide(this.nextLink);},initSwap:function(){Element.show(this.loader);Element.hide(this.photo);Element.hide(this.captionBox);Element.hide(this.prevLink);Element.hide(this.nextLink);this.setNewPhotoParams();this.resizePhotoBox();this.setPhotoCaption();}}
var CommentsBox=Class.create();CommentsBox.prototype={initialize:function(){this.CommentsBox='CommentsBox';},hideTheBox:function(){new Effect.toggle(this.CommentsBox,'blind',{delay:0.5,duration:0.3});},initComments:function(){Element.hide(this.CommentsBox);}}
var SearchResultsBox=Class.create();SearchResultsBox.prototype={initialize:function(photoId){this.SearchResultsBox='SearchResultsBox';},showSearchResultsBox:function(){new Effect.SlideDown(this.SearchResultsBox,{duration:0.5});},closeSearchResultsBox:function(){new Effect.SlideUp(this.SearchResultsBox,{duration:0.5});},initSearchResultsBox:function(){Element.hide(this.SearchResultsBox);}}
var myrules={'#Photo':function(element){element.onload=function(){var myPhoto=new Slideshow(photoId);myPhoto.showPhoto();}},'#PrevLink':function(element){element.onclick=function(){updateImage("PrevLink");return false;}},'#NextLink':function(element){element.onclick=function(){updateImage("NextLink");return false;}},'#CommentsLink':function(element){element.onclick=function(){getComments();}},a:function(element){element.onfocus=function(){this.blur();}}};Behaviour.addLoadEvent(init);Behaviour.apply();function init()
{var myPhoto=new Slideshow(photoId);myPhoto.initSwap();var myCommentsBox=new CommentsBox();myCommentsBox.initComments();var mySearchResultsBox=new SearchResultsBox();mySearchResultsBox.initSearchResultsBox();}
function updateImage(WhoCalled)
{var pars='whocalled='+WhoCalled+'&p='+photoId;new Ajax.Request("index_photoupdate.php",{method:'post',postBody:pars,onSuccess:function(resp){var responce=resp.responseText;photoArray=responce.split("||");photoId=photoArray[0];var myCommentsBox=new CommentsBox(photoId);myCommentsBox.initComments();var myPhoto=new Slideshow(photoId);myPhoto.initSwap();},onFailure:function(resp){alert("Oops, there's been an error obtaining the next photo.");}});}
function getComments()
{var url='comments_list.php';var pars='p='+photoId;var ajax=new Ajax.Updater({success:'CommentsBox'},url,{method:'get',parameters:pars,onSuccess:succesDrawbox,onFailure:reportError});}
function sendComments()
{var url='comments_list.php?p='+photoId;var pars=Form.serialize($('CommentForm'));var ajax=new Ajax.Updater({success:'CommentsBox'},url,{asynchronous:true,parameters:pars,onFailure:reportError});}
function reportError(request)
{alert("Oops, there's been an error.");}
function succesDrawbox(request)
{var myCommentsBox=new CommentsBox(photoId);myCommentsBox.hideTheBox();}
function getSearchResults()
{var url='search_result.php';var pars=Form.serialize($('sform'));if(pars.length>2)
{var ajax=new Ajax.Updater({success:'SearchResultsBox'},url,{asynchronous:true,parameters:pars,onSuccess:DrawSearchResultsbox,onFailure:reportError});}
else
{var mySearchResultsBox=new SearchResultsBox();mySearchResultsBox.initSearchResultsBox();searchresultdown=false;}}
function DrawSearchResultsbox(request)
{if(searchresultdown!=true)
{var mySearchResultsBox=new SearchResultsBox();mySearchResultsBox.showSearchResultsBox();searchresultdown=true;}}
function CloseSearchResultsbox(request)
{var mySearchResultsBox=new SearchResultsBox();mySearchResultsBox.closeSearchResultsBox();searchresultdown=false;}

