CoolSpotters.PaginationEffects={PREV:1,NEXT:-1,PlainJane:function(container,new_data,direction,options){container.innerHTML=new_data;if(options.transition_callback!=null)
options.transition_callback();},SlideOff:function(container,new_data,direction,options){container.makeClipping();container.makePositioned();var dims=container.getDimensions();if(container.style.height==null||container.style.height.length==0)
{container.setStyle({height:dims["height"]+"px",width:dims["width"]+"px"});}
var gallery_list=container.firstDescendant();gallery_list.insert({after:new_data});var gal_lists=container.childElements();if(gal_lists.length==2)
{gal_lists[1].absolutize();gal_lists[1].setStyle({left:(-1*direction*dims.width+1)+"px",top:"0px"});var new_one=gal_lists[1];gallery_list.absolutize();gallery_list.style.zIndex="10";return new Effect.Parallel([new Effect.MoveBy(gal_lists[0],0,direction*(dims.width+1)),new Effect.MoveBy(gal_lists[1],0,direction*(dims.width+1))],{duration:0.5,afterFinish:function(effect){gal_lists[0].remove();new_one.style.position="relative";if(options.transition_callback!=null)
options.transition_callback();}});}},VerticalSlide:function(container,new_data,direction,currentPage,requestedPage,totalPages,options){container.style.zIndex="100";var dims=container.getDimensions();container.setStyle({height:dims["height"]+"px",width:dims["width"]+"px"});container.makePositioned();container.makeClipping();var content_container=container.firstDescendant();if(new_data!=null)
{if(direction<0)
{content_container.insert({bottom:new_data});}
else if(direction>0)
{content_container.insert({top:new_data});}}
var children=content_container.childElements();var req_dims=children[requestedPage-1].getDimensions();var margin=5;var slide=null;if(requestedPage>currentPage)
{var cur_dims=children[currentPage-1].getDimensions();diff=requestedPage-currentPage;if(diff==1)
{slide=cur_dims['height']+margin;}
else
{for(i=requestedPage-1;i>=currentPage;i--)
{var r_dims=children[i].getDimensions();slide+=r_dims['height'];slide+=margin;}}}
else
{var cur_dims=children[currentPage-1].getDimensions();diff=currentPage-requestedPage;if(diff==1)
{slide=req_dims['height']+margin;}
else
{for(i=requestedPage+1;i<=currentPage;i++)
{var r_dims=children[i-1].getDimensions();slide+=r_dims['height'];slide+=margin;}}}
content_container.style.zIndex="10";new Effect.Move(content_container,{x:0,y:direction*slide,afterFinish:function(effect){if(options.transition_callback!=null)
options.transition_callback();}});}};CoolSpotters.CSPaginator=Class.create();CoolSpotters.CSPaginator.prototype={content_container:null,page_dots_container:null,page_dots:null,scroller:null,url:null,params:null,totalPages:0,initialPage:0,currentPage:0,currentRequest:null,currentClick:null,options:{method:"get",paramName:"page",defaultParams:null,asynchronous:true,activePageClass:"active",inactivePageClass:null,pagesTag:"li",transition:CoolSpotters.PaginationEffects.PlainJane,pageLoadedCallback:null,transition_callback:null,max_pages:10},initialize:function(container,page_dots,scroller,pagination_url,total_pages,initial_page,options)
{this.options=$H(this.options).update(options||{}).toObject();this.page_dots_container=$(page_dots);if(this.page_dots_container!=null)
{this.page_dots=$A(this.page_dots_container.getElementsBySelector(this.options.pagesTag));this.scroller=$(scroller);this.content_container=$(container);this.totalPages=total_pages;this.url=pagination_url;if(this.totalPages>this.options.max_pages)
this.totalPages=this.options.max_pages;if(initial_page==null)
initial_page=1
this.initialPage=initial_page;this.options.onSuccess=this.presentNewPage.bind(this);this.options.onFailure=this.requestFailed.bind(this);this.options.transition_callback=this.requestCleanup.bind(this);this.setPageState(initial_page);try{Event.observe(this.scroller.getElementsByClassName("scroll-left")[0],"click",this.prevPage.bindAsEventListener(this));Event.observe(this.scroller.getElementsByClassName("scroll-right")[0],"click",this.nextPage.bindAsEventListener(this));var evHandler=this.jumpToPage.bindAsEventListener(this);this.page_dots.each(function(ele){$A(ele.descendants()).each(function(ele2){if(ele2.nodeName.toLowerCase()=="a"){Event.observe(ele2,"click",evHandler);}});});}catch(e)
{}}},setPageState:function(page)
{this.setDotState(this.currentPage-1,false);this.currentPage=page;this.setDotState(this.currentPage-1,true);},setLoadingDotState:function(index)
{if(index<0||index>=this.totalPages)
return;var links=this.page_dots[index].getElementsBySelector("a");if(links!=null&&links.length>0)
links[0].addClassName('dotload');},setDotState:function(index,is_active)
{if(index<0||index>=this.totalPages)
return;var links=this.page_dots[index].getElementsBySelector("a");if(links!=null&&links.length>0)
{if(is_active)
{links[0].removeClassName('dotload');links[0].addClassName("active");}
else
{links[0].removeClassName('dotload');links[0].removeClassName("active");}}},nextPage:function(e){if(e!=null)
e.stop();this.goToPage(this.currentPage+1);},prevPage:function(e){if(e!=null)
e.stop();this.goToPage(this.currentPage-1);},jumpToPage:function(e){if(e!=null)
e.stop();var elem=Event.element(e);var label=elem.innerHTML.stripTags();if(label!=null){var matches=label.match(/Page (\d+)/);if(matches!=null)
this.goToPage(Number(matches[1]));}},goToPage:function(page)
{if(page==null)
page=1;if(this.current_request!=null)
return;if(page==this.currentPage)
return;if(page<this.currentPage)
this.currentClick=CoolSpotters.PaginationEffects.PREV;else
this.currentClick=CoolSpotters.PaginationEffects.NEXT;if(page>this.totalPages)
page=1;if(page<1)
page=this.totalPages;entry=encodeURIComponent(this.options.paramName)+'='+page;this.options.parameters=this.options.callback?this.options.callback(this.element,entry):entry;if(this.options.defaultParams)
this.options.parameters+='&'+this.options.defaultParams;this.current_request=new Ajax.Request(this.url,this.options);this.setLoadingDotState(page-1);},presentNewPage:function(transport)
{var payload=transport.responseText.evalJSON();this.options.transition(this.content_container,payload.new_page,this.currentClick,this.options);this.setPageState(payload.current_page);this.sync_up_controls(payload);if(this.options.pageLoadedCallback!=null)
this.options.pageLoadedCallback(payload);},sync_up_controls:function(payload)
{},requestFailed:function(transport)
{},requestCleanup:function(transport)
{this.current_request=null;this.currentClick=null;}};CoolSpotters.CSArrowPaginator=Class.create();CoolSpotters.CSArrowPaginator.prototype={content_container:null,scroller:null,url:null,params:null,totalPages:0,initialPage:0,currentPage:0,currentRequest:null,requestedPage:null,currentClick:null,footer:null,arrow_up_control:null,arrow_down_control:null,arrow_up_active_control:null,arrow_down_active_control:null,arrow_up_off_control:null,arrow_down_off_control:null,pagesLoaded:null,down_click_listener:null,up_click_listener:null,isLoading:null,options:{method:"get",paramName:"page",fromParamName:"from",toParamName:"to",defaultParams:null,asynchronous:true,activePageClass:"active",inactivePageClass:null,pagesTag:"li",transition:CoolSpotters.PaginationEffects.VerticalSlide,pagesLoaded:null,transition_callback:null},initialize:function(container,scroller,pagination_url,total_pages,initial_page,footer,options)
{this.options=$H(this.options).update($H(options)||{}).toObject();this.scroller=$(scroller);this.content_container=$(container);this.totalPages=total_pages;this.url=pagination_url;if(initial_page==null)
initial_page=1
this.initialPage=initial_page;if(footer!="nil"){this.footer=null;}else{this.footer=$(footer);}
this.options.onSuccess=this.presentNewPage.bind(this);this.options.onFailure=this.requestFailed.bind(this);this.options.onLoading=this.addLoader.bind(this);this.options.onLoaded=this.removeLoader.bind(this);this.options.transition_callback=this.requestCleanup.bind(this);if(this.totalPages>1)
{this.setPageState(initial_page);this.initializePagesLoaded();this.setupControls();this.sync_up_controls();this.setupFooterControls();}},initializePagesLoaded:function()
{this.pagesLoaded=new Array(this.totalPages);for(var i=0;i<this.totalPages;i++)
{this.pagesLoaded[i]=false}
this.pagesLoaded[this.initialPage-1]=true;},addLoader:function()
{},removeLoader:function()
{},setupControls:function()
{disabled_up_link=$(document.createElement("a"));disabled_up_link.id='scroll-up-control'
disabled_up_link.addClassName('scroll-up-dim');disabled_up_link.setStyle({cursor:'default'});disabled_up_link.href='#';link_text=$(document.createTextNode('Up'));disabled_up_link.appendChild(link_text);up_link=$(document.createElement("a"));up_link.id='scroll-up-control'
up_link.addClassName('scroll-up');up_link.href='#';link_text=$(document.createTextNode('Up'));up_link.appendChild(link_text);disabled_down_link=$(document.createElement("a"));disabled_down_link.id='scroll-down-control';disabled_down_link.addClassName('scroll-down-dim');disabled_down_link.setStyle({cursor:'default'});disabled_down_link.href='#';link_text=$(document.createTextNode('Down'));disabled_down_link.appendChild(link_text);down_link=$(document.createElement("a"));down_link.id='scroll-down-control';down_link.addClassName('scroll-down');down_link.href='#';link_text=$(document.createTextNode('Down'));down_link.appendChild(link_text);this.arrow_up_active_control=up_link;this.arrow_down_active_control=down_link;this.arrow_up_off_control=disabled_up_link;this.arrow_down_off_control=disabled_down_link;},setupFooterControls:function()
{bottom_link=$(document.createElement("a"));bottom_link.id='scroll-up-bottom'
bottom_link.href='#';link_text=$(document.createTextNode('Bottom'));bottom_link.appendChild(link_text);top_link=$(document.createElement("a"));top_link.id='scroll-up-top'
top_link.href='#';link_text=$(document.createTextNode('Top'));top_link.appendChild(link_text);bottom_list_item=$(document.createElement('li'));top_list_item=$(document.createElement('li'));bottom_list_item.appendChild(bottom_link);top_list_item.appendChild(top_link);if(this.footer!=null){footer_container=this.footer.firstDescendant();bottom_element=footer_container.appendChild(bottom_list_item);top_element=footer_container.appendChild(top_list_item);Event.observe($('scroll-up-bottom'),"click",this.lastPage.bindAsEventListener(this));Event.observe($('scroll-up-top'),"click",this.firstPage.bindAsEventListener(this));}},setPageState:function(page)
{this.currentPage=page;},nextPage:function(e){if(e!=null)
e.stop();if(!this.isLoading)
this.goToPage(this.currentPage+1);},prevPage:function(e){if(e!=null)
e.stop();if(!this.isLoading)
this.goToPage(this.currentPage-1);},dontGoAnywhere:function(e){if(e!=null)
e.stop();},jumpToPage:function(e){if(e!=null)
e.stop();var elem=Event.element(e);var label=elem.innerHTML.stripTags();if(label!=null){var matches=label.match(/Page (\d+)/);if(matches!=null)
this.goToPage(Number(matches[1]));}},goToPage:function(page)
{if(page==null)
page=1;if(this.current_request!=null)
return;if(page==this.currentPage)
return;if(page<this.currentPage)
this.currentClick=CoolSpotters.PaginationEffects.PREV;else
this.currentClick=CoolSpotters.PaginationEffects.NEXT;if(this.hasLoadedPage(page)&&!this.isLoading)
{this.requestedPage=page;this.presentNewPage(null);}
else
{entry=encodeURIComponent(this.options.paramName)+'='+page;this.options.parameters=this.options.callback?this.options.callback(this.element,entry):entry;if(this.options.defaultParams)
this.options.parameters+='&'+$H(this.options.defaultParams).toQueryString();this.current_request=new Ajax.Request(this.url,this.options);this.requestedPage=page;this.isLoading=true;loader_span=this.scroller.getElementsBySelector('span.scroll-load');if(loader_span!=null)
Element.show(loader_span[0]);}},firstPage:function(e)
{if(e!=null)
e.stop();if(!this.isLoading)
{if(this.current_request!=null)
return;if(this.currentPage==1)
return;this.requestedPage=1;this.currentClick=CoolSpotters.PaginationEffects.PREV;this.options.transition(this.content_container,null,this.currentClick,this.currentPage,this.requestedPage,this.options);this.setPageState(this.requestedPage);this.sync_up_controls(null);}},lastPage:function(e)
{if(e!=null)
e.stop();if(!this.isLoading)
{if(this.current_request!=null)
return;if(this.currentPage==this.totalPages)
return;this.requestedPage=this.totalPages;this.currentClick=CoolSpotters.PaginationEffects.NEXT;var all_pages_loaded=true;var last_page_loaded=0;for(var i=this.currentPage;i<=this.totalPages;i++)
{if(!this.hasLoadedPage(i))
{last_page_loaded=i;all_pages_loaded=false;break;}}
if(all_pages_loaded)
{this.options.transition(this.content_container,null,this.currentClick,this.currentPage,this.requestedPage,this.options);this.setPageState(this.requestedPage);this.sync_up_controls(null);}
else
{entry=encodeURIComponent(this.options.fromParamName)+'='+last_page_loaded;entry+='&'+encodeURIComponent(this.options.toParamName)+'='+this.totalPages;this.options.parameters=this.options.callback?this.options.callback(this.element,entry):entry;if(this.options.defaultParams)
this.options.parameters+='&'+$H(this.options.defaultParams).toQueryString();this.current_request=new Ajax.Request(this.url,this.options);}}},hasLoadedPage:function(page)
{loaded=false;if(this.pagesLoaded!=null&&this.pagesLoaded[page-1])
{loaded=true;}
return loaded;},setAllPagesLoaded:function()
{for(var i=0;i<this.totalPages;i++)
{this.pagesLoaded[i]=true;}},presentNewPage:function(transport)
{this.isLoading=true;var payload=null;if(transport!=null)
payload=transport.responseText;this.options.transition(this.content_container,payload,this.currentClick,this.currentPage,this.requestedPage,this.totalPages,this.options);if(this.options.pageLoadedCallback!=null)
this.options.pageLoadedCallback(payload);},sync_up_controls:function(payload)
{if(this.currentPage==0)
this.currentPage=1;if(this.currentPage>this.totalPages)
this.currentPage=this.totalPages;if(this.arrow_up_control!=null)
Event.stopObserving(this.arrow_up_control,"click",this.up_link_listener);if(this.arrow_down_control!=null)
Event.stopObserving(this.arrow_down_control,"click",this.down_link_listener);if(this.currentPage==1&&this.totalPages==1)
{this.arrow_up_control=null;this.arrow_down_control=null;}
else if(this.currentPage==1&&this.totalPages>1)
{this.arrow_up_control=this.arrow_up_off_control;this.arrow_down_control=this.arrow_down_active_control;this.up_link_listener=this.dontGoAnywhere.bindAsEventListener(this);this.down_link_listener=this.nextPage.bindAsEventListener(this);Event.observe(this.arrow_up_control,"click",this.up_link_listener);Event.observe(this.arrow_down_control,"click",this.down_link_listener);}
else if(this.currentPage==this.totalPages)
{this.arrow_up_control=this.arrow_up_active_control;this.arrow_down_control=this.arrow_down_off_control;this.up_link_listener=this.prevPage.bindAsEventListener(this);this.down_link_listener=this.dontGoAnywhere.bindAsEventListener(this);Event.observe(this.arrow_up_control,"click",this.up_link_listener);Event.observe(this.arrow_down_control,"click",this.down_link_listener);}
else if(this.currentPage>1&&this.currentPage<this.totalPages)
{this.arrow_up_control=this.arrow_up_active_control;this.arrow_down_control=this.arrow_down_active_control;this.up_link_listener=this.prevPage.bindAsEventListener(this);this.down_link_listener=this.nextPage.bindAsEventListener(this);Event.observe(this.arrow_up_control,"click",this.up_link_listener);Event.observe(this.arrow_down_control,"click",this.down_link_listener);}
this.renderControls();},renderControls:function()
{if(this.scroller!=null)
this.scroller.getElementsBySelector('a').each(function(ele){ele.remove();})
if(this.arrow_down_control!=null&&this.scroller!=null)
this.scroller.insert({top:this.arrow_down_control});if(this.arrow_up_control!=null&&this.scroller!=null)
this.scroller.insert({top:this.arrow_up_control});},requestFailed:function(transport)
{},requestCleanup:function(transport)
{this.current_request=null;this.currentClick=null;this.pagesLoaded[this.requestedPage-1]=true;if(this.requestedPage==this.totalPages)
this.setAllPagesLoaded();this.setPageState(this.requestedPage);this.sync_up_controls(null);this.requestedPage=null;this.isLoading=false;loader_span=this.scroller.getElementsBySelector('span.scroll-load');if(loader_span!=null)
Element.hide(loader_span[0]);},reset:function(total_pages,initial_page)
{this.totalPages=total_pages;if(initial_page==null)
initial_page=1
this.initialPage=initial_page;this.setPageState(initial_page);this.initializePagesLoaded();this.sync_up_controls(null);this.content_container.down().setStyle({top:'0px'})}};CoolSpotters.PhotoTagging={};CoolSpotters.MediaGallery={};CoolSpotters.PhotoTagging.PhotoTag=Class.create();CoolSpotters.PhotoTagging.PhotoTag.prototype={image_element:null,element:null,marker:null,inner_marker:null,very_inner_marker:null,data:null,options:{radius:54,click_callback:null,drag_end_callback:null,x_offset:0,y_offset:0,drop_zone_id:"not_pictured_drop_target"},click_handler:null,drop_zone:null,not_pictured:false,active_image:null,inactive_image:null,initialize:function(profile_medium,image,options)
{this.options=$H(this.options).update(options||{}).toObject();this.image_element=image;this.data=profile_medium;this.drop_zone=$(this.options.drop_zone_id);this.render_tag_marker(this.data.x_coord,this.data.y_coord);this.click_handler=this.handle_click.bindAsEventListener(this);Event.observe(this.element,"mouseover",this.display_tag_hover.bindAsEventListener(this));Event.observe(this.element,"mouseout",this.hide_tag_hover.bindAsEventListener(this));Event.observe(this.marker,"click",this.click_handler);},render_tag_marker:function(centerX,centerY)
{this.box_is_out=true;var tag_container=new Element("div",{"style":"z-index: 1000; position: absolute;"+"width: "+(this.options.radius)+"px; height: "+(this.options.radius)+"px; cursor: pointer;","class":"tag_zone_box"});var outer_box=new Element("div",{"style":"position: absolute; top: 0px; left: 0px; width: "+
(this.options.radius)+"px; height: "+(this.options.radius)+"px;","class":"tag_marker_box"});this.active_image=new Element("img",{"src":"http://www.static.coolspotters.com/images/icons/spot_tag_active.png","alt":"active tag location"});this.inactive_image=new Element("img",{"src":"http://www.static.coolspotters.com/images/icons/spot_tag.png","alt":"inactive tag location"});if($('IE6root')!=null)
{if(typeof(fnLoadPngs)=="function")
{fnLoadPngs();}
this.iepngfix(this.active_image);this.iepngfix(this.inactive_image);}
tag_container.appendChild(outer_box);this.element=tag_container;this.marker=outer_box;if(centerX===null||centerY===null)
{this.not_pictured=false;if(this.image_element!=null)
{var dims=this.image_element.getDimensions();this.move_to(dims.width/2,dims.height/2);}else{this.not_pictured=true;this.move_to(-1,-1);}}else if(centerX==-1&&centerY==-1)
{this.not_pictured=true;this.move_to(-1,-1);}else{this.not_pictured=false;this.move_to(centerX,centerY);}
return tag_container;},iepngfix:function(img)
{var src=img.src;img.style.width=img.width+"px";img.style.height=img.height+"px";img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"')";img.src="/images/blank.gif";img.style.visibility="visible";},box_coords_for_dropzone:function(dzpos)
{var delta_offset=$(this.options.tags_container).cumulativeOffset();var dzrel=[];dzrel[0]=dzpos[0]-delta_offset[0];dzrel[1]=dzpos[1]-delta_offset[1];dzrel.left=dzrel[0];dzrel.top=dzrel[1];return dzrel;},box_coords_for_center:function(x,y)
{if(x==-1||y==-1)
{return this.box_coords_for_dropzone(this.drop_zone_coords());}
var box_x=x-(this.options.radius/2)+this.options.x_offset;var box_y=y-(this.options.radius/2)+this.options.y_offset;var dims=this.image_element.getDimensions();if(box_x<this.options.x_offset)
{box_x=this.options.x_offset;}
if(box_y<this.options.y_offset)
{box_y=this.options.y_offset;}
if(box_x+this.options.radius>(dims.width+this.options.x_offset))
{box_x=dims.width+this.options.x_offset-this.options.radius;}
if(box_y+this.options.radius>(dims.height+this.options.y_offset))
{box_y=dims.height+this.options.y_offset-this.options.radius;}
return[box_x,box_y];},drop_zone_coords:function()
{var dzpos=this.drop_zone.cumulativeOffset();dzpos.left=dzpos.left-7;dzpos.top=dzpos.top-8;dzpos[0]=dzpos.left;dzpos[1]=dzpos.top;return dzpos;},current_center_coords:function()
{if(this.not_pictured===true)
{return[-1,-1];}
return this.center_coords_for(this.element);},center_coords_for:function(ele)
{var box_coords=ele.positionedOffset();return[box_coords.left+(this.options.radius/2)-this.options.x_offset,box_coords.top+(this.options.radius/2)-this.options.y_offset];},display_tag_hover:function(e)
{if(e!=null){e.stop();}
if(this.options.hover_callback!=null)
{this.options.hover_callback(e,this,true);}},hide_tag_hover:function(e)
{if(e!=null){e.stop();}
if(this.options.hover_callback!=null)
{this.options.hover_callback(e,this,false);}},handle_click:function(e)
{if(this.options.click_callback!=null)
{this.options.click_callback(e,this);}},move_to:function(x,y)
{if(x==-1||y==-1)
{this.not_pictured=true;}else{this.not_pictured=false;}
var coords=this.box_coords_for_center(x,y);this.element.style.top=coords[1]+"px";this.element.style.left=coords[0]+"px";if(this.options.drag_end_callback!=null)
{this.options.drag_end_callback(null,null,this);}},set_marker_on:function()
{Element.update(this.marker,this.active_image);},set_marker_off:function()
{Element.update(this.marker,this.inactive_image);},activate:function()
{var img=this.image_element;if(img!=null)
{var x_off=this.options.x_offset;var y_off=this.options.y_offset;this.marker.style.cursor="move";this.draggable=new Draggable(this.element,{handle:this.marker,onDrag:this.onDrag.bind(this),onEnd:this.onEnd.bind(this),starteffect:false,endeffect:false});}
Event.stopObserving(this.marker,"click",this.click_handler);},deactivate:function(success)
{if(this.draggable!=null)
{this.draggable.destroy();}
this.marker.style.cursor="pointer";Event.observe(this.marker,"click",this.click_handler);if(!success&&this.unsaved()==false)
{var coords=this.box_coords_for_center(this.data.x_coord,this.data.y_coord);var teffect=new Effect.Move(this.element,{duration:0.1,mode:'absolute',x:coords[0],y:coords[1]});}},unsaved:function()
{if(this.data.id==null)
{return true;}else if(this.data.x_coord==null||this.data.y_coord==null)
{return true;}else{return false;}},onDrag:function(draggable)
{},onEnd:function(draggable,e)
{var img=this.image_element;if(img!=null)
{var element_dimensions=Element.getDimensions(this.element);var parent_dimensions=Element.getDimensions(img);var x_off=this.options.x_offset;var y_off=this.options.y_offset;var real_coords=draggable.currentDelta();var dzpos=this.drop_zone_coords();function constrain(n,lower,upper){if(n>upper){return upper;}
else if(n<lower){return lower;}
else{return n;}}
var constrained=[constrain(real_coords[0],x_off,parent_dimensions.width-element_dimensions.width+x_off),constrain(real_coords[1],y_off,parent_dimensions.height-element_dimensions.height+y_off)];if(constrained[0]!=real_coords[0]||constrained[1]!=real_coords[1])
{var delta_offset=img.getOffsetParent().cumulativeOffset();var dzrel=[];dzrel[0]=delta_offset[0]+real_coords[0]-dzpos[0];dzrel[1]=delta_offset[1]+real_coords[1]-dzpos[1];var distance_a=Math.sqrt(Math.pow(dzrel[0],2)+Math.pow(dzrel[1],2));if(distance_a<this.options.radius*2)
{this.not_pictured=true;constrained=[dzpos[0]-delta_offset[0],dzpos[1]-delta_offset[1]];}else{this.not_pictured=false;}
var teffecta=new Effect.Move(draggable.element,{x:constrained[0],y:constrained[1],mode:'absolute',duration:0.1});}else{this.not_pictured=false;}}else{this.not_pictured=true;var teffectb=new Effect.Move(draggable.element,{x:dzpos[0],y:dzpos[1],mode:'absolute',duration:0.1});}
if(this.options.drag_end_callback!=null)
{this.options.drag_end_callback(draggable,e,this);}}};CoolSpotters.MediaGallery.TaggingDialog=Class.create(CoolSpotters.ModalDialog,{initialize:function($super,tag,options)
{this.tag=tag;$super(options);this.options.dialog_class="tag tool-container";this.options.drawer_main_offset=0;},open_dialog:function(content_hash)
{$$('.hide_on_smokeout').each(function(ele){ele.setStyle({'visibility':'hidden'});});if(this.dialog==null)
{if(this.options.form_onsubmit_handler==null){this.options.form_onsubmit_handler=this.close_dialog.bindAsEventListener(this);}
this.build_dialog();}
this.set_content(content_hash);Event.observe(window,"resize",this.resize_handler);Event.observe(window,"scroll",this.resize_handler);},close_dialog:function(e)
{if(e!=null)
{e.stop();}
Event.stopObserving(window,"resize",this.resize_handler);Event.stopObserving(window,"scroll",this.resize_handler);$$('.hide_on_smokeout').each(function(ele){ele.setStyle({'visibility':"visible"});});var this_class=this;var teffect=new Effect.Opacity(this.dialog,{from:1.0,to:0.0,duration:0.2,afterFinish:function(){this_class.remove();}});document.fire("cs_modal_dialog:close");CoolSpotters.ModalDialog.current_controller=null;return false;},attach_dialog:function()
{$(this.options.holder).appendChild(this.dialog);var positions=this.calculate_position();this.dialog.style.top=positions[0]+"px";this.dialog.style.left=positions[1]+"px";this.clip_box.style.height=positions[2]+"px";Effect.Appear(this.dialog,{duration:0.2});},calculate_position:function()
{var vpDims=document.viewport.getDimensions();var vpHeight=vpDims.height;var soffs=document.viewport.getScrollOffsets();var hbox=this.height_box;var box_height=hbox.getHeight();var container=this.dialog;var tool_dims=container.getDimensions();var pos=container.getOffsetParent().cumulativeOffset();var img=this.tag.image_element;var img_dims=null;var new_left=0+this.options.dialog_x_offset;if(img!=null)
{img_dims=img.getDimensions();}
var coords=this.tag.current_center_coords();new_left=-1*(tool_dims.width+5);if(this.options.drawer_offset>0){this.options.drawer_offset=this.options.drawer_offset*-1;}
this.drawer.select('.media-content').each(function(el){if($('IERoot')!=null){el.style.styleFloat="left";}else{el.style.cssFloat="left";}});var new_top=0;if(box_height+(pos.top-soffs.top)>vpDims.height)
{new_top=-1*(box_height+(pos.top-soffs.top)-vpDims.height+15);if(new_top<-1*box_height+this.tag.options.radius){new_top=-1*box_height+this.tag.options.radius;}}
if(this.drawer_should_be_out==true)
{var dh=this.drawer.getHeight();if(box_height<dh)
{box_height=dh+100;}}
return[new_top,new_left,box_height];}});CoolSpotters.MediaGallery.TaggingWizard=Class.create(CoolSpotters.Wizard,{initialize:function(tag,data,destroy_on_cancel,options)
{this.submit_observers=[];this.options.holder=tag.element;this.options.dialog_x_offset=tag.options.radius+12;this.options.coord_x_field="profile_medium_x_coord";this.options.coord_y_field="profile_medium_y_coord";this.options=$H(this.options).update(options||{}).toObject();this.options.form_onsubmit_handler=this.handle_form_submit.bindAsEventListener(this);this.ajax_success_callback=this.display_step.bind(this);this.ajax_failure_callback=this.display_transport_error.bind(this);this.ajax_complete_callback=this.cleanup_connection.bind(this);this.destroy_on_cancel=destroy_on_cancel;this.tag=tag;this.data=data;this.trigger_handler=this.launch_wizard.bindAsEventListener(this);this.initial_url=this.make_url(tag);this.bound_initer=this.loader_initializer.bindAsEventListener(this);this.tag.options.drag_end_callback=this.active_tag_on_drag.bind(this);this.launch_wizard();},make_url:function(tag)
{return"/cs/profile_media/"+tag.data.id+"/edit.js";},launch_wizard:function(e)
{if(e!=null){e.stop();}
if(CoolSpotters.Wizard.current_wizard!=null)
{alert("Please finish or close the current wizard before launching another.");return;}
CoolSpotters.Wizard.current_wizard=this;Event.observe(document,"cs_modal_dialog:panel_loaded",this.bound_initer);this.create_dialog();return false;},loader_initializer:function(e)
{Event.stopObserving(document,"cs_modal_dialog:panel_loaded",this.bound_initer);this.load_wizard_panel(this.initial_url);this.initialized=true;},create_dialog:function(content_hash)
{if(content_hash==null)
{content_hash={button_text:false,title:"Loading...",crossfade:false,title_color:this.options.initial_color,content:"<div style=\"margin-top: 10px; text-align: center;\"><img src=\"/images/icons/loaders/dial1.gif\" alt=\"loading\" /></div>"};}
this.dialog=new CoolSpotters.MediaGallery.TaggingDialog(this.tag,this.options);this.initialized=false;this.dialog.open_dialog(content_hash);Event.observe(this.dialog.back_link,"click",this.handle_back_click.bindAsEventListener(this));Event.observe(document,"cs_modal_dialog:close",this.dialog_closed.bindAsEventListener(this));},load_wizard_panel:function(url,request_parameters)
{request_parameters=typeof(request_parameters)!='undefined'?request_parameters:new Hash();if(this.current_request!=null){return;}
var req_opts={method:this.options.method,evalJS:false,asynchronous:true};req_opts.onSuccess=this.ajax_success_callback;req_opts.onFailure=this.ajax_failure_callback;req_opts.onComplete=this.ajax_complete_callback;if(this.initialized==false)
{req_opts.parameters={"profile_medium[id]":this.tag.data.id,"profile_medium[x_coord]":this.tag.data.x_coord,"profile_medium[y_coord]":this.tag.data.y_coord,"medium_type":this.data.medium_type,"medium_id":this.data.medium_id,"spot_id":this.data.spot_id}}else if(this.dialog!=null){req_opts.parameters=$H(Form.serialize(this.dialog.dialog_form,true)).merge(request_parameters).toObject();}
this.current_request=new Ajax.Request(url,req_opts);},process_response:function(panel_data)
{for(var i=0,len=this.submit_observers.length;i<len;i++)
{Event.stopObserving(document,"cs_wizard:submit",this.submit_observers[i]);}
this.submit_observers.clear();if(panel_data.next_url==null&&panel_data.success==true)
{this.handle_wizard_success();document.fire("cs_wizard:success",this.panel_data);this.dialog.close_dialog();}else{if(this.dialog==null)
{this.create_dialog(panel_data.content_hash);}else{this.dialog.set_content(panel_data.content_hash);}}},active_tag_on_drag:function(draggable,e,tag)
{if(tag==this.tag)
{this.sync_form_data_to_active_tag();if(this.dialog!=null)
{this.dialog.handle_window_resize();}}},sync_form_data_to_active_tag:function()
{var coords=this.tag.current_center_coords();var form_field=$(this.options.coord_x_field);if(form_field!=null)
{form_field.value=coords[0];}
form_field=$(this.options.coord_y_field);if(form_field!=null)
{form_field.value=coords[1];}}});CoolSpotters.MediaGallery.EditPhotoTagging=Class.create(CoolSpotters.MediaGallery.TaggingWizard,{make_url:function(tag)
{return"/cs/profile_media/"+tag.data.id+"/edit.js";}});CoolSpotters.MediaGallery.AddPhotoTagging=Class.create(CoolSpotters.MediaGallery.TaggingWizard,{make_url:function(tag)
{return"/cs/profile_media/new.js";}});CoolSpotters.PhotoTagger=Class.create({image_element:null,container:null,data:null,options:{tag_this_selector:'.tag_this_link',add_tag_selector:'.add-spot-tag',edit_tag_selector:'.edit_tag_link',notice_selector:".show_in_tagging",drop_zone_id:"not_pictured_drop_target",cancel_tag_selector:".cancel-tag-link",callback_obj:null,spot_box_radius:40,new_tag_step:1,exist_tag_step:6,edit_url:"/cs/profile_media/",new_url:"/cs/profile_media/new.js",create_url:"/cs/profile_media.js",gap:5,tool_id:"tool-container",tool_css_class:"tag tool-container",link_list_prefix:"profile_medium_info_",link_list_id:"profile_link_list_holder",coord_x_field:"profile_medium_x_coord",coord_y_field:"profile_medium_y_coord",untag_link_selector:".untag_link",destroy_close_link:"tag_destroy_close_button",initial_show_duration:2000},current_spot_box_width:40,event_callbacks:null,notice_boxes:null,in_tagging_mode:false,current_mode:null,tags:null,current_wizard:null,initialize:function(image_element,container,data,overall_container,options)
{this.event_callbacks={};this.tags=[];this.options=$H(this.options).update(options||{}).toObject();this.image_element=$(image_element);this.container=$(container);this.drop_zone=$(this.options.drop_zone_id);this.canvas=$(overall_container);this.data=data;this.add_all_handlers(this.canvas);if(this.image_element!=null)
{Event.observe(this.image_element,"mouseover",this.show_hovers.bindAsEventListener(this));Event.observe(this.image_element,"mouseout",this.hide_hovers.bindAsEventListener(this));}
this.tagging_success_callback=this.complete_tagging_step.bindAsEventListener(this);this.tagging_closing_callback=this.tagging_dialog_closed.bindAsEventListener(this);this.layout_hovers();this.show_hovers();this.initial_timeout=setTimeout(this.hide_hovers.bind(this),this.options.initial_show_duration);},unwire_all:function(ele)
{this.remove_all_handlers(ele);if(this.current_wizard!=null){this.current_wizard.dialog_closed();}
this.current_wizard=null;this.image_element=null;this.container=null;this.drop_zone=null;this.canvas=null;this.data=null;this.event_callbacks=null;},add_all_handlers:function(element)
{if(element==null){element=document;}
if(this.options.tag_this_selector!=null)
{if(this.event_callbacks.tag_this_handler==null){this.event_callbacks.tag_this_handler=this.tag_this_handler.bindAsEventListener(this);}
this.add_handler_for_selector(this.options.tag_this_selector,element,this.event_callbacks.tag_this_handler);}
if(this.options.add_tag_selector!=null)
{if(this.event_callbacks.add_tag_handler==null){this.event_callbacks.add_tag_handler=this.add_tag_handler.bindAsEventListener(this);}
this.add_handler_for_selector(this.options.add_tag_selector,element,this.event_callbacks.add_tag_handler);}
if(this.options.edit_tag_selector!=null)
{if(this.event_callbacks.edit_tag_handler==null){this.event_callbacks.edit_tag_handler=this.edit_tag_handler.bindAsEventListener(this);}
this.add_handler_for_selector(this.options.edit_tag_selector,element,this.event_callbacks.edit_tag_handler);}
if(this.options.cancel_tag_selector!=null)
{if(this.event_callbacks.cancel_tag_handler==null){this.event_callbacks.cancel_tag_handler=this.cancel_tag_handler.bindAsEventListener(this);}
this.add_handler_for_selector(this.options.cancel_tag_selector,element,this.event_callbacks.cancel_tag_handler);}},remove_all_handlers:function(element)
{if(element==null){element=document;}
if(this.options.tag_this_selector!=null)
{this.remove_handler_for_selector(this.options.tag_this_selector,element,this.event_callbacks.tag_this_handler);}
if(this.options.add_tag_selector!=null)
{this.remove_handler_for_selector(this.options.add_tag_selector,element,this.event_callbacks.add_tag_handler);}
if(this.options.edit_tag_selector!=null)
{this.remove_handler_for_selector(this.options.edit_tag_selector,element,this.event_callbacks.edit_tag_handler);}
if(this.options.cancel_tag_selector!=null)
{this.remove_handler_for_selector(this.options.cancel_tag_selector,element,this.event_callbacks.cancel_tag_handler);}},add_handler_for_selector:function(selector,node,handler)
{var eles=null;if(node==null||node==document){eles=$$(selector);}else{eles=node.select(selector);}
for(var i=0;i<eles.length;i++)
{Event.observe(eles[i],"click",handler);}},remove_handler_for_selector:function(selector,node,evt_handler)
{var eles=null;if(node==null||node==document){eles=$$(selector);}else{eles=node.select(selector);}
for(var i=0;i<eles.length;i++)
{Event.stopObserving(eles[i],"click",evt_handler);}},tag_this_handler:function(event)
{if(event!=null){event.stop();}
if(!CoolSpotters.LoggedInState)
{CoolSpotters.ModalDialog.mustlogin({dialog_class:'tool-container twide',modal_width:644,cancel_text:'Close'});return false;}
if(!this.in_tagging_mode){this.enter_tagging_mode();}
if(this.active_tag==null)
{var ele=event.element();var complex_name=ele.next().innerHTML.stripTags().unescapeHTML();var pm=this.data.profiles[complex_name];if(pm!=null)
{var tag=this.add_photo_tag_box(pm);this.activate_tag(tag);this.current_wizard=new CoolSpotters.MediaGallery.EditPhotoTagging(tag,this.data,false);}}},add_tag_handler:function(event)
{if(event!=null){event.stop();}
if(!CoolSpotters.LoggedInState)
{CoolSpotters.ModalDialog.mustlogin({dialog_class:'tool-container twide',modal_width:644,cancel_text:'Close'});return false;}
if(!this.in_tagging_mode){this.enter_tagging_mode();}
if(this.active_tag==null)
{var pm=this.create_new_pm();var tag=this.add_photo_tag_box(pm);this.activate_tag(tag);this.current_wizard=new CoolSpotters.MediaGallery.AddPhotoTagging(tag,this.data);}},edit_tag_handler:function(event,tag)
{if(event!=null){event.stop();}
if(!CoolSpotters.LoggedInState)
{CoolSpotters.ModalDialog.mustlogin({dialog_class:'tool-container twide',modal_width:644,cancel_text:'Close'});return false;}
if(!this.in_tagging_mode){this.enter_tagging_mode();}
if(this.active_tag==null)
{if(tag==null)
{var ele=event.element();var complex_name=ele.next().innerHTML.stripTags().unescapeHTML();tag=this.find_tag_for_complex_name(complex_name);}
this.activate_tag(tag);this.current_wizard=new CoolSpotters.MediaGallery.EditPhotoTagging(tag,this.data,true);}},layout_hovers:function()
{var profile_names=Object.keys(this.data.profiles);for(var i=0,len=profile_names.length;i<len;i++)
{var pm=this.data.profiles[profile_names[i]];if(pm.x_coord!=null&&pm.y_coord!=null&&pm.x_coord>0&&pm.y_coord>0)
{var box=this.add_photo_tag_box(pm);if(pm.id!=null)
{var el2=$(this.options.link_list_prefix+pm.id);if(el2!=null)
{Event.observe(el2,"mouseover",this.handle_link_mouseover.bindAsEventListener(this));Event.observe(el2,"mouseout",this.handle_link_mouseout.bindAsEventListener(this));}}}}},remove_hovers:function()
{},handle_link_mouseover:function(e)
{var el=e.element();if(el!=null)
{var profile_name=this.extract_complex_name_from_li_block(el);if(profile_name!=null)
{var tag=this.find_tag_for_complex_name(profile_name);if(tag!=null){tag.set_marker_on();}}}},handle_link_mouseout:function(e)
{var el=e.element();if(el!=null)
{var profile_name=this.extract_complex_name_from_li_block(el);if(profile_name!=null)
{var tag=this.find_tag_for_complex_name(profile_name);tag.set_marker_off();}}},show_hovers:function(e)
{if(e!=null){e.stop();}else{e={};}
var relTarg=$(e.relatedTarget);if(relTarg==null||!relTarg.hasClassName("tag_marker_box"))
{if(this.initial_timeout!=null){clearTimeout(this.initial_timeout);}
this.tags.each(function(pm)
{if(pm.x_coord!=-1&&pm.y_coord!=-1){pm.set_marker_on();}});}},hide_hovers:function(e)
{if(e!=null&&e.stop!=null){e.stop();}else{e={};}
var current_tag=this.active_tag;var relTarg=$(e.relatedTarget);if(relTarg==null||(!relTarg.hasClassName("tag_marker_box")&&relTarg.up(".tag_zone_box")==null&&this.in_tagging_mode!=true))
{this.tags.each(function(pm)
{if(pm!=current_tag){pm.set_marker_off();}});}},hover_tag_handler:function(event,tag,on)
{if(event!=null){event.stop();}
var el=$(this.options.link_list_prefix+tag.data.id);if(el!=null)
{if(on)
{el.addClassName("taghover");}else{el.removeClassName("taghover");}}},add_photo_tag_box:function(pm)
{if(this.image_element!=null)
{this.image_element_offsets=this.image_element.positionedOffset();}else{var dzpos=this.drop_zone.positionedOffset();this.image_element_offsets=dzpos;}
var box=new CoolSpotters.PhotoTagging.PhotoTag(pm,this.image_element,{click_callback:this.navigate_to_tag.bind(this),hover_callback:this.hover_tag_handler.bind(this),x_offset:this.image_element_offsets.left,y_offset:this.image_element_offsets.top,tags_container:this.options.tags_container});this.container.appendChild(box.element);this.tags.push(box);return box;},find_tag_for_complex_name:function(complex_name)
{var tag=null;if(this.data!=null)
{var pm=this.data.profiles[complex_name];if((pm.x_coord==-1&&pm.y_coord==-1)||this.data.medium_type=="Link")
{tag=this.add_photo_tag_box(pm);}else{for(var i=0,len=this.tags.length;i<len;i++)
{if(this.tags[i].data.profile_id==pm.profile_id)
{tag=this.tags[i];break;}}}}
return tag;},extract_complex_name_from_markup:function(element)
{if(element.hasClassName(this.options.edit_tag_selector.sub(/^\.|^#/,"")))
{var complex_name=element.next().innerHTML.stripTags().unescapeHTML();tag=this.find_tag_for_complex_name(complex_name);}},extract_complex_name_from_li_block:function(element)
{var profile_name=null;if(element.nodeName.toUpperCase()!="LI")
{element=element.up("li");}
if(element!=null)
{var spans=element.select("span[rel=profile_complex_name]")
if(spans.length>0)
{profile_name=spans[0].innerHTML.stripTags().unescapeHTML();}}
return profile_name;},activate_tag:function(tag)
{if(this.active_tag==null)
{tag.set_marker_on();tag.activate();tag.element.style.zIndex="10000"
this.active_tag=tag;Event.observe(document,"cs_wizard:success",this.tagging_success_callback);Event.observe(document,"cs_wizard:closing",this.tagging_closing_callback);}},deactivate_tag:function(tag,success)
{if(!this.in_tagging_mode||(tag!=null&&tag.data!=null&&Number(tag.data.x_coord)==-1&&Number(tag.data.y_coord==-1))){tag.set_marker_off();}
Event.stopObserving(document,"cs_wizard:success",this.tagging_success_callback);Event.stopObserving(document,"cs_wizard:closing",this.tagging_closing_callback);tag.deactivate(success);tag.element.style.zIndex="1000";this.active_tag=null;},destroy_tag:function(tag)
{this.tags=this.tags.without(tag);Effect.Fade(tag.element,{duration:0.2,afterFinish:function(obj){Element.remove(tag.element);}});},calculate_mouse_coords:function(event)
{var result=[];if(this.image_element!=null)
{var cumuImageOffsets=Element.cumulativeOffset(this.image_element);var mx=event.pointerX();var my=event.pointerY();var result=[(mx-cumuImageOffsets.left),(my-cumuImageOffsets.top)];var dzOffs=this.drop_zone.cumulativeOffset();var dzDims=this.drop_zone.getDimensions();if(mx>dzOffs[0]&&my>dzOffs[1]&&mx<dzOffs[0]+dzDims.width&&my<dzOffs[1]+dzDims.height)
{result[0]=-1;result[1]=-1;}}else{result[0]=-1;result[1]=-1;}
result.left=result[0];result.top=result[1];return result;},enter_tagging_mode:function()
{if(this.options.notice_selector!=null)
{$$(this.options.notice_selector).each(function(el){el.show();});}
if(this.tags!=null)
{if(this.image_element!=null){this.image_element_offsets=this.image_element.positionedOffset();}else{this.image_element_offsets=this.drop_zone.positionedOffset();}
var offs=this.image_element_offsets;this.tags.each(function(tag){var center=tag.current_center_coords();tag.options.x_offset=offs.left;tag.options.y_offset=offs.top;tag.move_to(center[0],center[1]);});}
if(this.image_element!=null)
{this.image_element.style.cursor="crosshair";}
this.drop_zone.style.cursor="crosshair";this.set_image_click_handler(this.handle_image_click.bindAsEventListener(this));this.in_tagging_mode=true;this.show_hovers();},exit_tagging_mode:function()
{if(this.options.notice_selector!=null)
{$$(this.options.notice_selector).each(function(el){el.hide();});}
if(this.image_element!=null){this.image_element_offsets=this.image_element.positionedOffset();}else{this.image_element_offsets=this.drop_zone.positionedOffset();}
if(this.current_wizard!=null&&this.current_wizard.dialog!=null)
{this.current_wizard.dialog.close_dialog();}
if(this.active_tag!=null)
{var tag=this.active_tag;this.deactivate_tag(tag,false);}
var offs=this.image_element_offsets;if(this.tags!=null)
{this.tags.each(function(tag){var center=tag.current_center_coords();tag.options.x_offset=offs.left;tag.options.y_offset=offs.top;tag.move_to(center[0],center[1]);});}
this.tagging_dialog_closed(null);if(this.image_element!=null)
{this.image_element.style.cursor="default";}
this.drop_zone.style.cursor="default";this.set_image_click_handler(null);this.in_tagging_mode=false;this.hide_hovers();},cancel_tag_handler:function(event)
{if(event!=null){event.stop();}
if(!this.in_tagging_mode){return;}
this.exit_tagging_mode();},complete_tagging_step:function(e)
{this.data=e.memo.success_data.profile_media_data;var coords=this.active_tag.current_center_coords();if(this.active_tag.data.complex_name==null||this.active_tag.data.complex_name==this.data["the_profile_medium"])
{this.active_tag.data=this.data.profiles[this.data["the_profile_medium"]];}
this.active_tag.data.x_coord=coords[0];this.active_tag.data.y_coord=coords[1];var llholder=$(this.options.link_list_id);if(llholder!=null)
{llholder.update(e.memo.success_data.link_list);this.add_all_handlers(llholder);this.drop_zone=$(this.options.drop_zone_id);if(this.event_callbacks.image_click_handler!=null&&this.drop_zone!=null)
{Event.observe(this.drop_zone,"click",this.event_callbacks.image_click_handler);}}},tagging_dialog_closed:function(e)
{var success=false;var destroy_tag=false;if(e!=null&&e.memo!=null)
{success=e.memo.success;if(e.memo.success_data!=null&&e.memo.success_data.destroy_tag===true)
{destroy_tag=true;}}
var tag=this.active_tag;if(tag!=null)
{this.deactivate_tag(this.active_tag,success);if(tag.unsaved()||(tag.data.x_coord==-1&&tag.data.y_coord==-1)||destroy_tag===true){this.destroy_tag(tag);}
this.hover_tag_handler(null,tag,false);}},extract_profile_id:function(source)
{var matches=source.match(/_(\d+)$/);if(matches!=null)
{return matches[1];}else{return null;}},create_new_pm:function()
{var dims=null;if(this.image_element!=null){dims=Element.getDimensions(this.image_element);}else{dims={width:-2,height:-2,0:-2,1:-2}}
var pm={profile_id:null,x_coord:dims.width/2,y_coord:dims.height/2,medium_type:this.data.medium_type,medium_id:this.data.medium_id,url:null};return pm;},handle_image_click:function(e)
{var mouse_coords=this.calculate_mouse_coords(e);if(this.active_tag==null)
{var pm=this.create_new_pm();pm.x_coord=mouse_coords.left;pm.y_coord=mouse_coords.top;var tag=this.add_photo_tag_box(pm);this.activate_tag(tag);this.current_wizard=new CoolSpotters.MediaGallery.AddPhotoTagging(tag,pm);}else{this.active_tag.move_to(mouse_coords.left,mouse_coords.top);}},set_image_click_handler:function(evtHandler)
{var img=this.image_element;if(this.event_callbacks.image_click_handler!=null)
{if(img!=null)
{Event.stopObserving(img,"click",this.event_callbacks.image_click_handler);}
Event.stopObserving(this.drop_zone,"click",this.event_callbacks.image_click_handler);}
this.event_callbacks.image_click_handler=evtHandler;if(evtHandler!=null){if(img!=null)
{Event.observe(img,"click",this.event_callbacks.image_click_handler);}
Event.observe(this.drop_zone,"click",this.event_callbacks.image_click_handler);}},navigate_to_tag:function(event,tag)
{if(event!=null){event.stop();}
if(this.in_tagging_mode)
{this.edit_tag_handler(event,tag);}else{document.location=tag.data.url;}},setDefaultFocus:function()
{if(this.active_tag!=null)
{var user_inputs=this.active_tag.element.select("input[type='text']","textarea");if(user_inputs!=null&&user_inputs.length>0)
{Form.Element.focus(user_inputs[0]);}}}});CoolSpotters.MediaGallery.Gallery=Class.create({options:{page:1,medium_id:null,gallery_pane:"gallery_content_pane",inner_pane:"gallery_inner_pane",comment_wrapper:"comment_hide_block",comment_content:"discussion_holder",comments_header:"comment_header_element",carousel_holder:"carousel_holder",page_indicator:"gal_indicator",carousel_indicator:"carousel_indicator",sheet_template_add:".js?page=#{page}",medium_template_add:"/#{medium_id}.js",carousel_template_add:"/#{medium_id}/scroll_page.js?direction=#{direction}&selected_id=#{selected_id}",image_element_id:"media_photo_element",tagging_container:"photo_tagging_container",load_medium:true,related_profile_data:null},url_base:null,pagination_handler:null,sheet_handler:null,image_click_handler:null,next_image_handler:null,prev_image_handler:null,current_page_hash:null,page_success_handler:null,transport_error_handler:null,in_sheet_view:null,clear_status_func:function(e){window.status="";},initialize:function(url_base,options)
{this.options=$H(this.options).update(options||{}).toObject();this.sheet_url_template=new Template(url_base+this.options.sheet_template_add);this.medium_url_template=new Template(url_base+this.options.medium_template_add);this.carousel_url_template=new Template(url_base+this.options.carousel_template_add);this.sheet_url_standard_template=new Template(url_base+'#page-#{page}')
this.medium_url_standard_template=new Template(url_base+'#medium-#{medium_id}')
this.gallery_pane=$(this.options.gallery_pane);this.inner_pane=$(this.options.inner_pane);this.page_success_handler=this.handle_new_page_loaded.bind(this);this.image_success_handler=this.handle_new_image_loaded.bind(this);this.transport_error_handler=this.transport_error.bind(this);this.transport_complete_handler=this.transport_complete.bind(this);this.carousel_success_handler=this.handle_carousel_page_loaded.bind(this);this.image_click_handler=this.load_single_image_click.bindAsEventListener(this);this.url_base=url_base;var initial_hash=window.location.hash;if(initial_hash==null||initial_hash=="")
{if(this.options.medium_id!=null){initial_hash="#medium-"+this.options.medium_id;}else{initial_hash="#page-1"}}
if(this.options.load_medium)
{this.route_hash(initial_hash);}
else
{this.route_loaded_hash(initial_hash);}
if(Prototype.Browser.WebKit)
{this.hash_change_checker=new PeriodicalExecuter(function(pe){if(window.location.hash!=this.current_page_hash)
{this.route_hash(window.location.hash);}}.bind(this),0.25);}},parse_hash:function(hash)
{var match_data=hash.match(/#?(\w+)-(\d+)(?:-(\d+))?/);return match_data;},route_hash:function(anchor_hash)
{if(anchor_hash!=null&&anchor_hash!="")
{if(anchor_hash.charAt(0)!='#'){anchor_hash="#"+anchor_hash;}
var page_state=this.parse_hash(anchor_hash);if(page_state!=null&&page_state.length>2)
{if(page_state[1]=="page")
{this.load_sheet_page(page_state[2]);this.set_new_hash(anchor_hash);}else if(page_state[1]=="medium")
{this.load_single_page(page_state[2]);this.set_new_hash(anchor_hash);}else if(page_state[1]=="forward"||page_state[1]=="back")
{this.load_carousel_page(page_state[1],page_state[2],page_state[3]);}}
else
{this.load_sheet_page(1);this.set_new_hash("#page-1");}}},route_loaded_hash:function(anchor_hash)
{if(anchor_hash!=null&&anchor_hash!="")
{if(anchor_hash.charAt(0)!='#'){anchor_hash="#"+anchor_hash;}
var page_state=this.parse_hash(anchor_hash);this.related_data=this.options.profile_media_data;this.wire_page();this.set_new_hash(anchor_hash);this.in_sheet_view=false;}
this.options.load_medium=true;},set_new_hash:function(new_hash)
{this.current_page_hash=new_hash;window.location.replace(new_hash);},route_redirect:function(new_hash,page_state)
{hash_loc=window.location.href.indexOf('#')
just_url=(hash_loc>0?window.location.href.substring(0,hash_loc):window.location.href);if(just_url!=this.url_base)
{if(page_state[1]=="page")
{window.location.href=this.sheet_url_standard_template.evaluate({"page":page_state[2]});return false;}
else if(page_state[1]=="medium")
{window.location.href=this.medium_url_standard_template.evaluate({"medium_id":page_state[2]});return false;}}
return true;},wire_page:function()
{var handler=this.image_click_handler;var status_handler=this.clear_status_func;this.gallery_pane.select("a").each(function(el){if(!$(el).hasClassName("gallery_ignore"))
{Event.observe(el,"click",handler);Event.observe(el,"mouseover",status_handler);Event.observe(el,"mouseout",status_handler);el.href="javascript:void(0);"}});if(this.in_sheet_view===false)
{this.current_tagger=new CoolSpotters.PhotoTagger(this.options.image_element_id,this.options.tagging_container,this.related_data,this.inner_pane,{tags_container:this.options.tagging_container});}},wire_carousel:function()
{var handler=this.image_click_handler;var status_handler=this.clear_status_func;$(this.options.carousel_holder).select("a").each(function(el){if(!$(el).hasClassName("gallery_ignore"))
{Event.observe(el,"click",handler);Event.observe(el,"mouseover",status_handler);Event.observe(el,"mouseout",status_handler);el.href="javascript:void(0);"}});},unwire_page:function()
{var handler=this.image_click_handler;var status_handler=this.clear_status_func;this.gallery_pane.select("a").each(function(el){if(!el.hasClassName("gallery_ignore"))
{Event.stopObserving(el,"click",handler);Event.stopObserving(el,"mouseover",status_handler);Event.stopObserving(el,"mouseout",status_handler);}});if(this.in_sheet_view===false)
{if(this.current_tagger!=null){this.current_tagger.unwire_all(this.inner_pane);}
this.current_tagger=null;}},load_single_image_click:function(e)
{if(e!=null){e.stop();}
var element=Event.element(e);if(element.nodeName.toLowerCase()!="a")
{element=element.up("a");}
if(element.rel!=null){this.route_hash(element.rel);}
return false;},setup_tagger:function()
{},begin_page_transition:function(next_step)
{this.gallery_pane.makeClipping();this.gallery_pane.style.height=this.inner_pane.getHeight()+"px";this.inner_pane.setOpacity(0.0);next_step();},finish_page_transition:function()
{this.gallery_pane.undoClipping();this.gallery_pane.style.height="auto";var teffect=new Effect.Opacity(this.inner_pane,{from:0.0,to:1.0,duration:0.1,queue:{position:"end",scope:"coolspotters-gallery"}});this.wire_page();},begin_image_transition:function(next_step)
{this.gallery_pane.makeClipping();this.gallery_pane.style.height=this.inner_pane.getHeight()+"px";var effects=this.gallery_pane.select('.hide_on_transition').each(function(ele){ele.setOpacity(0.0);});next_step();},finish_image_transition:function()
{this.gallery_pane.undoClipping();this.gallery_pane.style.height="auto";var effects=this.gallery_pane.select('.hide_on_transition').collect(function(ele){return new Effect.Opacity(ele,{sync:true,from:0.0,to:1.0});});var teffect=new Effect.Parallel(effects,{duration:0.1,queue:{position:"end",scope:"coolspotters-gallery"}});this.wire_page();},show_when_content_ready:function(method)
{var ims=this.inner_pane.select("img");if(ims!=null&&ims.length>0)
{var total=ims.length;var eh=function(e){total--;if(total==0)
{this.animate_and_show(should_show);}}.bindAsEventListener(this);ims.each(function(el){Event.observe(el,"load",eh);});}else{this.animate_and_show(should_show);}},animate_window_resize:function(finish_transition)
{var core_anim_duration=0.15;var teffect=new Effect.Morph(this.gallery_pane,{duration:core_anim_duration,queue:{position:"end",scope:"coolspotters-gallery"},style:{height:this.inner_pane.getHeight()+"px"},afterFinish:finish_transition});},load_sheet_page:function(page)
{if(this.current_request!=null){return;}
req_opts={asynchronous:true,evalJS:false,method:'get',onFailure:this.transport_error_handler,onComplete:this.transport_complete_handler}
if(this.in_sheet_view!==true)
{req_opts.onSuccess=this.page_success_handler;var carousel_loader=$(this.options.carousel_indicator);if(carousel_loader!=null){carousel_loader.addClassName("loading");}}else{req_opts.onSuccess=this.image_success_handler;var loader=$(this.options.page_indicator);if(loader!=null){loader.addClassName("loading");}}
this.unwire_page();this.current_request=new Ajax.Request(this.sheet_url_template.evaluate({"page":page}),req_opts);this.in_sheet_view=true;},load_single_page:function(medium_id)
{if(this.current_request!=null){return;}
req_opts={asynchronous:true,evalJS:false,method:'get',onFailure:this.transport_error_handler,onComplete:this.transport_complete_handler}
if(this.in_sheet_view===true)
{req_opts.onSuccess=this.page_success_handler;}else{req_opts.onSuccess=this.image_success_handler;}
var loader=$(this.options.page_indicator);if(loader!=null){loader.addClassName("loading");}
this.unwire_page();this.current_request=new Ajax.Request(this.medium_url_template.evaluate({"medium_id":medium_id}),req_opts);this.in_sheet_view=false;},load_carousel_page:function(direction,medium_id,selected_id)
{if(this.current_request!=null){return;}
this.last_carousel_turn=direction;req_opts={asynchronous:true,evalJS:false,method:'get',onSuccess:this.carousel_success_handler,onFailure:this.transport_error_handler,onComplete:this.transport_complete_handler}
var carousel_loader=$(this.options.carousel_indicator);if(carousel_loader!=null){carousel_loader.addClassName("loading");}
this.current_request=new Ajax.Request(this.carousel_url_template.evaluate({"medium_id":medium_id,"direction":direction,"selected_id":selected_id}),req_opts);},handle_new_page_loaded:function(transport)
{var data=transport.responseText.evalJSON();this.related_data=data.profile_media_data;this.begin_page_transition(function(){this.inner_pane.style.height="auto";this.inner_pane.update(data.canvas);this.animate_window_resize(this.finish_page_transition.bind(this));this.set_comments(data)}.bind(this));},handle_new_image_loaded:function(transport)
{var data=transport.responseText.evalJSON();this.related_data=data.profile_media_data;this.begin_image_transition(function(){this.inner_pane.setOpacity(0.0);this.inner_pane.style.height="auto";this.inner_pane.update(data.canvas);var effects=this.gallery_pane.select('.hide_on_transition').each(function(ele){ele.setOpacity(0.0);});this.inner_pane.setOpacity(1.0);this.animate_window_resize(this.finish_image_transition.bind(this));this.set_comments(data);}.bind(this));},handle_carousel_page_loaded:function(transport)
{var data=transport.responseText.evalJSON();try{$(this.options.carousel_holder).update(data.carousel_content);this.wire_carousel();}catch(e)
{}},set_comments:function(data)
{if(data!=null)
{if(data.comments===false)
{if(this.options.comment_wrapper!=null&&$(this.options.comment_wrapper)!=null)
{$(this.options.comment_wrapper).hide();}
if(this.options.comment_content!=null&&$(this.options.comment_content)!=null)
{$(this.options.comment_content).update("");}}
else
{if(this.options.comment_wrapper!=null&&$(this.options.comment_wrapper)!=null)
{$(this.options.comment_wrapper).show();}
if(data.comments!=null){if(this.options.comments_header!=null&&$(this.options.comments_header)!=null)
{$(this.options.comments_header).update(data.comments_header);}
if(this.options.comment_content!=null&&$(this.options.comment_content)!=null)
{$(this.options.comment_content).update(data.comments);}}}}},transport_error:function(transport)
{alert("There wasn an unexpected error loading the gallery.  Please try again.");},transport_complete:function(transport)
{this.current_request=null;var loader=$(this.options.page_indicator);if(loader!=null){loader.removeClassName("loading");}
var carousel_loader=$(this.options.carousel_indicator);if(carousel_loader!=null){carousel_loader.removeClassName("loading");}}});CoolSpotters.CSDiscussions=Class.create();CoolSpotters.CSDiscussions.prototype={discussion_form_html:null,discussion_container:null,comments_url:null,options:{method:"get",reply_link_class:"reply_link",edit_link_class:"edit_link",new_link_class:"post-new",new_link_nested:true,report_link_class:"report_link",includeActivityFeed:false,autogrow_textareas:true,form_element_id:"moveable_discussion_form",parent_id_field:"reply_parent_id_field",cancel_class:"post-cancel",cancel_link_nested:true,submit_class:"post-comment",return_url_field:"return_url",param_name:'p',pagination_loader:'.paginator_loader',discussion_header:'comment_header'},form_element:null,parent_id_field:null,discussion_form_element:null,resizeable_controller:null,in_edit_mode:false,swapped_content:null,textarea:null,post_new_bottom:$('post_new_bottom'),initialize:function(url,discussion_container,discussion_form_html,post_new_bottom,options)
{this.options=$H(this.options).update(options||{}).toObject();this.discussion_form_html=discussion_form_html;this.discussion_container=$(discussion_container);this.comments_url=url;this.post_new_bottom=post_new_bottom;this.createFormControl();this.wireUpComments();this.wireUpPagination();},wireUpComments:function()
{var reply_links=this.discussion_container.getElementsBySelector("a.reply_link");this.post_new_bottom=$('post_new_bottom');if(reply_links!=null)
{var this_class=this;$A(reply_links).each(function(ele,index){Event.observe(ele,"click",this_class.reply_link_clicked.bindAsEventListener(this_class));});}
var edit_links=this.discussion_container.getElementsBySelector("a.edit_link");if(edit_links!=null)
{var this_class=this;$A(edit_links).each(function(ele,index){Event.observe(ele,"click",this_class.edit_link_clicked.bindAsEventListener(this_class));});}
var report_links=this.discussion_container.getElementsBySelector("a.report_link");if(report_links!=null)
{var this_class=this;report_links.each(function(ele,index){Event.observe(ele,"click",this_class.report_link_clicked.bindAsEventListener(this_class));});}
var delete_links=this.discussion_container.getElementsBySelector("a.delete_link");if(delete_links!=null)
{var this_class=this;delete_links.each(function(ele,index){Event.observe(ele,"click",this_class.delete_link_clicked.bindAsEventListener(this_class));});}
var post_news=this.discussion_container.getElementsBySelector(".post-new");if(post_news!=null)
{var this_class=this;var new_link_nested=this.options.new_link_nested;$A(post_news).each(function(ele,index){if(new_link_nested)
ele=ele.down(0);Event.observe(ele,"click",this_class.new_comment_link_clicked.bindAsEventListener(this_class));});}
var post_new_link=$('post_new_comment_link')
if(post_new_link!=null)
{Event.observe(post_new_link,"click",this_class.new_comment_link_clicked.bindAsEventListener(this_class));}},createFormControl:function()
{this.discussion_form_element=$(document.createElement("div"));this.discussion_form_element.id=this.options.form_element_id;this.form_element=$(document.createElement("form"));this.form_element.action=this.comments_url;this.form_element.method="post";this.form_element.innerHTML=this.discussion_form_html;this.discussion_form_element.appendChild(this.form_element);var tas=this.discussion_form_element.getElementsByTagName("textarea");if(tas!=null&&tas.length>0)
{this.textarea=tas[0];this.resizeable_controller=new ResizeableTextarea(this.textarea);}
var inputs=this.form_element.getElementsByTagName("input");for(var k=0;k<inputs.length;k++)
{if(inputs[k].id==this.options.parent_id_field)
{this.parent_id_field=inputs[k];}else if(inputs[k].id==this.options.return_url_field)
{this.return_url_field=inputs[k];}}
this.submit_button=this.form_element.getElementsBySelector("."+this.options.submit_class)[0];Event.observe(this.submit_button,"click",this.submit_clicked.bindAsEventListener(this));this.return_url_field.value=document.location;},remove_form:function()
{if(this.discussion_form_element.parentNode!=null){if(this.in_edit_mode)
{this.discussion_form_element.hide();this.discussion_form_element.insert({after:this.swapped_content});this.swapped_content.show();var input=this.form_element.down(0);if(input.name=="_method")
{input.remove();}
this.form_element.action=this.comments_url;this.discussion_form_element.remove();this.textarea.removeClassName("ajaxload1");this.discussion_form_element.removeClassName("tier2");this.in_edit_mode=false;}else{this.discussion_form_element.remove();this.discussion_form_element.removeClassName("tier2");}
this.resizeable_controller.reset();}},add_form:function(target,position,parent_id)
{this.parent_id_field.value=parent_id
this.textarea.value="";var hash={};hash[position]=this.discussion_form_element;$(target).insert(hash);this.discussion_form_element.show();this.cancel_link=this.form_element.getElementsBySelector("."+this.options.cancel_class)[0];if(this.options.cancel_link_nested)
this.cancel_link=this.cancel_link.down(0);Event.observe(this.cancel_link,"click",this.cancel_clicked.bindAsEventListener(this));this.hidePostNewLinks();if(this.textarea!=null)
this.textarea.focus();this.comment_errors=$('comment-errors');this.comment_errors.hide();this.submit_button.up('span').className='form-btn-disabled';this.form_validator=new CoolSpotters.SimpleValidator(this.textarea,this.submit_button,{submit_enable_style:'form-btn',submit_disable_style:'form-btn-disabled'});this.form_interceptor=new CoolSpotters.FormButtonInterceptor(this.submit_button,{loading_text:'Posting',old_label:'Post!',add_style:'form-btn-ajax',remove_style:''});},enter_edit_mode:function(target_comment)
{if(target_comment!=null)
{var comment_id=this.parse_comment_id(target_comment);this.form_element.action=this.comments_url+"/"+comment_id;this.form_element.insert({top:"<input type=\"hidden\" name=\"_method\" value=\"put\" />"});target_comment.hide();if(target_comment.hasClassName("tier2"))
this.discussion_form_element.addClassName("tier2");this.cancel_link=this.form_element.getElementsBySelector("."+this.options.cancel_class)[0];if(this.options.cancel_link_nested)
this.cancel_link=this.cancel_link.down(0);Event.observe(this.cancel_link,"click",this.cancel_clicked.bindAsEventListener(this));target_comment.insert({before:this.discussion_form_element});this.textarea.value="";this.resizeable_controller.reset();this.discussion_form_element.show();this.textarea.addClassName("ajaxload1");this.swapped_content=target_comment.remove();this.in_edit_mode=true;this.hidePostNewLinks();this.form_interceptor=new CoolSpotters.FormButtonInterceptor(this.submit_button,{loading_text:'Posting',old_label:'Post!',add_style:'form-btn-ajax',remove_style:'form-btn',nested_buttons:true,ajax_special:true});new Ajax.Request(this.comments_url+"/"+comment_id+"/edit.js",{method:"get",onSuccess:this.received_edit_data.bind(this),onFailure:this.ajax_error.bind(this),onComplete:this.ajax_complete.bind(this)});}},received_edit_data:function(transport)
{var data=transport.responseText.evalJSON(true);this.textarea.value=data["comment"];this.parent_id_field.value=data["parent_id"];this.resizeable_controller.resize();},ajax_error:function(transport)
{alert("There was an error loading your comment for edit");this.remove_form();},ajax_complete:function(transport)
{this.textarea.removeClassName("ajaxload1");this.resizeable_controller.resize();this.textarea.focus();},ajax_submit_error:function(transport)
{alert("There was a problem submitting your comment.");},ajax_submit_complete:function(transport)
{if(this.form_interceptor!=null)
{this.form_interceptor.toggle();this.form_interceptor.unwire_events();}
this.form_interceptor=null;if(this.form_validator!=null)
this.form_validator.halt();this.form_validator=null;this.showPostNewLinks();this.textarea.removeClassName("ajaxload1");this.resizeable_controller.reset();this.remove_form();},parse_comment_id:function(element)
{var edit_link=element.getElementsBySelector('a.edit_link')[0]
var matches=edit_link.href.match(/\/(\d+)\/edit/);if(matches!=null&&matches.length>=2)
{return matches[1];}
else
{return null;}},parse_reply_comment_id:function(element)
{var matches=element.id.match(/(\d+)/);if(matches!=null&&matches.length>=2)
{return matches[0];}
else
return null;},reply_link_clicked:function(e)
{if(e!=null)
e.stop();this.hidePostNewLinks();this.remove_form();this.discussion_form_element.addClassName("tier2");var element=e.element();var target_comment=element.up(".post");var positioning_element=target_comment;var position="before";var parent_id=null;if(target_comment!=null)
{if(target_comment.hasClassName("tier2"))
{while(target_comment.hasClassName("tier2"))
{if(target_comment.previous("div.post"))
{target_comment=target_comment.previous("div.post");}
else
{target_comment=target_comment.up().previous();break;}}
last_reply=null;while(positioning_element!=null&&positioning_element.hasClassName("tier2"))
{last_reply=positioning_element;positioning_element=positioning_element.next(".post");}
if(positioning_element==null)
{positioning_element=last_reply;position="after";}}else{positioning_element=target_comment.next(".post");last_reply=target_comment;while(positioning_element!=null&&positioning_element.hasClassName("tier2"))
{last_reply=positioning_element;positioning_element=positioning_element.next(".post");}
if(positioning_element==null)
{positioning_element=last_reply;position="after";}}
parent_id=this.parse_reply_comment_id(target_comment);this.add_form(positioning_element,position,parent_id);}},edit_link_clicked:function(e)
{if(e!=null)
e.stop();this.remove_form();var element=e.element();var target_comment=element.up(".post");if(target_comment!=null)
{this.enter_edit_mode(target_comment);}},delete_link_clicked:function(e)
{if(e!=null)
e.stop();ele=Event.element(e);if(ele!=null)
{new Ajax.Request(ele.href,{method:'get'});}},report_link_clicked:function(e)
{if(e!=null)
e.stop();},new_comment_link_clicked:function(e)
{if(e!=null)
{ele=Event.element(e);e.stop();}
if(!CoolSpotters.LoggedInState)
{CoolSpotters.ModalDialog.mustlogin({dialog_class:'tool-container twide',modal_width:644,mustlogin_action:"Comments",cancel_text:'Close'});return false;}
this.remove_form();var links=this.discussion_container.getElementsBySelector("."+this.options.new_link_class);if(links!=null&&links.length>0)
{this.add_form(links[links.length-1],"after",null);this.resizeable_controller.reset();}
if(ele.id=='post_new_comment_link')
{Effect.ScrollTo(this.form_element,{offset:-20})}
return false;},cancel_clicked:function(e)
{if(e!=null)
e.stop();this.remove_form();this.showPostNewLinks();if(this.form_validator!=null)
this.form_validator.halt();this.form_validator=null;this.resizeable_controller.resize();},submit_clicked:function(e)
{if(e!=null)
e.stop();var ele=Event.element(e);var comment_url=null;var comment_id=this.parse_comment_id_from_action(ele.form.action);if(this.in_edit_mode)
comment_url=this.comments_url+"/"+comment_id;else
comment_url=this.comments_url;new Ajax.Request(comment_url,{method:"post",parameters:Form.serialize(this.discussion_form_element),onFailure:this.ajax_submit_error.bind(this),onComplete:this.ajax_submit_complete.bind(this)});},attachLinkEvents:function(comment_id)
{var comment_element=$('comment_id_'+comment_id)
var reply_links=comment_element.getElementsBySelector("a.reply_link");if(reply_links!=null)
{var this_class=this;$A(reply_links).each(function(ele,index){Event.observe(ele,"click",this_class.reply_link_clicked.bindAsEventListener(this_class));});}
var edit_links=comment_element.getElementsBySelector("a.edit_link");if(edit_links!=null)
{var this_class=this;$A(edit_links).each(function(ele,index){Event.observe(ele,"click",this_class.edit_link_clicked.bindAsEventListener(this_class));});}
var report_links=comment_element.getElementsBySelector("a.report_link");if(report_links!=null)
{var this_class=this;report_links.each(function(ele,index){Event.observe(ele,"click",this_class.report_link_clicked.bindAsEventListener(this_class));});}
var delete_links=comment_element.getElementsBySelector("a.delete_link");if(delete_links!=null)
{var this_class=this;delete_links.each(function(ele,index){Event.observe(ele,"click",this_class.delete_link_clicked.bindAsEventListener(this_class));});}},wireUpPagination:function()
{var comment_navs=$$("div#comments-nav");if(comment_navs!=null)
{var this_class=this;$A(comment_navs).each(function(ele,index){var pagination_links=ele.getElementsBySelector("a.page");if(pagination_links!=null)
{$A(pagination_links).each(function(ele,index){Event.observe(ele,"click",this_class.pagination_link_clicked.bindAsEventListener(this_class));});}});}},pagination_link_clicked:function(e)
{if(e!=null)
e.stop();var ele=Event.element(e);comment_pg=this.parse_comment_page(ele.href);loader=$$(this.options.pagination_loader);if(loader!=null)
loader[0].show();new Ajax.Request(this.comments_url,{method:"get",parameters:{'p':comment_pg},onComplete:this.afterPaginate.bind(this)});},parse_comment_page:function(str)
{var matches=str.match(/p=(\d+)/);if(matches!=null&&matches.length>=2)
return matches[1];else
return null;},parse_comment_id_from_action:function(str)
{var matches=str.match(/comments\/(\d+)/);if(matches!=null&&matches.length>=2)
return matches[1];else
return null;},afterPaginate:function()
{loader=$$(this.options.pagination_loader);if(loader!=null)
loader[0].hide();this.wireUpComments();this.wireUpPagination();Effect.ScrollTo(this.options.discussion_header);},showPostNewLinks:function()
{if(this.post_new_bottom!=null)
this.post_new_bottom.show();},hidePostNewLinks:function()
{if(this.post_new_bottom!=null)
this.post_new_bottom.hide();}};