var SLIDESHOW_SIZE=320;function slideshowSetup(){SITE_BASE_URL="";PHOTOS_SERVICE_URL="/services/Photos";if(window.WIDGET_MODE){SITE_BASE_URL=geckoHome;PHOTOS_SERVICE_URL+=".php"}}function Slideshow(B,D,A){window.slideshow=this;slideshowSetup();this.area=D;this.queryUrl=B;this.itemIndex=0;this.results=new Array();this.showName=(A.showName)?A.showName:false;this.showLocation=(A.showLocation)?A.showLocation:false;this.showCaption=(A.showCaption)?A.showCaption:false;this.showFlag=(A.showFlag)?A.showFlag:false;this.showUpload=(A.showUpload)?A.showUpload:false;this.showCredit=(A.showCredit)?A.showCredit:false;this.showMakeCover=(A.showMakeCover)?A.showMakeCover:false;this.showInfoOnMouseOver=(A.showInfoOnMouseOver)?A.showInfoOnMouseOver:false;this.randomize=(A.randomize)?A.randomize:false;this.onEmptyResults=A.onEmptyResults;if(B&&D){var C=document.postForm;if(this.queryUrl.match(/guide=(\d+)/)){C.guide.value=RegExp.$1}if(this.queryUrl.match(/listing=(\d+)/)){C.listing.value=RegExp.$1}this.loadData()}}Slideshow.prototype.renderFrame=function(I,G,F,H){var E="<div class='slideshow-main'>";E+="<div class='slideshow-image'><img src='"+I.image+"' width='320' height='320'></div>";E+="<div class='slideshow-box-controls'>";if(G>0){E+="   <div class='pager-box' onclick='navSlideshowLeft()'>&lt;</div>"}else{E+="<div class='pager-box'></div>"}var B=5*Math.floor(G/5);for(var D=B;D<Math.min(B+5,F);D++){var A=(D==G)?"selected":"";E+="   <div class='pager-box "+A+"' onclick='navSlideshowIndex("+D+")'>"+(D+1)+"</div>"}if(G<F-1){E+="   <div class='pager-box' onclick='navSlideshowRight()'>&gt;</div>"}else{E+="<div class='pager-box'></div>"}if(this.showUpload){E+="<div class='photo-upload-box' onclick='uploadPhoto()'></div>"}E+="</div>";var C=(this.showInfoOnMouseOver)?"none":"block";E+="<div class='slideshow-popup' style='display:"+C+"'>";E+=this.getInfo(I,H);E+="</div>";E+="</div>";E+="</div>";E+="<div class='slideshow-extra-controls'>";if(this.showMakeCover){E+="<div class='slideshow-make-cover'><a href='#' onclick='return false' title='Make Cover'>Make cover</a></div>"}E+="</div>";return E};Slideshow.prototype.loadData=function(){var B=this;var A=this.queryUrl;YAHOO.util.Connect.asyncRequest("GET",A,{success:B.processResults,failure:function(C){},scope:B})};Slideshow.prototype.processResults=function(A){try{var C=JSON.parse(A.responseText);bbox=C.boundaries;this.results=C.results;if(this.results.length==0){if(this.onEmptyResults){this.onEmptyResults()}else{this.area.innerHTML="<div style='slideshow-none-available'>No photos available</div><div>Be first to upload a photo.  <div class='link' onclick='uploadPhoto()'>Upload Photo</div></div>"}return }if(this.randomize){this.results.sort(function(G,F){return 0.5-Math.random()})}memberPhotos=[];for(var D=0;D<this.results.length;D++){var B=this.results[D];memberPhotos.push(new Photo(B.caption,B.squareThumb,null,null,B.largePath,B.id,null,B.location,parseInt(B.width),parseInt(B.height),null,B.dateAdded,B.dateTaken))}this.renderItem()}catch(E){alert(E)}};Slideshow.prototype.renderItem=function(){var C=this.results[this.itemIndex];var A=(C.canRate=="true"||window.WIDGET_MODE);this.area.innerHTML=this.renderFrame(C,this.itemIndex,this.results.length,A);this.infoPopup=getFirstElementByClassName("slideshow-popup",this.area);this.setupInfo(C,A);if(this.showInfoOnMouseOver){var D=getFirstElementByClassName("slideshow-image",this.area);YAHOO.util.Event.addListener(D,"mouseover",this.showInfo,this,true);YAHOO.util.Event.addListener(D,"mouseout",this.hideInfo,this,true);YAHOO.util.Event.addListener(this.infoPopup,"mouseover",this.showInfo,this,true);YAHOO.util.Event.addListener(this.infoPopup,"mouseout",this.hideInfo,this,true)}if(this.showMakeCover){var B=getFirstElementByClassName("slideshow-make-cover",this.area);YAHOO.util.Event.addListener(B,"click",this.makeCoverPhoto,this,true)}};Slideshow.prototype.setupInfo=function(E,D){if(D){this.photoRating=new StarRating(E.userRating,5,"stars/rating-star-photo",14,14);var C=getFirstElementByClassName("photo-rating",this.area);this.photoRating.renderSelector(C);var B=getFirstElementByClassName("rate-photo-button",this.area);YAHOO.util.Event.addListener(B,"click",this.ratePhoto,this,true)}if(!E.userFlagged){var A=getFirstElementByClassName("flag-photo-button",this.area);YAHOO.util.Event.addListener(A,"click",this.flagPhoto,this,true)}};function navSlideshowLeft(){slideshow.moveLeft()}function navSlideshowRight(){slideshow.moveRight()}function navSlideshowIndex(A){slideshow.moveIndex(A)}Slideshow.prototype.moveIndex=function(A){if(A>=0&&A<this.results.length){this.itemIndex=A;this.renderItem()}};Slideshow.prototype.moveLeft=function(A){if(this.itemIndex-1>=0){this.itemIndex--;this.renderItem()}};Slideshow.prototype.moveRight=function(A){if(this.itemIndex+1<this.results.length){this.itemIndex++;this.renderItem()}};Slideshow.prototype.getInfo=function(B,A){var D=(B.url)?"onclick='slideshowClicked(\""+B.url+"\")'":"";var E="";E+="<div class='slideshow-box-info-bg'></div>";E+="<div class='slideshow-box-info clear_fix' "+D+"><div class='slideshow-name-info'>";if(this.showCaption){var C="";if(B.caption){C=B.caption;if(C.length>30){C=C.substring(0,30)+"..."}C="&quot;"+C+"&quot;"}E+="   <div class='slideshow-caption'>"+C+"</div>"}if(this.showName){E+="   <div class='slideshow-name'>"+B.name+"</div>"}if(this.showLocation){E+="   <div class='slideshow-guide-name'>"+B.guideName+"</div>"}if(this.showCredit&&B.userName){if(window.WIDGET_MODE){E+="<div class='slideshow-author'>By: "+B.userName+"</div>"}else{E+="<div class='slideshow-author'>By: <a target='_top' href='"+B.userLink+"'>"+B.userName+"</a></div>"}}E+="</div><div class='slideshow-rating-info'>";E+="   <div class='slideshow-rating'>"+new StarRating(B.rating,5,"stars/rating-star-photo",14,14).getHtml()+"</div>";var F=(B.reviewCount==1)?"1 review":B.reviewCount+" reviews";E+="   <div class='slideshow-reviews'>"+F+"</div>";E+="</div>";if(A){E+="<div class='slideshow-rating-controls'><div class='rating-label'>Rate this photo:</div><div class='photo-rating'></div><div class='link rate-photo-button'>Save</a></div></div>"}if(this.showFlag){if(B.userFlagged){E+="<div class='slideshow-flag'>Photo Flagged</div>"}else{E+="<div class='slideshow-flag flag-photo-button link' title='Flag inappropriate or irrelevant photos'>Flag</div>"}}E+="</div>";return E};Slideshow.prototype.showInfo=function(){this.cancelHide=true;if(this.infoPopupShown){return }var A=this.results[this.itemIndex];if(!A){return }this.infoPopupShown=true;this.infoPopup.style.display="block"};Slideshow.prototype.hideInfo=function(){this.cancelHide=false;setTimeout(delegateCallback(this,this.hideInfoSoon),300)};Slideshow.prototype.hideInfoSoon=function(){if(!this.cancelHide){this.infoPopup.style.display="none";this.infoPopupShown=false}};Slideshow.prototype.flagPhoto=function(){var B=this.results[this.itemIndex];var D="event=flagPhoto";if(B.id!=null){D+="&media="+B.id}var A=null;if(B.flickrId!=null){A=B.flickrId}else{if(B.flickr_id!=null){A=B.flickr_id}}if(A!=null){D+="&flickr_id="+A;if(document.form.guide!=null){D+="&guide="+document.form.guide.value}if(document.form.item!=null){D+="&listing="+document.form.item.value}}B.userFlagged=true;var C=this;D+="&"+getSessionParams();YAHOO.util.Connect.asyncRequest("POST",PHOTOS_SERVICE_URL,{success:C.flagHandler,failure:function(E){},scope:C},D)};Slideshow.prototype.flagHandler=function(){var A=getFirstElementByClassName("slideshow-flag",this.area);A.style.display="none";this.infoPopupShown=false};Slideshow.prototype.ratePhoto=function(){var A=this.results[this.itemIndex];var C="event=ratePhoto";if(A.id!=null){C+="&media="+A.id}if(A.flickr_id!=null){C+="&flickr_id="+A.flickr_id;if(document.form.guide!=null){C+="&guide="+document.form.guide.value}if(document.form.item!=null){C+="&listing="+document.form.item.value}}rating=this.photoRating.getRating();C+="&rating="+rating;A.userRating=rating;var B=this;C+="&"+getSessionParams();YAHOO.util.Connect.asyncRequest("POST",PHOTOS_SERVICE_URL,{success:B.ratingHandler,failure:function(D){},scope:B},C)};Slideshow.prototype.ratingHandler=function(){var A=getFirstElementByClassName("slideshow-rating-controls",this.area);A.style.display="none"};Slideshow.prototype.makeCoverPhoto=function(){var A=this.results[this.itemIndex];var C="event=makeCoverPhoto";if(A.id!=null){C+="&media="+A.id}if(document.form.guide){C+="&guide="+document.form.guide.value}if(document.form.listing){C+="&listing="+document.form.listing.value}if(A.flickr_id){C+="&flickr_id="+A.flickr_id}var B=this;C+="&"+getSessionParams();YAHOO.util.Connect.asyncRequest("POST",PHOTOS_SERVICE_URL,{success:B.makeCoverPhotoHandler,scope:B},C)};Slideshow.prototype.makeCoverPhotoHandler=function(){alert("new cover applied!")};function viewAsSlideshow(){slideshow.viewAsSlideshow()}Slideshow.prototype.viewAsSlideshow=function(){if($("photoImage").src.indexOf("blank.gif")>0){return }openSlideshow(this.itemIndex)};function slideshowClicked(A){window.location=A};
