/* init/init_entity
 
@author Jacob at Goby
 @version 02/07/12
@svn goby_-150
*/

function Entity(data,widgets)
{for(var i in data)
this[i]=data[i];if(data.facets)
this.title=data.facets.title;this.widgets=widgets;this.renderWidgets();if(Goby.conf('USE_LOGIN'))
{if(!this.timeSensitive)
this.renderRating();this.renderShare();this.renderSave();}
objects.push(this);}
Entity.prototype={getID:function()
{return this.id;},renderWidgets:function()
{this.widgetSet=new WidgetMgr(this.widgets.left);this.widgetSet_r=new WidgetMgr(this.widgets.right);},imbue:function()
{},selectWidget:function(id)
{if(id=="edit")
return this.edit();var widget=this.widgetSet.getWidget(id);$(window).scrollTo(widget.anchor,600,{easing:'easeOutCubic'});},edit:function(){window.location=Goby.conf('path.base')+"/edit-listing/"+this.getID()+"/"+this.title.urlEncode();},getCategories:function()
{return this.categorySet;},getPrimaryCategory:function()
{for(mainCat in this.getCategories())break;return this.getCategories()[mainCat];},updateRating:function(data){this.ratingForm.ende(data,1);this.ratingForm.fields.rating.setValue(data.info.mine);},updateReview:function(data){this.widgetSet.getWidget('reviews')?this.widgetSet.getWidget('reviews').updateRating(data):null;},renderRating:function()
{var node=$("#facet_rating").get(0);if(node)
{$(node).html('');var ratingParams={values:{rating:this.rating.mine>0?this.rating.mine:null,entityID:this.getID()},avg:this.overallRating.average>0?this.overallRating.average:0,overallTotal:this.overallRating.totalNumberOfRatings>0?this.overallRating.totalNumberOfRatings:0,total:this.overallRating.totalNumberOfRatings>0?this.overallRating.totalNumberOfRatings:0};this.ratingForm=new RatingForm(ratingParams,this);node.appendChild(this.ratingForm);node=null;}},type:'entity',share:function(option)
{switch(option.value)
{case"email":trackEvent([PAGE_ID,'share_email'],2);var body="I found "+this.title+" here on Goby.com:\n"
+this.url+"\n\n"
+"This site has lots of great ideas for things to do. You should check it out!";window.location="mailto:?subject="+encodeURIComponent(this.title)+"&body="
+encodeURIComponent(body);return false;break;case"facebook":postEntityToNewsFeed({link:this.url,title:this.title});return false;break;case"twitter":var href="http://twitter.com/?status="+encodeURIComponent("Check this out (via Goby.com): "+this.title+"\n"+this.url);window.open(href,"_blank");trackEvent([PAGE_ID,'share_twitter_old'],2);return true;break;default:break;}},renderSave:function()
{var saveModule=new BookmarkSelect({container:document.getElementById('action_save'),className:"selectGhost",id:"TabGhost"},this);saveModule.addOption(null,{label:"SAVE",value:-1});saveModule.display();},renderShare:function()
{var shareModule=new Selector({container:document.getElementById('action_share'),className:"selectGhost",id:"TabGhost"},{callbackObject:this,callbackMethod:"share"});shareModule.addOption(null,{label:'<span class="share"><small class=\"icon\"></small><span class="txt">SHARE</span></span>',value:-1});shareModule.addOption(null,{label:'<span class="facebook"><small class="icon"></small><span class="txt">facebook</span></span>',value:'facebook'});shareModule.addOption(null,{label:'<span class="twitter"><small class="icon"></small><span class="txt">twitter</span></span>',value:'twitter'});shareModule.addOption(null,{label:'<span class="email"><small class="icon"></small><span class="txt">email</span></span>',value:'email'});shareModule.display();}}
Goby.set("Entity",new Entity(Goby.get('entity'),Goby.get("entityParams")));
