HLG.Class('ContentEntityInfo',{defer:true,attach:{context:'.portlet-content-entity-info','.group-add a.toggle':function(a){a.form=a.up('.group-add').down('form.toggle');if(!a.form)
return;a.obs('click',this.toggle_group);},'a.toggle-details':function(a){var el=this.context.down('.extended-info');a.el=el;var actions=this.context.down('.actions');if(actions)
actions.setStyle({width:(actions.getWidth()-(parseInt(actions.getStyle('padding-left'))+parseInt(actions.getStyle('padding-right'))))+'px'});var h=el.getHeight();if(Object.isUndefined(el.start_height)){if(el.hasClassName('is-rsvp')){el.start_height=this.context.down('.actions').getHeight();}else{el.start_height=h;}
var new_div=$(E('div'));var htm=el.innerHTML;var p_len=htm.length;do{p_len=htm.length;htm=htm.replace(/<script.*?\/(script)?>/gi,'');}while(htm.length!=p_len);new_div.innerHTML=htm;new_div.style.visibility='hidden';var ov=el.style.overflow;el.style.overflow='hidden';el.appendChild(new_div);el.end_height=el.lastChild.getHeight();el.removeChild(el.lastChild);el.style.overflow=ov;}
var from=el.start_height;var to=el.end_height;if(to>from){a.obs('click',this.toggle_extended_info);}else{el.style.height='auto';a.hide();}}},initialize:function(context){this.context=context;this.toggle_extended_info=this.toggle_extended_info.bindAsEventListener(this);this.toggle_group=this.toggle_group.bindAsEventListener(this);this.group_animating=false;},toggle_group:function(event){var a=event.findElement('a');a.blur();event.stop();if(this.group_animating)
return;this.group_animating=true;var ef;if(!a.form.visible())
ef=[new Effect.Appear(a.form,{sync:true}),new Effect.BlindDown(a.form,{sync:true})];else
ef=[new Effect.Fade(a.form,{sync:true}),new Effect.BlindUp(a.form,{sync:true})];new Effect.Parallel(ef,{duration:.5,afterFinish:function(){this.group_animating=false;}.bind(this)});},toggle_extended_info:function(event){var a=event.findElement('a');el=a.el;a.blur();event.stop();var h=el.getHeight();if(Object.isUndefined(el.start_height)){if(el.hasClassName('is-rsvp'))
el.start_height=this.context.down('.actions').getHeight();else
el.start_height=h;var new_div=E('div');new_div.innerHTML=el.innerHTML;new_div.style.visibility='hidden';var ov=el.style.overflow;el.style.overflow='hidden';el.appendChild(new_div);el.end_height=el.lastChild.getHeight();el.removeChild(el.lastChild);el.style.overflow=ov;}
var from=el.start_height;var to=el.end_height;if(Math.abs(h-el.end_height)<Math.abs(h-el.start_height)){from=to;to=el.start_height;}
var effects=[];if(from<to){if(el.hasClassName('is-rsvp')){new Effect.Fade(this.context.down('.actions').setStyle({position:'absolute'}));window.location.hash='track-rsvp-view';if(Object.isUndefined(this.rsvp_view_tracked)){this.rsvp_view_tracked=true;HLG.track('/rsvp/view',{explicit:['omniture']});}}else{a.hide();}}else{if(el.hasClassName('is-rsvp')){effects.push(new Effect.Appear(this.context.down('.actions'),{sync:true,afterFinish:function(ef){ef.element.setStyle({position:'relative'});}}));window.location.hash='';}else{this.context.select('.toggle-details').invoke('show');}}
effects.push(new Effect.Tween(el,from,to,{sync:true,queue:{position:'end',scope:'extended_info'},beforeStart:function(eff){if(from>to)
el.removeClassName('expanded');else
el.setStyle({height:from+'px',opacity:from/Math.max(to,from)}).show();},afterFinish:function(eff){el.up('.portlet').select('a.toggle-details').each(function(a){if(a.innerHTML=='more')a.innerHTML='less';else if(a.innerHTML=='less')a.innerHTML='more';});if(from<to)
el.addClassName('expanded');else if(el.hasClassName('is-rsvp'))
el.hide();}},function(p){this.setStyle({height:p+'px',opacity:p/Math.max(to,from)});}));el.up('.portlet').select('.auto-add_me_to_guestlist').each(function(b){if(from>to){effects.push(new Effect.Opacity(b,{sync:true,from:0,to:1,beforeStart:function(obj){b.style.visibility='visible';}}));}else{effects.push(new Effect.Opacity(b,{sync:true,from:1,to:0,afterFinish:function(obj){b.style.visibility='hidden';}}));}});new Effect.Parallel(effects,{duration:0.5});}});HLG.WentRecently={initialize:function(){HLG.loadFunction(HLG.WentRecently.add);},add:function(event,context){if(typeof(context)=="undefined")context=$(document.body);else context=$(context);context.select('.portlet-went-recently .i-went-popup').each(function(popup){if(popup.hasClassName('i-went-popupd'))
return;Calendar.setup({inputField:popup.select('input.went_on')[0],ifFormat:'%Y-%m-%d',flat:popup.select('.calendar-container')[0],weekNumbers:false,dateStatusFunc:function(date,y,m,d){var date=new Date();if(date.getFullYear()<y||date.getFullYear()==y&&date.getMonth()<m||date.getFullYear()==y&&date.getMonth()==m&&date.getDate()<d)
return true;return false;}});popup.addClassName('i-went-popupd');});context.select('.portlet-went-recently a.toggle-went-recently').each(function(el){if(el.hasClassName('went-recentlyd'))
return;el.obs('click',HLG.WentRecently.toggle);el.addClassName('went-recentlyd');});},toggle:function(event){var el=event.element().up('.portlet').select('.i-went-popup')[0];if(typeof(el)=='undefined')
return;event.element().blur();Effect.toggle(el,'appear',{duration:.3});event.stop();}}
HLG.InterestedPeople={initialize:function(){HLG.loadFunction(HLG.InterestedPeople.add);},add:function(event,context){if(typeof(context)=="undefined")context=$(document.body);else context=$(context);context.select('.portlet-interested-people div.controls a').each(function(el){if(el.hasClassName('controlsd'))
return;el.obs('click',HLG.InterestedPeople.filter);el.addClassName('controlsd');});},filter:function(event){var el=event.element();el.blur();event.stop();el.up('div').select('a').invoke('removeClassName','current');el.addClassName('current');var s=$('interested_people').sidescroller;if(el.hasClassName('common'))
s.meta_data.set('o','common');else if(el.hasClassName('recent'))
s.meta_data.set('o','recent');if(el.hasClassName('men'))
s.meta_data.set('f','m');else if(el.hasClassName('women'))
s.meta_data.set('f','f');else if(el.hasClassName('all'))
s.meta_data.set('f','a');s.reset();}}
HLG.IMightRunInto={initialize:function(){HLG.loadFunction(HLG.IMightRunInto.add);},add:function(event,context){if(typeof(context)=="undefined")context=$(document.body);else context=$(context);context.select('.portlet-i-might-run-into div.controls a').each(function(el){if(el.hasClassName('controlsd'))
return;el.obs('click',HLG.IMightRunInto.filter);el.addClassName('controlsd');});},filter:function(event){var el=event.element();el.blur();event.stop();el.up('div').select('a').invoke('removeClassName','current');el.addClassName('current');var s=$('might-run-into').sidescroller;if(el.hasClassName('men'))
s.meta_data.set('g','m');else if(el.hasClassName('women'))
s.meta_data.set('g','f');else if(el.hasClassName('all'))
s.meta_data.set('g','');s.reset();}}
HLG.WhoLikesMyStuff={initialize:function(){HLG.loadFunction(HLG.WhoLikesMyStuff.add);},add:function(event,context){if(typeof(context)=="undefined")context=$(document.body);else context=$(context);context.select('.portlet-who-likes-my-stuff div.controls a').each(function(el){if(el.hasClassName('current')){el.obs('click',function(e){e.stop();e.element().blur();});}else{el.obs('click',HLG.WhoLikesMyStuff.filter);}
el.addClassName('controlsd');});},filter:function(event){var el=event.element();el.blur();event.stop();el.up('div').select('a').invoke('removeClassName','current');el.addClassName('current');if(el.hasClassName('men'))
gender='m';else if(el.hasClassName('women'))
gender='f';else if(el.hasClassName('all'))
gender='';if($('who-likes-my-stuff')){new Ajax.Updater('who-likes-my-stuff','ajax/who_likes_my_stuff.php',{method:'post',parameters:{entity_type:$('who-likes-my-stuff').className,gender:gender}});}}}
HLG.MyTwoCents={initialize:function(){HLG.loadFunction(HLG.MyTwoCents.add);},add:function(event,context){if(typeof(context)=="undefined")context=$(document.body);else context=$(context);context.select('.portlet-my-two-cents a.next').each(function(el){if(el.hasClassName('nextd'))
return;el.obs('click',HLG.MyTwoCents.next);el.addClassName('nextd');});},next:function(event){var el=event.element();el.blur();event.stop();var cur_li=el.up('li');var next_li=cur_li.next('li');if(next_li==undefined)
next_li=cur_li.up('ul').select('li')[0];cur_li.setStyle({zIndex:2});if(cur_li.effect!=null)
return;if(next_li.effect!=null){next_li.effect.cancel();next_li.undoPositioned().setStyle({top:0,opacity:1});next_li.effect=null;next_li.show();}
next_li.setStyle({zIndex:1,display:'block'});cur_li.effect=new Effect.DropOut(cur_li,{duration:.5,afterFinish:function(obj){obj.effects.each(function(ef){ef.element.effect=null;});}});}}
HLG.Class('EntityTags',{defer:true,attach:'.portlet-entity-tags div.controls a.add-tags',initialize:function(a){this.a=a;this.toggle=this.toggle.bindAsEventListener(this);this.a.obs('click',this.toggle);},toggle:function(e){e.stop();this.a.blur();Effect.toggle(this.a.up('.portlet').down('form'),'slide',{duration:.5,afterFinish:function(effect){effect.element.setStyle({overflow:'hidden'});}});var el=this.a.up('.portlet').down('div.special-tags');if(el){el.toggle();if(el.visible()){el.setStyle({overflow:'hidden'});}}}});HLG.Class('EntityPhotos',{defer:true,attach:{context:'.portlet-entity-photos','a.upload-photos':function(a){a.obs('click',this.upload_photos_popup.bind(this));}},initialize:function(context){this.context=context;this.upload_popup=new IPopup(425,'portlet-photo-upload','Upload Photos');},upload_photos_popup:function(evt){evt.stop();this.upload_popup.show();}});HLG.Class('EventTools',{defer:true,attach:{context:'.portlet-event-tools','a.toggle-send-reminders':function(a){a.obs('click',this.toggle_reminders);},'.upload-photos > a':function(a){a.obs('click',this.upload_photos_popup.bind(this));}},initialize:function(context){this.toggle_reminders=this.toggle_reminders.bind(this);this.upload_photos_popup=this.upload_photos_popup.bind(this);this.context=context;this.upload_popup=new IPopup(425,'portlet-photo-upload','Upload Photos');},toggle_reminders:function(evt){evt.stop();evt.element().blur();Effect.toggle(this.context.down('form'),'blind',{duration:.5});},upload_photos_popup:function(evt){evt.stop();this.upload_popup.show();}});HLG.Class('PhotoUpload',{defer:true,attach:{context:'.portlet-photo-upload'},initialize:function(context){if(context.hasClassName('ipopup'))
return;this.context=context;var settings={flash_url:$F(context.down('.flash-url')),upload_url:$F(context.down('.upload-url')),file_size_limit:$F(context.down('.size-limit')),file_types:"*.gif;*.jpg;*.jpeg;*.png",file_types_description:"Image Files",file_upload_limit:100,file_queue_limit:0,custom_settings:{context:context},post_params:$F(context.down('.post-params')).evalJSON(),debug:false,button_placeholder:context.down('.select-button'),button_image_url:$F(context.down('.button-image-url')),button_width:$F(context.down('.button-image-width')),button_height:$F(context.down('.button-image-height')),file_queued_handler:this.fileQueued,file_queue_error_handler:this.fileQueueError,file_dialog_complete_handler:this.fileDialogComplete,upload_start_handler:this.uploadStart,upload_progress_handler:this.uploadProgress,upload_error_handler:this.uploadError,upload_success_handler:this.uploadSuccess,upload_complete_handler:this.uploadComplete,queue_complete_handler:this.queueComplete};var swfu=new SWFUpload(settings);this.context.down('form').removeClassName('done').addClassName('select-photos');},fileQueued:function(f){this.customSettings.context.down('ul.file-list').insert({bottom:'<li class="'+f.id+' pending"><div class="name">'+f.name+'</div><div class="status">Pending...</div></li>'});},fileQueueError:function(){},fileDialogComplete:function(num_selected,num_queued,total_queued){try{if(num_queued>0){this.customSettings.context.down('.processing .caption').innerHTML='Uploading '+num_queued+' photo'+(num_queued>1?'s':'')+'... ';this.customSettings.context.down('form').addClassName('processing').removeClassName('select-photos');this.startUpload();}}catch(e){throw e;}},uploadStart:function(f){var li=this.customSettings.context.down('ul.file-list li.'+f.id);li.addClassName('uploading').removeClassName('pending');li.down('div.status').innerHTML='Uploading...';},uploadProgress:function(){},uploadError:function(f,error_code,error_message){var li=this.customSettings.context.down('ul.file-list li.'+f.id);li.addClassName('error').removeClassName('pending').removeClassName('uploading');li.down('div.status').innerHTML='Error!';},uploadSuccess:function(f,server_data,received_response){var li=this.customSettings.context.down('ul.file-list li.'+f.id);li.addClassName('complete').removeClassName('pending').removeClassName('uploading');li.down('div.status').innerHTML='Complete!';},uploadComplete:function(f){if(this.getStats().files_queued>0)
this.startUpload();},queueComplete:function(){this.customSettings.context.down('form').removeClassName('processing').addClassName('done');}});HLG.InboxFriendRequests={initialize:function(){HLG.loadFunction(HLG.InboxFriendRequests.add);},add:function(event,context){if(typeof(context)=="undefined")context=$(document.body);else context=$(context);context.select('.portlet-inbox-friend-requests a.toggle-message').each(function(el){if(el.hasClassName('messaged'))
return;el.obs('click',HLG.InboxFriendRequests.toggle);el.addClassName('messaged');});},toggle:function(event){var el=event.element().up('li.message').select('.request-message')[0];if(typeof(el)=='undefined')
return;event.element().blur();var h=el.getHeight();if(typeof(el.start_height)=='undefined'){el.start_height=h;var new_div=E('div');new_div.innerHTML=el.innerHTML;new_div.style.visibility='hidden';var ov=el.style.overflow;el.style.overflow='hidden';el.appendChild(new_div);el.end_height=el.lastChild.getHeight();el.removeChild(el.lastChild);el.style.overflow=ov;}
var from=el.start_height;var to=el.end_height;if(Math.abs(h-el.end_height)<Math.abs(h-el.start_height)){from=to;to=el.start_height;}
new Effect.Tween(el,from,to,{duration:0.5,queue:{position:'end',scope:'friend_request'},afterFinish:function(obj){el.up('li.message').select('a.toggle-message').each(function(a){if(a.innerHTML=='more')a.innerHTML='less';else if(a.innerHTML=='less')a.innerHTML='more';});}},function(p){this.setStyle({height:p+'px'});});event.stop();}}
HLG.EntMightLike={initialize:function(){HLG.loadFunction(HLG.EntMightLike.add);},add:function(event,context){if(typeof(context)=="undefined")context=$(document.body);else context=$(context);context.select('.might-like-sidescroller .add-button a, .might-like-sidescroller .skip-button a').each(function(b){if(b.hasClassName('disappeared'))
return;b.addClassName('disappeared');b.obs('click',HLG.EntMightLike.click);});},click:function(event){var li=event.element().up('li');var el=li.up('.might-like-sidescroller');var ss=el.sidescroller;ss.remove(li,function(){ss.meta_data.set('event_ids',ss.meta_data.get('event_ids').replace(li.down('.add-button').entity_id,'').replace('||','|').replace(/^\||\|$/g,''));});}};HLG.Class('EntityPicker',{defer:true,attach:{context:'.portlet-entity-picker','.skip-button':function(el){var ent=HLG.extract_entity(el);var a=el.down('a');if(ent.type=='userint'||!LOGGED_IN_USER_ID){a.obsClear('click');}
a.obs('click',this.skip_stuff);},'.slot-users a':function(a){a.obs('click',function(e){e.stop();a.blur();this.change_to(HLG.extract_entity(a.down('img')));this.preload();}.bindAsEventListener(this));},'.slot-users img.photo':function(img){img.obs('load',function(e){this.slot_loading_count--;if(this.slot_loading_count<=0){this.slot_loading_count=0;this.slot_stop();}}.bindAsEventListener(this));}},initialize:function(portlet){this.portlet=portlet;this.skip_stuff=this.skip_stuff.bindAsEventListener(this);this.receive=this.receive.bind(this);this.added_entity=this.added_entity.bind(this);this.slot_step=this.slot_step.bind(this);this.slot_stop=this.slot_stop.bind(this);this.stuff_timer_multiplier=this.people_timer_multiplier=2;this.show_next_stuff=true;this.show_next_user=true;this.slot_interval=false;this.slot_loading_count=0;this.num_people=parseInt(this.portlet.down('.user-count .count').innerHTML);HLG.add_ent.obs('add',this.added_entity);},added_entity:function(e){var ent=e.entity;if(ent.type=='event'){this.portlet.select('.listings .num-events').each(function(el){el.innerHTML=parseInt(el.innerHTML)+1;});}
else if(ent.type=='venue'){this.portlet.select('.listings .num-venues').each(function(el){el.innerHTML=parseInt(el.innerHTML)+1;});}
else if(ent.type=='userint')
this.adjust_user_count(-1);this.portlet.select('.listings .listing.'+ent.className).invoke('removeClassName','unseen');var li=this.portlet.down('.listing.'+ent.className);if(li){if(!li.hasClassName('current'))
li.remove();else{var timer_multiplier=1;if(ent.type=='userint'){timer_multiplier=this.people_timer_multiplier;this.people_timer_multiplier=1;if(this.num_people==0)
this.show_interstitial('people');}
else{timer_multiplier=this.stuff_timer_multiplier;this.stuff_timer_multiplier=1;}
setTimeout(function(){if(ent.type=='userint'){this.show_next_user=this.next_entity(ent);if(!this.show_next_stuff){this.processing(true);}}
else{this.show_next_stuff=this.next_entity(ent);if(!this.show_next_stuff){this.processing(true);}}}.bind(this),timer_multiplier*2000);}
this.preload({action:'added',ent:ent});}},skip_stuff:function(e){e.stop();var a=e.findElement('a');var el=e.findElement('span');a.blur();var listing=el.up('.listing');if(!listing.hasClassName('current')||listing.hasClassName('active'))
return;var ent=HLG.extract_entity(el);if(ent.type=='userint')
this.adjust_user_count(-1);this.portlet.select('.listings .listing.'+ent.className).invoke('removeClassName','unseen');if(ent.type=='userint'){this.show_next_user=this.next_entity(ent);if(!this.show_next_user)
this.show_interstitial('people');}
else{this.show_next_stuff=this.next_entity(ent);if(!this.show_next_stuff)
this.processing(true);}
this.preload({action:'skipped',ent:ent});},show_interstitial:function(which){var ef=[];if(which=='stuff'){this.portlet.down('.stuff h2').innerHTML=this.portlet.down('.stuff h2').innerHTML.replace('10','More');}
ef.push(new Effect.Appear(this.portlet.down('.'+which+' .interstitial'),{sync:true}));if(this.portlet.down('.'+which+' .dots')){ef.push(new Effect.Fade(this.portlet.down('.'+which+' .dots'),{sync:true}));}
new Effect.Parallel(ef,{duration:(ie6?0:0.5),afterFinish:function(){new Effect.Fade(this.portlet.down('.'+which+' .interstitial'),{delay:5});}.bind(this)});},next_entity:function(ent){if(ent.type=='userint')
var context_class='people';else{var num_stuff_clicked=this.portlet.select('.dots .dot.selected').length;var dots=this.portlet.select('.dots .dot');if(num_stuff_clicked==dots.length)
num_stuff_clicked=0;num_stuff_clicked++;dots.slice(0,num_stuff_clicked).invoke('addClassName','selected');dots.slice(num_stuff_clicked).invoke('removeClassName','selected');if(num_stuff_clicked==1&&this.portlet.down('.dots').visible()){this.show_interstitial('stuff');}
var context_class='stuff';}
var next=this.portlet.down('.'+context_class+' .listings .listing.unseen');if(!next){return false;}
return this.change_to(HLG.extract_entity(next));},change_to:function(ent){var to_show=this.portlet.down('.listings .listing.'+ent.className);if(!to_show)
return false;context=to_show.up('.context');var current=context.down('.listings .listing.current');if(current){current=HLG.extract_entity(current);if(current.type==ent.type&&current.id==ent.id)
return false;this.hide_entity(current);}
this.show_entity(ent);return true;},hide_entity:function(ent){if(!this.portlet.down('.listings .listing.current.'+ent.className))
return;var ef=[];var found=this.portlet.down('.listings .listing.current.'+ent.className);this.portlet.select('.listings .listing.current.'+ent.className).each(function(li){ef.push(new Effect.Fade(li,{sync:true,beforeStart:function(effect){li.addClassName('active');},afterFinish:function(effect){if(found!=li)
li.remove();else
li.removeClassName('active').removeClassName('current');}}));});new Effect.Parallel(ef,{duration:(ie6?0:0.5),queue:{position:'end',scope:'entity_picker_hide'},afterFinish:function(effect){this.portlet.select('.listings .listing.'+ent.className).invoke('removeClassName','active').invoke('removeClassName','current').invoke('hide');}.bind(this)});},show_entity:function(ent){var ef=[];var found=this.portlet.down('.listings .listing.current.'+ent.className);this.portlet.select('.listings .listing.'+ent.className).each(function(li){if(found&&li!=found){if(li.hasClassName('current')){ef.push(new Effect.Fade(li,{sync:true,beforeStart:function(effect){li.addClassName('active').removeClassName('current');},afterFinish:function(effect){li.remove();}}));}
else
li.remove();}
else{found=li;ef.push(new Effect.Appear(li,{sync:true,beforeStart:function(effect){li.addClassName('active')},afterFinish:function(effect){li.addClassName('current').removeClassName('active');}}));}});new Effect.Parallel(ef,{duration:(ie6?0:0.5),queue:{position:'end',scope:'entity_picker_show'}});},processing:function(show){},preload:function(options){this.slot_start();var params={full_stuff:'',upcoming_stuff:'',full_users:'',upcoming_users:''};if(!options)
options={};options.action=options.action||'';options.ent=options.ent||{type:'',id:0};params.ent_action=options.action;params.ent_type=options.ent.type;params.ent_id=options.ent.id;this.portlet.select('.stuff .listings .listing').each(function(li){var ent=HLG.extract_entity(li);params.full_stuff+='|'+ent.ent_str;});var num_upcoming=0;var current=this.portlet.down('.stuff .listings .listing.current');if(current){current.nextSiblings().findAll(function(e){return e.hasClassName('e');}).each(function(li){num_upcoming++;if(num_upcoming>200)
return;var ent=HLG.extract_entity(li);params.upcoming_stuff+='|'+ent.ent_str;});}
this.portlet.select('.people .listings .listing').each(function(li){var ent=HLG.extract_entity(li);params.full_users+='|'+ent.id;});var num_upcoming=0;var current=this.portlet.down('.people .listings .listing.current');if(current){current.nextSiblings().findAll(function(e){return e.hasClassName('e');}).each(function(li){num_upcoming++;if(num_upcoming>200)
return;var ent=HLG.extract_entity(li);params.upcoming_users+='|'+ent.id;});}
var track=false;if(options.action){track='game/';if(options.action=='added')
track+='add/';else
track+='skip/';track+=options.ent.type;}
new Ajax.Request('ajax/entity_picker.php',{method:'post',parameters:params,onSuccess:this.receive,track:track});},receive:function(t){var json=t.responseJSON;json.content.full_listings.each(function(l){l.ent=HLG.extract_entity('e-'+l.ent);var li=E('li');li.addClassName('listing').addClassName('e').addClassName(l.ent.className).addClassName('unseen');if(l.sponsored)
li.addClassName('sponsored');li.innerHTML=l.html;li.setStyle({display:'none'});var insert_in;if(l.ent.type=='userint')
var insert_in=this.portlet.down('.people ul.listings');else
var insert_in=this.portlet.down('.stuff ul.listings');var rep=insert_in.down('.'+l.ent.className);if(rep){li.className=rep.className;if(rep.visible())
li.show();rep.replace(li);}
else
insert_in.insert({bottom:li});}.bind(this));var current_user=this.portlet.down('.people .listings .listing.current');if(!current_user)
current_user=this.portlet.select('.people .listings .listing').last();var num_new=0;json.content.new_user_listings.each(function(l){l.ent=HLG.extract_entity('e-'+l.ent);if(this.portlet.down('.people .listings .listing.'+l.ent.className))
return;num_new++;var li=E('li');li.addClassName('listing').addClassName('e').addClassName(l.ent.className).addClassName('unseen');li.innerHTML=l.html;li.setStyle({display:'none'});if(!current_user){this.portlet.down('.people .listings').insert({bottom:li});current_user=li;this.change_to(HLG.extract_entity(li));}
else
current_user.insert({after:li});}.bind(this));if(json.content.num_people)
this.adjust_user_count(json.content.num_people,true);else
this.adjust_user_count(num_new);this.update_slot_images();if(!this.show_next_stuff){var current=HLG.extract_entity(this.portlet.down('.stuff .listings .listing.current'));if(!current){current=HLG.extract_entity(this.portlet.down('.stuff .listings .listing.unseen'));if(!current)
return;this.change_to(current);}
else
this.next_entity(current);this.show_next_stuff=true;}
if(!this.show_next_user){var current=HLG.extract_entity(this.portlet.down('.people .listings .listing.current'));if(!current){current=HLG.extract_entity(this.portlet.down('.people .listings .listing.unseen'));if(!current)
return;this.change_to(current);}
else
this.next_entity(current);this.show_next_user=true;}},adjust_user_count:function(amount,override){var count=this.portlet.down('.matches .user-count .count');if(override)
count.innerHTML=amount;else
count.innerHTML=parseInt(count.innerHTML)+amount;var num_users=parseInt(count.innerHTML);this.portlet.select('.num-queued-people').each(function(el){el.innerHTML=num_users;});return this.num_people=num_users;},update_slot_images:function(){var users=this.portlet.select('.people .listings .listing.unseen');while(users.length>4)
users.splice(Math.floor(Math.random()*users.length),1);this.portlet.select('.people .slot-users a').each(function(a,index){if(!users[index]){a.hide();return;}
a.show();var img=a.down('img.photo');var ent=HLG.extract_entity(img);if(ent)
img.removeClassName(ent.className);ent=HLG.extract_entity(users[index]);img.addClassName(ent.className);this.slot_loading_count++;img.src=users[index].down('img.slot-image').src;}.bind(this));if(this.slot_loading_count==0)
setTimeout(this.slot_stop,1000);},slot_start:function(){if(this.slot_interval!==false||ie6)
return;this.portlet.select('.slot-users img.slot').each(function(i){i.show();i.height=i.getHeight();i.num_blocks=i.height/i.up('a').down('img.photo').getHeight();});this.slot_interval=setInterval(this.slot_step,120);},slot_stop:function(){if(this.slot_interval!==false)
clearInterval(this.slot_interval);this.portlet.select('.slot-users img.slot').invoke('hide');this.slot_interval=false;},slot_step:function(){this.portlet.select('.slot-users img.slot').each(function(img){img.setStyle({top:-(Math.floor((img.num_blocks-1)*Math.random())*img.height/img.num_blocks)+'px'});});}});HLG.Class('BetaEntityPicker',{defer:true,attach:{context:'.portlet-beta-entity-picker','ul.nav a.item':function(a){a.obs('click',this.nav_click);},'.skip-button':function(el){var ent=HLG.extract_entity(el);var a=el.down('a');if(ent.type=='userint'||!LOGGED_IN_USER_ID){a.obsClear('click');a.obs('click',this.skip_user_click,true);}},'.bottom-items':function(el){el.setStyle({'position':'absolute'});}},initialize:function(portlet){this.portlet=portlet;this.nav_click=this.nav_click.bindAsEventListener(this);this.skip_user_click=this.skip_user_click.bindAsEventListener(this);this.receive=this.receive.bind(this);HLG.add_ent.obs('add',this.added_entity.bind(this));HLG.add_ent.obs('skip',this.added_entity.bind(this));this.loadPages();var first_ent=this.portlet.down('.whats-hot .entities .queue li.current > div');if(first_ent){var ent=HLG.extract_entity(first_ent);var sponsored=first_ent.down('img.sash');if(sponsored){HLG.track(null,{explicit:['hit'],c:'ent-ad',s:1,e:ent.ent_str});}}},loadPages:function(){var pages=[];this.portlet.select('ul.pages > li.page').each(function(p){if(p.hasClassName('loaded')||p.hasClassName('loading'))
return;p.addClassName('loading');pages.push($w(p.className).without('current','page')[0]);});if(!pages.length)
return;var params={'action':'load-content','pages[]':pages};var qp=window.location.search.substr(1).toQueryParams();new Ajax.Request('ajax/entity_picker.php'+(qp.view_as?'?view_as='+qp.view_as:''),{method:'post',parameters:params,onSuccess:this.receivePages.bind(this)});},receivePages:function(t){var content=t.responseJSON.content;for(k in content){this.portlet.select('ul.pages > li.page.'+k).each(function(p){p.addClassName('loaded').removeClassName('loading');p.update(content[k]);});}
HLG.contentChanged();},nav_click:function(e){e.stop();var a=e.findElement(a);a.blur();var li=a.up('li');if(li.hasClassName('current'))
return;HLG.ads.toggle('AD_RIGHT');this.loadPages();this.portlet.select('ul.nav > li.current').invoke('removeClassName','current');this.portlet.select('ul.pages > li.current').invoke('removeClassName','current');this.portlet.select('ul.pages > li.'+li.className).invoke('addClassName','current');this.portlet.select('ul.nav > li.'+li.className).invoke('addClassName','current');},skip_user_click:function(e){var a=e.findElement('a');var el=e.findElement('span');a.blur();var ent=HLG.extract_entity(el);this.added_entity({action:'skip',entity:ent});},added_entity:function(e){var ent=e.entity;var li;if(ent.type!='userint'){this.portlet.select('ul.pages > li.page.my-events').invoke('removeClassName','loaded');if(e.action=='add'){if(ent.type=='event'){this.portlet.select('.num-events').each(function(el){el.innerHTML=parseInt(el.innerHTML)+1;});}
else if(ent.type=='venue'){this.portlet.select('.num-venues').each(function(el){el.innerHTML=parseInt(el.innerHTML)+1;});}}
li=this.portlet.down('.whats-hot .entities .'+ent.className);if(li)
li=li.up('li');}
else{li=this.portlet.down('.similar-people .entities .'+ent.className).up('li');if(LOGGED_IN_USER_ID){this.portlet.select('.num-people').each(function(el){el.innerHTML=parseInt(el.innerHTML)-1;});}}
if(li){if(!li.hasClassName('current')){li.addClassName('completed').removeClassName('upcoming');}
else{setTimeout(function(){if(ent.type=='userint'){this.show_next_user=this.next_entity(ent);if(!this.show_next_user){this.show_interstitial('similar-people');}}
else{this.show_next_stuff=this.next_entity(ent);if(!this.show_next_stuff){this.show_interstitial('whats-hot');}}}.bind(this),e.action=='skip'?0:2000);}
this.preload({action:e.action,ent:ent});}},ensure_current_entities:function(){var current=this.portlet.down('.similar-people .entities li.current');if(!current||current.hasClassName('fading')&&!current.next('.current'))
this.next_entity({type:'userint'});current=this.portlet.down('.whats-hot .entities li.current');if(!current||current.hasClassName('fading')&&!current.next('.current'))
this.next_entity({type:'event'});},next_entity:function(ent){var next=false;if(ent.type=='userint'){var queue=this.portlet.down('.similar-people .entities');var entities=this.portlet.select('.similar-people .entities li.complete');if(!LOGGED_IN_USER_ID&&entities.length>=7){entities.each(function(e){queue.insert({bottom:e.remove()});e.addClassName('upcoming').removeClassName('complete');});}
next=this.portlet.down('.similar-people .entities li.upcoming > div');}
else{var queue=this.portlet.down('.whats-hot .entities .queue');var entities=this.portlet.select('.whats-hot .entities li.complete');if(!LOGGED_IN_USER_ID&&entities.length>=7){entities.each(function(e){queue.insert({bottom:e.remove()});e.addClassName('upcoming').removeClassName('complete');});}
next=this.portlet.down('.whats-hot .entities li.upcoming > div');}
if(!next){this.hide_current(ent.type);return false;}
return this.change_to(HLG.extract_entity(next));},hide_current:function(type){var current;if(type=='userint')
current=this.portlet.down('.similar-people .entities li.current');else
current=this.portlet.down('.whats-hot .entities li.current');if(current){current.setStyle({'zIndex':1}).addClassName('fading');new Effect.Opacity(current,{to:0,afterFinish:function(ef){current.removeClassName('current').removeClassName('fading').addClassName('complete');current.setStyle({'opacity':1});}});}},change_to:function(ent){this.hide_current(ent.type);if(ent.type=='userint'){var li=this.portlet.down('.similar-people .entities .'+ent.className).up('li');li.setStyle({'zIndex':0});li.removeClassName('upcoming').addClassName('current');}
else{var li=this.portlet.down('.whats-hot .entities .'+ent.className).up('li');li.setStyle({'zIndex':0});li.removeClassName('upcoming').addClassName('current');setTimeout(function(){li.down('.bottom-items').setStyle('position','absolute');},100);var sponsored=li.down('img.sash');if(sponsored){HLG.track('/',{explicit:['hit'],c:'ent-ad',s:1,e:ent.ent_str});}}
return true;},preload:function(options){var params={action:'beta-preload',stuff:'',exclude_users:'',users:'',exclude_users:''};if(!options)
options={};options.action=options.action||'';options.ent=options.ent||{type:'',id:0};params.ent_action=options.action;params.ent_type=options.ent.type;params.ent_id=options.ent.id;this.portlet.select('.whats-hot .queue > li.upcoming > div').each(function(d){var ent=HLG.extract_entity(d);params.stuff+='|'+ent.ent_str;});this.portlet.select('.whats-hot .queue > li.complete > div').each(function(d){var ent=HLG.extract_entity(d);params.exclude_stuff+='|'+ent.ent_str;});this.portlet.select('.similar-people .entities li.upcoming > div').each(function(li){var ent=HLG.extract_entity(li);params.users+='|'+ent.id;});this.portlet.select('.similar-people .entities li.complete > div').each(function(li){var ent=HLG.extract_entity(li);params.exclude_users+='|'+ent.id;});new Ajax.Request('ajax/entity_picker.php',{method:'post',parameters:params,onSuccess:this.receive});},receive:function(t){var json=t.responseJSON;json.content.stuff_listings.each(function(l){l.ent=HLG.extract_entity('e-'+l.ent);var li=E('li');li.addClassName('nofade').addClassName('upcoming');li.innerHTML=l.html;var insert_in=this.portlet.down('.whats-hot .entities ul');var existing=insert_in.down('.'+l.ent.className);if(!existing){insert_in.insert({bottom:li});}}.bind(this));json.content.new_user_listings.each(function(l){l.ent=HLG.extract_entity('e-'+l.ent);var li=E('li');li.addClassName('nofade').addClassName('upcoming');li.innerHTML=l.html;var insert_in=this.portlet.down('.similar-people .entities');var rep=insert_in.down('.'+l.ent.className);if(!rep)
insert_in.insert({top:li});}.bind(this));json.content.user_listings.each(function(l){l.ent=HLG.extract_entity('e-'+l.ent);var li=E('li');li.addClassName('nofade').addClassName('upcoming');li.innerHTML=l.html;var insert_in=this.portlet.down('.similar-people .entities');var rep=insert_in.down('.'+l.ent.className);if(!rep)
insert_in.insert({bottom:li});}.bind(this));if(json.content.num_users){this.portlet.select('.num-people').each(function(el){el.innerHTML=json.content.num_users;});}
this.ensure_current_entities();},show_interstitial:function(which){var ef=[];ef.push(new Effect.Appear(this.portlet.down('.'+which+' .interstitial'),{sync:true,to:0.9}));if(this.portlet.down('.'+which+' .dots')){ef.push(new Effect.Fade(this.portlet.down('.'+which+' .dots'),{sync:true}));}
new Effect.Parallel(ef,{duration:(ie6?0:0.5),afterFinish:function(){new Effect.Fade(this.portlet.down('.'+which+' .interstitial'),{delay:5});}.bind(this)});}});HLG.NewMyStuff={initialize:function(){HLG.loadFunction(HLG.NewMyStuff.add);HLG.add_ent.obs('add',HLG.NewMyStuff.added_entity);},added_entity:function(e){if(e.entity.type=='event'){$$('.portlet-new-mystuff .num-events').each(function(el){el.innerHTML=parseInt(el.innerHTML)+1;});}},add:function(event,context){if(typeof(context)=="undefined")context=$(document.body);else context=$(context);context.select('.portlet-new-mystuff .section').each(function(el){el.setStyle({height:el.getHeight()+'px'});});context.select('.portlet-new-mystuff .section li').invoke('show');context.select('.portlet-new-mystuff .section h3 a.expand').each(function(a){if(a.expander)
return;a.expander=true;a.obs('click',HLG.NewMyStuff.click_expand.bindAsEventListener(a));});context.select('.portlet-new-mystuff .section h3 a.collapse').each(function(a){if(a.expander)
return;a.expander=true;a.obs('click',HLG.NewMyStuff.click_collapse.bindAsEventListener(a));});},click_expand:function(event){event.stop();this.blur();this.hide();var section=this.up('.section');section.down('h3 a.collapse').show();if(!section.full_height){section.collapsed_height=section.getHeight();section.setStyle({height:'auto'});section.full_height=section.getHeight();section.setStyle({height:section.collapsed_height+'px'});}
new Effect.Morph(section,{style:{height:section.full_height+'px'},duration:.5});},click_collapse:function(event){event.stop();this.blur();this.hide();var section=this.up('.section');section.down('h3 a.expand').show();if(!section.collapsed_height){section.collapsed_height=section.down('h3').getHeight();section.select('ul li').slice(0,2).each(function(li){section.collapsed_height+=li.getHeight();});}
new Effect.Morph(section,{style:{height:section.collapsed_height+'px'},duration:.5});},click:function(event){var messages=event.element().up('div.messages').up('.portlet').select('.messages');var box=event.element().up('div.messages').down('div.box');if(!box)
return;if(box.visible())
return;var ef=[];ef.push(new Effect.BlindDown(box,{sync:true}));messages.each(function(m){var b=m.down('div.box');if(b==box){b.up('.messages').addClassName('expanded');return;}
if(!b.visible())
return;b.up('.messages').removeClassName('expanded');ef.push(new Effect.BlindUp(b,{sync:true}));});new Effect.Parallel(ef,{duration:.4});}}
HLG.Class('RecentlyBookmarked',{defer:true,attach:{context:'.portlet-recently-bookmarked','.add':function(btn){btn.obs('click',this.click);},'.skip':function(btn){btn.obs('click',this.click);}},initialize:function(portlet){this.portlet=portlet;this.click=this.click.bindAsEventListener(this);this.receive=this.receive.bind(this);},click:function(e){e.stop();var a=e.findElement('a');var user=a.up('.e');var ent=HLG.extract_entity(user);var params={'o_who':ent.ent_str,users:'','num_left':this.portlet.select('.e.upcoming').length};this.portlet.select('.e').each(function(e){var ent=HLG.extract_entity(e);params.users+='|'+ent.id;});var track='recently_bookmarked/';if(a.hasClassName('add')){params._submit_check='add_user';track+='add';}
else{params._submit_check='skip_user';track+='skip';}
track+='/'+ent.type;new Ajax.Request('ajax/recently_bookmarked.php',{method:'post',parameters:params,track:track,onSuccess:this.receive});var next=user.next('.e');user.hide().removeClassName('current').removeClassName('upcoming');next.show().addClassName('current');},receive:function(t){this.portlet.insert(t.responseJSON.content);if(!this.portlet.down('.current'))
this.portlet.down('.e').addClassName('current');}});HLG.Class('YouMightKnowFullPortlet',{attach:{context:'.portlet-you-might-know-full','.select-controls a':function(a){a.obs('click',this.toggle_selects);}},initialize:function(context){this.context=context;this.toggle_selects=this.toggle_selects.bindAsEventListener(this);},toggle_selects:function(event){event.stop();var a=event.findElement('a');a.blur();a.up('.select-controls').select('a').invoke('toggle');if(a.hasClassName('select-all'))
this.context.select('.users input[type=checkbox]').each(function(i){i.checked=true;});else
this.context.select('.users input[type=checkbox]').each(function(i){i.checked=false;});}});HLG.Class('SpecialOfferEvents',{defer:true,attach:{context:'.portlet-special-offer-events','a.expand':function(a){this.expand_links.push(a);a.obs('click',this.expand);},'a.collapse':function(a){this.collapse_links.push(a);a.obs('click',this.collapse);},'ul.events':function(el){el.collapsed_height=el.getHeight();el.setStyle({height:el.collapsed_height+'px'});el.select('li').invoke('show');el.setStyle({height:'auto'});el.expanded_height=el.getHeight();el.setStyle({height:el.collapsed_height+'px'});}},initialize:function(portlet){this.portlet=portlet;this.expand_links=[];this.collapse_links=[];this.expand=this.expand.bindAsEventListener(this);this.collapse=this.collapse.bindAsEventListener(this);this.events=this.portlet.down('ul.events');},expand:function(e){e.stop();this.expand_links.invoke('hide');this.collapse_links.invoke('show');new Effect.Morph(this.events,{style:{height:this.events.expanded_height+'px'},duration:.5});},collapse:function(e){e.stop();this.collapse_links.invoke('hide');this.expand_links.invoke('show');new Effect.Morph(this.events,{style:{height:this.events.collapsed_height+'px'},duration:.5});}});HLG.Class('UpgradeToPromoterPopup',{attach:'.portlet-upgrade-to-promoter',initialize:function(popup){}});HLG.UpgradeToPromoterPopup.show=function(){var p=new IPopup(425,'portlet-upgrade-to-promoter','Event Organizer Approval');p.show();};HLG.Class('UpTo',{defer:true,attach:{context:'.portlet-upto','form.upto':function(f){f.obs('submit',this.submit_upto);},'form.upto input.upto':function(i){i.obs('change',this.change_upto);i.obs('keyup',this.change_upto);if(!i.hasClassName('default')){if(Object.isUndefined(this.up_to_text)){this.upto_text=$F(i);if(!this.upto_text.blank()){this.update_upto_text(this.upto_text);}}
else
i.value=this.upto_text;}},'.ping-toggle':function(b){b.obs('click',this.ping_toggle);},'input.text.default':function(i){i.default_val=$F(i);i.obs('focus',function(e){if(i.hasClassName('default')){i.value='';i.removeClassName('default');}});i.obs('blur',function(e){if($F(i).blank()){i.addClassName('default');i.value=i.default_val;}});}},initialize:function(portlet){this.portlet=portlet;this.change_upto=this.change_upto.bindAsEventListener(this);this.ping_toggle=this.ping_toggle.bindAsEventListener(this);this.submit_upto=this.submit_upto.bindAsEventListener(this);var el=this.portlet.down('.upto_text');if(el){this.original_upto_text=el.innerHTML;this.update_upto_text(el.innerHTML);}
else
this.original_upto_text='';},change_upto:function(e){var val=$F(e.element());if(val.blank())
this.update_upto_text(this.original_upto_text);else
this.update_upto_text(val.escapeHTML());},update_upto_text:function(text){this.upto_text=text;this.portlet.select('.upto_text').invoke('update',text);},ping_toggle:function(e){e.stop();e.element().blur();Effect.toggle(this.portlet.down('div.ping'),'blind',{duration:.5});this.portlet.select('.ping-toggle').invoke('toggle');this.portlet.select('form.upto input.ping').each(function(i){i.value=1-parseInt($F(i));});},submit_upto:function(e){var form=e.element();var input=form.down('input.upto');if(input.hasClassName('default')||$F(input).empty()){e.stop();input.focus();}}});HLG.Class('ABInvite',{defer:true,attach:{context:'.portlet-ab-invite','input[type=checkbox]':function(i){i.obs('change',this.oncheck);},'.select':function(el){el.obs('click',this.selectAll);},'.unselect':function(el){el.obs('click',this.unselectAll);}},initialize:function(portlet){this.portlet=portlet;this.oncheck=this.oncheck.bindAsEventListener(this);this.selectAll=this.selectAll.bindAsEventListener(this);this.unselectAll=this.unselectAll.bindAsEventListener(this);},updateCount:function(){var count=this.portlet.select('input[type=checkbox]').findAll(function(i){return $F(i);}).length;this.portlet.select('.num-invites').each(function(n){n.innerHTML=count;});this.portlet.select('.num-invites-text').each(function(n){n.innerHTML=(count==1)?'person to be your friend':'people to be your friends';});},oncheck:function(e){this.updateCount();},selectAll:function(e){e.stop();var el=e.element();el.blur();el.up('.col').select('input').each(function(i){i.checked=true;});el.up().select('.select').invoke('hide');el.up().select('.unselect').invoke('show');this.updateCount();},unselectAll:function(e){e.stop();var el=e.element();el.blur();el.up('.col').select('input').each(function(i){i.checked=false;});el.up().select('.unselect').invoke('hide');el.up().select('.select').invoke('show');this.updateCount();}});HLG.Class('VenueOwnerConsole',{defer:true,attach:{context:'.portlet-venue-owner-console','ul.tabs > li':function(e){e.obs('click',this.tab_click)},'input.text.default, textarea.default':function(i){i.default_val=$F(i);i.obs('focus',function(e){if(i.hasClassName('default')){i.value='';i.removeClassName('default');}});i.obs('blur',function(e){if($F(i).blank()){i.addClassName('default');i.value=i.default_val;}});},'form':function(f){f.obs('submit',this.form_submit)}},initialize:function(portlet){this.portlet=portlet;this.tab_click=this.tab_click.bind(this);this.form_submit=this.form_submit.bind(this);},tab_click:function(e){var a=e.findElement('a');var li=a.up('li');if(!li.hasClassName('bulletin')&&!li.hasClassName('offer'))
return;a.blur();e.stop();var className=$w(li.className).findAll(function(cl){return cl!='selected'&&cl!='unselected'&&cl!='first'&&cl!='last';}).join('.');this.portlet.select('ul.pages > li.selected').invoke('removeClassName','selected');this.portlet.select('ul.pages > li.'+className).invoke('addClassName','selected');},form_submit:function(e){var allow_empty=e.element().hasClassName('allow-empty');var empty_inputs=e.element().select('input[type=text],textarea').findAll(function(i){return i.hasClassName('default')||!allow_empty&&$F(i).empty();});if(empty_inputs.length){alert('Please fill in all fields');e.stop();}}});HLG.Class('MediaAlbum',{defer:true,attach:{context:'.portlet-media-album'},initialize:function(context){this.context=context;this.paginator=this.context.down('.pagination');if(!this.paginator)
return;this.paginator=this.paginator.AjaxPaginate;this.paginator.obs('change',this.change_page.bind(this));var first_page=this.context.down('.photos .page');this.page_width=first_page.getWidth()+parseInt(first_page.getStyle('margin-left'))+parseInt(first_page.getStyle('margin-right'));this.page_effect=false;},change_page:function(e){if(this.page_effect!==false)
this.page_effect.cancel();this.load_page(e.page);if(e.page+1<=e.max_page)
this.load_page(e.page+1);if(e.page+2<=e.max_page)
this.load_page(e.page+2);this.page_effect=new Effect.Move(this.context.down('.photos'),{x:-(this.page_width*e.page),mode:'absolute',afterFinish:function(){this.page_effect=false;}.bind(this),duration:0.5});},load_page:function(p){var page=this.context.down('.photos li.page',p);if(!page)
return;var photos=page.select('.not-loaded');if(!photos.length)
return;var ents=[];var i=0;var len=photos.length;for(i=0;i<len;i++){ents.push(HLG.extract_entity(photos[i]));}
var ent=HLG.extract_entity(this.context);new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'album_page','o_entity[type]':ent.type,'o_entity[id]':ent.id,'ents':ents.map(function(e){return e.ent_str;}).join(',')},onSuccess:this.photos_loaded.bind(this,ents)});},photos_loaded:function(ents,t){if(!t.responseJSON||t.responseJSON.errors)
return;var i=0;var len=ents.length;for(i=0;i<len;i++){if(!t.responseJSON.content[ents[i].ent_str])
continue;var photos=this.context.select('.not-loaded.'+ents[i].className);photos.invoke('replace',t.responseJSON.content[ents[i].ent_str]);}}});HLG.Class('PhotoPortlet',{defer:true,attach:{context:'.portlet-photo','.ss-speed a':function(a){a.obs('click',this.click_ss_speed.bind(this));},'.photos .photo-full img':function(el){el.obs('click',this.next_page);}},initialize:function(context){this.context=context;this.paginator=this.context.down('.pagination').AjaxPaginate;this.paginator.obs('change',this.change_page.bind(this));this.next_page=this.next_page.bind(this);this.prev_page=this.prev_page.bind(this);var pages=this.context.select('.photos li');this.max_page=pages.length-1;this.ss_end_page=this.paginator.currentPage()-1;if(this.ss_end_page<0)
this.ss_end_page=this.max_page;this.page_effect=false;this.comment_board_timeout=false;dooh.observe('load',this.hash_change.bind(this));this.ss_start();Event.observe(document,'keydown',function(e){if(e.keyCode==Event.KEY_LEFT){e.stop();this.prev_page();}else if(e.keyCode==Event.KEY_RIGHT){e.stop();this.next_page();}}.bind(this));},next_page:function(){var page=this.paginator.currentPage()+1;if(page>this.max_page)
page=0;this.paginator.gotoPage(page);return page;},prev_page:function(){var page=this.paginator.currentPage()-1;if(page<0)
page=this.max_page;this.paginator.gotoPage(page);return page;},change_page:function(e){this.max_page=e.max_page;this.goto_page(e.page);},goto_page:function(page){var max_page=this.max_page;if(this.page_effect!==false)
this.page_effect.cancel();this.load_page(page);this.load_page(page+1);this.load_page(page+2);var li=this.context.down('.photos > li',page);if(!li||li.hasClassName('current'))
return;var photo=HLG.extract_entity(li);this.set_hash(photo.id,this.get_ss_speed());this.ss_start();HLG.track('/photo-'+photo.id);},load_page:function(p){if(p>this.max_page)
p=p-this.max_page-1;var photo=this.context.down('.photos li',p);if(!photo||photo.hasClassName('loaded')||photo.hasClassName('loading'))
return;photo.addClassName('loading');var ent=HLG.extract_entity(photo);new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'full_photo','o_entity[type]':ent.type,'o_entity[id]':ent.id},onSuccess:this.photo_loaded.bind(this,photo)});},set_hash:function(id,speed){dooh.add(HLG.spfu('/photo-'+id,{ss:speed}));},photo_loaded:function(photo,t){if(!t.responseJSON||t.responseJSON.errors)
return;photo.innerHTML=t.responseJSON.content;photo.addClassName('loaded').removeClassName('loading');},hash_change:function(evt){if(!evt.hash){photo=this.context.down('.photos .main');if(photo){this.goto_page(photo.previousSiblings().length);}
return;}
var photo=/^\/(photo-\d+)/.exec(evt.hash);var params=evt.hash.toQueryParams();if(!params.ss)
params.ss='slow';if(photo){var li=this.context.down('.photos .e-'+photo[1]);if(li&&!li.hasClassName('current')){this.context.down('.photo-count .current').innerHTML=li.previousSiblings().length+1;this.context.select('.photos li.current').invoke('removeClassName','current');li.addClassName('current');this.context.select('.send_to_friends').each(function(s2f){s2f.onclick=function(){if(LOGGED_IN_USER_ID)sendToFriends2(true,"Check out this photo on Going",undefined,false,{"entity_type":"photo","entity_id":photo.id});return false;};});this.load_comment_board();}
if(params.ss=='off'){this.ss_end_page=this.paginator.currentPage()-1;if(this.ss_end_page<0)
this.ss_end_page=this.max_page;}
this.set_ss_speed(params.ss);}},load_comment_board:function(){var li=this.context.down('.photos li.current');if(!li)
return;var photo=HLG.extract_entity(li);if(!photo)
return;if(this.comment_board_timeout!==false)
clearTimeout(this.comment_board_timeout);this.comment_board_timeout=false;$$('.portlet-comment-board').invoke('hide');return;$$('.loading-comments').invoke('show');this.comment_board_timeout=setTimeout(function(){new Ajax.Request('ajax/comment.php',{method:'post',parameters:{'_submit_check':'get_comment_board','ent':photo.ent_str},onSuccess:this.comment_board_loaded.bind(this,photo)});}.bind(this),250);},comment_board_loaded:function(photo,t){var li=this.context.down('.photos li.current');if(!li)
return;var current_photo=HLG.extract_entity(li);if(!current_photo||current_photo.id!=photo.id)
return;if(t.responseJSON&&t.responseJSON.content){$$('.portlet-comment-board').invoke('replace',t.responseJSON.content).invoke('show');$$('.loading-comments').invoke('hide');}},get_ss_speed:function(){var photos=this.context.down('.photos');if(photos.hasClassName('on'))
return'on';if(photos.hasClassName('slow'))
return'slow';else if(photos.hasClassName('medium'))
return'medium';else if(photos.hasClassName('fast'))
return'fast';return'off';},speed_to_interval:function(speed){var interval=0;switch(speed){case'on':case'slow':interval=10;break;case'medium':interval=5;break;case'fast':interval=3;break;}
return interval;},click_ss_speed:function(evt){evt.stop();var a=evt.element();a.blur();if(a.hasClassName('current'))
return;this.set_ss_speed(a.className);},ss_start:function(){if(this.ss_interval!==false)
clearTimeout(this.ss_interval);this.ss_interval=false;var interval=this.speed_to_interval(this.get_ss_speed());if(interval>0)
this.ss_interval=setTimeout(this.ss_step.bind(this),interval*1000);},set_ss_speed:function(speed){if(speed==this.get_ss_speed())
return;this.context.down('.photos').removeClassName('slow').removeClassName('medium').removeClassName('fast').removeClassName('off').removeClassName('on').addClassName(speed);this.context.down('.ss-speed').select('a').invoke('removeClassName','current');this.context.down('.ss-speed a.'+speed).addClassName('current');var photo=HLG.extract_entity(this.context.down('.photos .current'));this.set_hash(photo.id,speed);this.ss_start();},ss_step:function(){this.next_page();}});HLG.Class('MediaAlbumOrganize',{defer:true,attach:{context:'.portlet-media-album-organize','.save-changes, a.delete':function(a){a.obs('click',this.save_changes);},'.cancel':function(a){a.obs('click',this.cancel);},'.rotate a':function(a){a.obs('click',this.rotate);},'.make-primary a':function(a){a.obs('click',this.make_primary);},'.hide a.hide':function(a){a.obs('click',this.hide_photo);},'.hide a.show':function(a){a.obs('click',this.show_photo);}},initialize:function(context){this.context=context;this.save_changes=this.save_changes.bind(this);this.saved=this.saved.bind(this);this.cancel=this.cancel.bind(this);this.rotate=this.rotate.bind(this);this.make_primary=this.make_primary.bind(this);this.hide_photo=this.hide_photo.bind(this);this.show_photo=this.show_photo.bind(this);this.current_order=this.get_order();this.current_captions=this.get_captions();this._processing=false;if(this.context.down('div.mode').hasClassName('caption'))
this.caption_mode();else
this.sort_mode();},sort_mode:function(){this.context.down('div.mode').addClassName('sort').removeClassName('caption');Sortable.create(this.context.down('.photos').identify(),{overlap:'horizontal',constraint:false,scroll:window});},caption_mode:function(){if(this.mode()=='sort'&&this.order_has_changed()){if(!confirm('You have not saved your changes. Are you sure you want to navigate away?'))
return;}
this.context.down('div.mode').addClassName('caption').removeClassName('sort');Sortable.destroy(this.context.down('.photos').identify());},mode:function(){var m=this.context.down('div.mode');if(m.hasClassName('sort'))
return'sort';if(m.hasClassName('caption'))
return'caption';},get_order:function(){return this.context.select('.photo-organize').collect(function(e){return HLG.extract_entity(e).ent_str;});},order_has_changed:function(){return this.current_order.join(':')!=this.get_order().join(':');},restore_order:function(){var photos=this.context.select('.photo-organize').collect(function(e){return e.up('li');}).invoke('remove');var container=this.context.down('.photos');var i=0;var current_order=this.current_order;var len=current_order.length;for(i=0;i<len;i++){container.insert(photos.find(function(p){return HLG.extract_entity(p.down('.photo-organize')).ent_str==current_order[i];}));}},get_captions:function(){var c={};this.context.select('.photo-organize').each(function(p){var ent=HLG.extract_entity(p);c[ent.ent_str]=$F(p.down('textarea'));});return $H(c);},get_changed_captions:function(){var new_captions=this.get_captions();var current_captions=this.current_captions;var changed={};new_captions.each(function(c){if(current_captions.get(c[0])!=c[1])
changed[c[0]]=c[1];});return $H(changed);},captions_have_changed:function(){return this.get_changed_captions().size()!=0;},get_to_delete:function(){return this.context.select('input.delete').findAll(function(i){return i.checked}).collect(function(i){return HLG.extract_entity(i.up('.photo-organize')).ent_str;});},has_to_delete:function(){return this.get_to_delete().length!=0;},processing:function(p){if(p&&!this._processing){this._processing=HLG.showProcessing('center','center');this.context.select('input,select,textarea').invoke('disable');}
else if(!p&&this._processing){this._processing.remove();this.context.select('input,select,textarea').invoke('enable');}},save_changes:function(evt){evt.stop();evt.element().blur();if(this.mode()=='caption'){if(this.has_to_delete()||this.captions_have_changed()){if(this.has_to_delete()&&!confirm('Are you sure you want to delete these photos?'))
return;this.processing(true);var ent=HLG.extract_entity(this.context);new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'delete_and_caption','o_entity[type]':ent.type,'o_entity[id]':ent.id,'delete':this.get_to_delete().toJSON(),'captions':this.get_changed_captions().toJSON()},onSuccess:this.saved});}
else{this.processing(true);this.saved({responseJSON:{content:true}});}}
else{var new_order=this.get_order();if(this.order_has_changed()){this.processing(true);var ent=HLG.extract_entity(this.context);new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'sort_album','o_entity[type]':ent.type,'o_entity[id]':ent.id,'order':new_order.toJSON()},onSuccess:this.saved});}
else{this.processing(true);this.saved({responseJSON:{content:true}});}}},cancel:function(evt){evt.element().blur();if(this.mode()=='caption'){}
else{this.restore_order();}
this.processing(false);},saved:function(t){if(t.responseJSON&&t.responseJSON.content){if(t.responseJSON.content===true){this.current_order=this.get_order();location.href=HLG.spfu(location.href,{'edit':null});return;}
else if(t.responseJSON.content.deleted&&t.responseJSON.content.deleted.length){if(t.responseJSON.content.captioned&&t.responseJSON.content.captioned.length){location.href=HLG.spfu(location.href,{'edit':null});return;}
else{var deleted=t.responseJSON.content.deleted;var len=deleted.length;if(len>=this.context.select('.photos li').length){location.href=HLG.spfu(location.href,{'edit':null});return;}
var effects=[];for(var i=0;i<len;i++){var el=this.context.down('.e-photo-'+deleted[i]);if(el)
effects[effects.length]=new Effect.BlindUp(el,{sync:true,afterFinish:function(){el.remove();}});}
new Effect.Parallel(effects);}}
else if(t.responseJSON.content.captioned&&t.responseJSON.content.captioned.length){location.href=HLG.spfu(location.href,{'edit':null});return;}}
else
alert('error');this.processing(false);},rotate:function(evt){evt.stop();var a=evt.element();a.blur();var photo=a.up('.photo-organize');var ent=HLG.extract_entity(photo);new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'rotate_photo','o_entity[type]':ent.type,'o_entity[id]':ent.id,'dir':a.hasClassName('left')?'l':'r'},onSuccess:this.rotated.bind(this,ent)});},rotated:function(ent,t){if(t.responseJSON&&t.responseJSON.content==true){var photo=this.context.down('.photo-organize.'+ent.className);var img=photo.down('img');img.src=HLG.spfu(img.src,{'rand':Math.floor(Math.random()*1000000)});}
else
alert('error');},make_primary:function(evt){evt.stop();var a=evt.element();a.blur();var photo=a.up('.photo-organize');var ent=HLG.extract_entity(photo);new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'set_primary_photo','o_entity[type]':ent.type,'o_entity[id]':ent.id}});this.context.select('.photo-organize .make-primary').invoke('removeClassName','primary');this.context.select('.photo-organize.'+ent.className+' .make-primary').invoke('addClassName','primary');},hide_photo:function(evt){evt.stop();var a=evt.element();a.blur();var photo=a.up('.photo-organize');var ent=HLG.extract_entity(photo);new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'hide_photo','o_entity[type]':ent.type,'o_entity[id]':ent.id}});photo.select('span.hide').invoke('addClassName','hidden');},show_photo:function(evt){evt.stop();var a=evt.element();a.blur();var photo=a.up('.photo-organize');var ent=HLG.extract_entity(photo);new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'show_photo','o_entity[type]':ent.type,'o_entity[id]':ent.id}});photo.select('span.hide').invoke('removeClassName','hidden');}});HLG.Class('MediaAlbumTools',{defer:true,attach:{context:'.portlet-media-album-tools','.upload-photos > a':function(a){a.obs('click',this.upload_photos_popup.bind(this));},'.caption-photos > a':function(a){a.obs('click',this.caption_photos.bind(this));},'.sort-photos > a':function(a){a.obs('click',this.sort_photos.bind(this));},'.edit-album > a':function(a){a.obs('click',this.edit_album_popup.bind(this));}},initialize:function(context){this.context=context;this.upload_popup=new IPopup(425,'portlet-photo-upload','Upload Photos');this.edit_popup=new IPopup(350,'portlet-edit-media-album','Edit Album');},upload_photos_popup:function(evt){evt.stop();this.upload_popup.show();},edit_album_popup:function(evt){evt.stop();this.edit_popup.show();},caption_photos:function(evt){var portlet=this.load_organize_portlet(this.caption_photos.bind(this,evt),evt);if(!portlet)
return;portlet.MediaAlbumOrganize.caption_mode();},sort_photos:function(evt){var portlet=this.load_organize_portlet(this.sort_photos.bind(this,evt),evt);if(!portlet)
return;portlet.MediaAlbumOrganize.sort_mode();},load_organize_portlet:function(callback,evt){var ent=HLG.extract_entity(this.context);var portlet=$$('.portlet-media-album-organize.'+ent.className)[0];if(portlet||$$('.portlet-media-album.'+ent.className)[0]){evt.stop();var url=evt.element().href;url='/'+url.substr(url.indexOf(HOME)+HOME.length);dooh.add(url);if(portlet)
return portlet;new Ajax.Request('ajax/media_album.php',{method:'post',parameters:{'_submit_check':'load_organize_portlet','o_entity[type]':ent.type,'o_entity[id]':ent.id},onSuccess:function(t){if(this.receive_organize_portlet(t,ent))
callback();}.bind(this)});}
return null;},receive_organize_portlet:function(t,ent){if(!t.responseJSON||t.responseJSON.errors||!t.responseJSON.content.portlet)
return false;$$('.portlet-media-album.'+ent.className)[0].replace(t.responseJSON.content.portlet);HLG.MediaAlbumOrganize.load();HLG.contentChanged();return true;}});HLG.EntityFeed={show_more:function(a,entity,last_id){var portlet=a.up('.portlet');a.hide();portlet.down('.show-more .processing').show();var last=portlet.down('li.last.feed_entry');if(!Object.isUndefined(last)){var matches=last.className.match(/entity-feed_entry-(\d+)/)
last_id=matches[1];}
new Ajax.Request('ajax/entity_feed.php',{method:'get',parameters:{entity:entity,last_id:last_id},onSuccess:function(response){portlet.down('.show-more').remove();if(!Object.isUndefined(last)){last.removeClassName('last');}
portlet.insert(response.responseText);}});},delete_entry:function(a,efe_id){if(!confirm('Are you sure you want to delete this item?')){return;}
var li=a.up('li.entity');a.hide();var processing=li.down('.delete img');processing.show();new Ajax.Request('ajax/delete_feed_entry.php',{method:'post',parameters:{efe_id:efe_id},onSuccess:function(response){if(response.responseJSON.errors){processing.hide();a.show();alert(response.responseJSON.errors);}else{if(li.hasClassName('first')&&!li.hasClassName('last')){li.next().addClassName('first');}else if(li.hasClassName('last')&&!li.hasClassName('first')){li.previous().addClassName('last');}
li.remove();}}});}}