var GallerySlideshow=Class.create({initialize:function(carousel){this.carousel=carousel;
this.running=false;
this.commentsDomElement=$("comments")
},start:function(){this.running=true;
var carousel=this.carousel;
this.interval=setInterval(function scroll(){carousel.scrollTo(carousel.currentIndex()+1)
},7000);
this.commentsDomElement.hide()
},stop:function(){this.running=false;
clearInterval(this.interval);
this.commentsDomElement.show()
},toggle:function(){if(this.running){this.stop()
}else{this.start()
}}});
var GalleryObjectRenderer=Class.create({render:function(item,targetDiv,autoPlay){if(!item||!item.type){return 
}if(autoPlay===undefined){autoPlay=true
}var holder=$(targetDiv);
if(holder){if(item.type=="image"||item.type=="IMAGE"){holder.setStyle({height:"100%",width:"100%"});
holder.update('<img oncontextmenu="return false;" src="'+item.url+'" /></a>')
}else{if(item.type=="video"||item.type=="VIDEO"){if(window.flowplayer){holder.update();
var width=document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
var displayWidth=width-360;
var displayHeight=displayWidth*0.66;
holder.setStyle({height:displayHeight+"px",width:displayWidth+"px"});
$f(targetDiv,"/flash/lib/flowplayer/flowplayer.commercial-3.1.1.swf",{version:[9,115],onFail:function(){var answer=confirm("You need the latest Flash version to listen to ANYwebcam.com audio. Click ok to be taken to the download site");
if(answer){window.open("http://get.adobe.com/flashplayer/","_blank")
}},key:"#$a122d01ca6094a09e00",clip:{url:item.url,scaling:"orig",autoPlay:false,autoBuffering:false},canvas:{backgroundColor:"#ffffff"},plugins:{controls:{tooltips:{buttons:true},timeBgColor:"#ffffff",bufferGradient:"none",tooltipColor:"#c9d5e0",backgroundGradient:[0.6,0.3,0,0,0],timeColor:"#000000",borderRadius:"0px",sliderGradient:"none",durationColor:"#000000",buttonColor:"#1c61a7",sliderColor:"#1c61a7",buttonOverColor:"#4981ba",volumeSliderColor:"#1c61a7",volumeSliderGradient:"none",progressColor:"#fbb83c",tooltipTextColor:"#000000",backgroundColor:"#eae8dd",bufferColor:"#cccccc",progressGradient:"medium",height:24}}})
}}else{if(item.type=="audio"||item.type=="AUDIO"){if(window.flowplayer){holder.update();
holder.setStyle({height:"24px",width:"100%"});
$f(targetDiv,"/flash/lib/flowplayer/flowplayer.commercial-3.1.1.swf",{version:[9,115],onFail:function(){var answer=confirm("You need the latest Flash version to listen to ANYwebcam.com audio. Click ok to be taken to the download site");
if(answer){window.open("http://get.adobe.com/flashplayer/","_blank")
}},key:"#$a122d01ca6094a09e00",clip:{url:item.url,autoPlay:false,autoBuffering:false},plugins:{controls:{tooltips:{buttons:true},timeBgColor:"#ffffff",bufferGradient:"none",tooltipColor:"#c9d5e0",backgroundGradient:[0.6,0.3,0,0,0],timeColor:"#000000",borderRadius:"0px",sliderGradient:"none",durationColor:"#000000",buttonColor:"#1c61a7",sliderColor:"#1c61a7",buttonOverColor:"#4981ba",volumeSliderColor:"#1c61a7",volumeSliderGradient:"none",progressColor:"#fbb83c",tooltipTextColor:"#ffffff",backgroundColor:"#eae8dd",bufferColor:"#cccccc",progressGradient:"medium",height:24,opacity:1,autoHide:"never"}}})
}}}}}}});
(function(){function setUpGalleryCarousel(){var carouselControls=$("horizontal_carousel");
if(carouselControls){var galleryObjects=window.galleryObjects;
var renderer=window.galleryObjectRenderer;
var currentElementId;
var carousel=new UI.Carousel("horizontal_carousel",{scrollInc:1,nbVisible:3}).observe("scroll:ended",function(event){var newItemId=Math.round(event.memo.carousel.currentIndex())+1;
var currentItem=galleryObjects[newItemId];
currentElementId=newItemId;
renderer.render(currentItem,"full-gallery-item",true)
});
if(window.location.hash.length>1){var hash=window.location.hash.substr(1,window.location.hash.length);
var galleryObjectIndex=galleryObjects.indexOf(galleryObjects.find(function(galleryObject){return galleryObject.id==hash
}));
currentElementId=galleryObjectIndex;
if(currentElementId==1){renderer.render(galleryObjects[currentElementId],"full-gallery-item",false)
}carousel.scrollTo(currentElementId-1)
}else{currentElementId=0;
renderer.render(galleryObjects[1],"full-gallery-item",false)
}carouselControls.delegate("click",{".carousel-item":function(event,matchedElement){carousel.scrollTo(matchedElement.relatedId()-1)
}},{stop:true,matchElementIfDescendantOfSelector:true});
var slideshowLink=$("slideshow-link");
if(slideshowLink){var gallerySlideshow=new GallerySlideshow(carousel);
function slideshow(event){event.stop();
slideshowLink.toggleClassName("slideshow-started");
gallerySlideshow.toggle()
}slideshowLink.observe("click",slideshow)
}Event.observe(document,"keyup",function(event){if(event.keyCode==Event.KEY_LEFT){carousel.scrollTo(currentElementId-2)
}if(event.keyCode==Event.KEY_RIGHT){carousel.scrollTo(currentElementId)
}})
}}document.observe("dom:loaded",setUpGalleryCarousel)
})();
(function(){function setupGalleries(){var galleryElement=$("gallery");
if(galleryElement){galleryElement.delegate("click",{".toggle-control":function(event){var relatedElement=event.element().relatedElement();
if(relatedElement){relatedElement.toggle()
}},".cancel-comment":function(event){var relatedElement=event.element().relatedElement();
if(relatedElement){relatedElement.toggle()
}},".delete-comment":function(event){var galleryElement=$("gallery");
var commentElement=event.element().up(".comment");
if(galleryElement&&commentElement){galleryId=galleryElement.relatedId();
commentId=commentElement.relatedId();
if(confirm("Are you sure you want to delete this comment?")){GalleryService.deleteGalleryComment(galleryId,commentId,function(result){if(result&&commentElement){commentElement.highlightSuccess().fade()
}})
}}},".vote":function(event,element){if(!element){return 
}var galleryElement=element.up(".gallery");
if(galleryElement){var galleryId=galleryElement.relatedId();
var voteValue=element.relatedId();
galleryElement.select(".vote").invoke("hide");
GalleryService.voteForGallery(galleryId,voteValue,function(result){if(!result){galleryElement.select(".vote").invoke("show");
return 
}var vote=result.result;
galleryElement.down(".vote-stars").removeClassName("vote-1-star-average").removeClassName("vote-2-star-average").removeClassName("vote-3-star-average").removeClassName("vote-4-star-average").removeClassName("vote-5-star-average").removeClassName("vote-1-star").removeClassName("vote-2-star").removeClassName("vote-3-star").removeClassName("vote-4-star").removeClassName("vote-5-star").addClassName("vote-"+vote.gallery.averagePoints+"-star-average");
galleryElement.down(".total-votes").update(vote.gallery.totalVotes);
galleryElement.down(".vote-total").highlightSuccess();
var message=new Element("p").update(result.message).hide().appear();
galleryElement.down(".gallery-vote").insert(message)
})
}}},{stop:true});
if(!(Prototype.Browser.IE&&Prototype.Browser.Version<7)){galleryElement.delegate("mouseover",{".vote":function(event,element){var voteStars=element.up(".vote-stars");
if(voteStars){voteStars.addClassName("vote-"+element.readAttribute("rel")+"-star")
}}});
galleryElement.delegate("mouseout",{".vote":function(event,element){var voteStars=element.up(".vote-stars");
if(voteStars){voteStars.removeClassName("vote-"+element.readAttribute("rel")+"-star")
}}})
}}}document.observe("dom:loaded",function(){setupGalleries()
})
})();
(function(){function setUpRenderableGalleryObjects(){$$(".render-gallery-object").each(function(link){Event.observe(link,"click",function(e){e.stop();
var id=link.relatedId("media-item-");
var rel=link.getAttribute("rel");
var uid=link.getAttribute("uid");
var target="render-media-item-"+id;
if($(target).visible()){$(target).fade();
return 
}$(target).appear();
var ext;
switch(rel){case"image":ext=".jpg";
break;
case"gif":ext=".gif";
break;
case"video":ext=".mp4";
break;
case"audio":ext=".mp3";
break
}var url="/images/uploads/"+uid+"/"+rel+"/"+id+ext;
var renderer=new GalleryObjectRenderer();
renderer.render({type:rel,url:url},target,false)
})
})
}document.observe("dom:loaded",setUpRenderableGalleryObjects)
}());
