CoolSpotters.SpotPopOverRevised=Class.create({mPopoverTriggerElements:null,mPopoverTriggerSelector:null,mMouseOutTimers:null,initialize:function(trigger,profile_trigger)
{this.mPopoverTriggerSelector=trigger;this.mPopoverTriggerElements=$$(trigger);this.mMouseOutTimers=new Hash();for(i=0;i<this.mPopoverTriggerElements.length;i++)
{Event.observe(this.mPopoverTriggerElements[i],"mouseover",this.switchToSpot.bindAsEventListener(this));Event.observe(this.mPopoverTriggerElements[i],"mouseout",this.switchToProfile.bindAsEventListener(this));}
this.mProfileTrigger=profile_trigger;this.mProfileTriggerElements=$$(profile_trigger);for(i=0;i<this.mProfileTriggerElements.length;i++)
{Event.observe(this.mProfileTriggerElements[i],"mouseover",this.switchToSpotDescription.bindAsEventListener(this));Event.observe(this.mProfileTriggerElements[i],"mouseout",this.switchToDefault.bindAsEventListener(this));}},switchToSpot:function(e)
{if(e!=null)
e.stop();var ele=Event.element(e);var popover_link=null;if(Element.match(ele,this.mPopoverTriggerSelector))
{popover_link=ele}else{possibility=ele.up(this.mPopoverTriggerSelector)
if(possibility)
{popover_link=possibility}}
if(popover_link!=null&&popover_link!=undefined)
{this.change_view_to(popover_link,true,false);}},switchToProfile:function(e)
{if(e!=null)
{e.stop();ele=Event.element(e);if(ele!=null&&ele!=undefined)
{var ele_popover=null;var related=null;if(Element.match(ele,this.mPopoverTriggerSelector))
{ele_popover=ele}else{possibility=ele.up(this.mPopoverTriggerSelector)
if(possibility)
{ele_popover=possibility}}
if(e.relatedTarget!=null)
{related=e.relatedTarget;if(!Element.match(related,this.mPopoverTriggerSelector))
{possibility=related.up(this.mPopoverTriggerSelector)
if(possibility)
{related=possibility;}}}
if(ele_popover!=null&&related!=null&&related.id!=ele_popover.id)
{this.change_view_to(ele_popover,false,false);}}}},switchToSpotDescription:function(e)
{var ele=Event.element(e);this.change_view_to(ele,false,true);},switchToDefault:function(e)
{var ele=Event.element(e);this.change_view_to(ele,false,false);},change_view_to:function(ele,spot,description)
{var spot_id=this.parseSpotId(ele.id);var pdele=$('profile_description_'+spot_id);var sdele=$('spot_text_'+spot_id);var spot_box=$('spot_image_'+spot_id);var spot_desc=$('spot_description_info_'+spot_id);var spot_link=$('spot_link_'+spot_id);if(spot===true)
{pdele.style.display="none";sdele.style.display="block";if(spot_box.down("img")!=null)
{spot_box.style.zIndex=100;spot_box.style.display="block";}else if(!spot_desc.empty()){spot_desc.style.display="block";spot_link.addClassName('viewinfo-over');}}else if(description===true)
{pdele.style.display="block";sdele.style.display="none";spot_box.hide();spot_desc.style.display="block";}else{pdele.style.display="block";sdele.style.display="none";spot_link.removeClassName('viewinfo-over');spot_box.hide();spot_desc.hide();}},safeSetTimeout:function(name,func,timeout)
{var existing_val=this.mMouseOutTimers.get(name);if(existing_val!=null)
{clearTimeout(existing_val);}
this.mMouseOutTimers.set(name,setTimeout(func,timeout));},safeDeleteTimeout:function(name)
{var existing_val=this.mMouseOutTimers.unset(name);if(existing_val!=null)
{clearTimeout(existing_val);}},parseSpotId:function(str)
{matches=str.match(/(\d+)/);if(matches!=null&&matches.length>=2)
{return matches[1];}
else
return null;},reattachEvents:function(ele)
{popoverElementsToAttach=null;descriptionElementsToAttach=null;if(ele!=null)
{popoverElementsToAttach=ele.select(this.mPopoverTriggerSelector);this.mPopoverTriggerElements=$$(this.mPopoverTriggerSelector);descriptionElementsToAttach=ele.select(this.mProfileTrigger);this.mProfileTriggerElements=$$(this.mProfileTrigger);}
else
{elementsToAttach=this.mPopoverTriggerElements=$$(this.mPopoverTriggerSelector);descriptionElementsToAttach=this.mProfileTriggerElements=$$(this.mProfileTrigger);}
for(i=0;i<popoverElementsToAttach.length;i++)
{popoverElementsToAttach[i].identify();Event.observe(popoverElementsToAttach[i],"mouseover",this.switchToSpot.bindAsEventListener(this));Event.observe(popoverElementsToAttach[i],"mouseout",this.switchToProfile.bindAsEventListener(this));}
for(j=0;j<descriptionElementsToAttach.length;j++)
{Event.observe(descriptionElementsToAttach[j],"mouseover",this.switchToSpotDescription.bindAsEventListener(this));Event.observe(descriptionElementsToAttach[j],"mouseout",this.switchToDefault.bindAsEventListener(this));}}});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.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();}};CoolSpotters.ProfileEditor=Class.create();CoolSpotters.ProfileEditor.prototype={nameElement:null,observeNameElement:false,initialValue:null,nameFormElement:null,cancelElement:null,resizer:null,initialize:function(nameElement,observeName,nameFormElement,namePrompt,elementResizer)
{this.nameElement=$(nameElement);this.observeNameElement=observeName;this.nameFormElement=$(nameFormElement);this.namePrompt=$(namePrompt);if(elementResizer!=null)
this.resizer=elementResizer;if(this.observeNameElement)
{this.initialValue=this.nameElement.value;Event.observe(this.nameElement,'keyup',this.handleChange.bindAsEventListener(this));Event.observe(this.nameElement,'focus',this.handleChange.bindAsEventListener(this));}},handleClick:function(e)
{if(!this.nameFormElement.visible())
this.nameFormElement.show();},handleChange:function(e)
{if(this.nameElement.value!=this.initialValue)
{if(this.resizer!=null)
this.resizer.resize();if(!this.nameFormElement.visible())
{this.nameFormElement.show();}
if(this.namePrompt!=null&&!this.namePrompt.visible())
this.namePrompt.show();}
else
{this.nameFormElement.hide();if(this.namePrompt!=null)
this.namePrompt.hide();}},hasChanges:function()
{return this.nameElement.value!=this.initialValue;}};CoolSpotters.TabManager=Class.create({locked:false,initialize:function()
{this.locked=false;},lock:function()
{this.locked=true;},unlock:function()
{this.locked=false;},unlocked:function()
{return!this.locked;},locked:function()
{return this.locked;}});CoolSpotters.TabController=Class.create({manager:null,tabs:null,initialize:function()
{this.manager=new CoolSpotters.TabManager();this.tabs=[];},addTab:function(tab)
{tab.addManager(this.manager);this.tabs.push(tab);},resize:function(tab)
{this.tabs.each(function(t){t.resize();});}});CoolSpotters.Tab=Class.create({element:null,tab_element:null,container:null,manager:null,initialize:function(element,tab_element,container)
{this.element=$(element);this.tab_element=$(tab_element);this.container=$(container);Event.observe(this.element,"click",this.handle_click.bindAsEventListener(this));},handle_click:function(e)
{if(e!=null)
{e.stop();}
var manager=this.manager;if(!this.tab_element.visible()&&manager.unlocked())
{manager.lock();var tab_dimensions=this.tab_element.getDimensions();var current_tab_header=$$('li a.selected').first();var current_tab=this.container.getElementsBySelector('div.visible_tab')[0];current_tab_header.removeClassName('selected');current_tab.removeClassName('visible_tab');this.element.addClassName('selected');var tab=this.tab_element;var container=this.container;var tooltip=$('tooltip-holder');if(tooltip!=null)
tooltip.hide();current_tab.hide();this.effect=new Effect.Morph(container,{duration:0.4,style:{height:tab_dimensions.height+'px'},afterFinish:function(effect){tab.show();tab.addClassName('visible_tab');manager.unlock();}});}},addManager:function(mgr)
{this.manager=mgr;},resize:function()
{if(this.tab_element.visible())
{var tab_dimensions=this.tab_element.getDimensions();var container=this.container;this.effect=new Effect.Morph(container,{duration:0.4,style:{height:tab_dimensions.height+'px'}});}}});CoolSpotters.DetailToggle=Class.create({options:{hide_text:'Less about me',show_text:'More about me'},initialize:function(ele,targ,options)
{this.element=$(ele);this.target_element=$(targ);this.options=this.options=$H(this.options).update(options||{}).toObject();Event.observe(this.element,'click',this.on_click.bindAsEventListener(this));},on_click:function(e)
{if(e!=null)
{e.stop();}
if(this.in_progress)
{return false;}
else
{element=this.element;if(this.target_element.visible())
{element=this.element;show_text=this.options.show_text
this.target_element.blindUp({duration:0.2,queue:{position:'end',scope:'description_scope'},afterFinish:function(){element.innerHTML=show_text;}});}
else
{element=this.element;hide_text=this.options.hide_text;this.target_element.blindDown({duration:0.2,queue:{position:'end',scope:'description_scope'},afterFinish:function(){element.innerHTML=hide_text;}});}}}})