/*
HTTP Host: b.static.ak.fbcdn.net
Generated: March 19th 2010 2:25:58 AM PDT
Machine: 10.16.139.110
Locale: nu_ll
Path: js/polls/social_poll.js
*/

if (window.CavalryLogger) { CavalryLogger.start_js(["js\/polls\/social_poll.js"]); }

function SocialPollController(_L0,_L1,_L2){this.poll_id=_L0;this.is_answered=_L1;this.is_social=_L2;this._init();}copy_properties(SocialPollController,{POLL_STATE_INITIAL:0,POLL_STATE_ANSWERED:1,MAX_RESULT_WIDTH:300});copy_properties(SocialPollController.prototype,{_init:function(){if(!this.is_answered){var _L0=DOM.scry($('choices_'+this.poll_id),'input[type="radio"]');if(_L0)for(var i=0;i<_L0.length;i++){var _L2=_L0[i];_L2.listen('click',this._vote.bind(this,_L2));}}if(this.is_social){var _L3=DOM.scry($('who_voted_'+this.poll_id),'a.show_friend_votes');if(_L3){show_friend_link=_L3[0];show_friend_link.listen('click',this._showFriends.bind(this));}}var _L4=DOM.scry(ge('delete_'+this.poll_id),'a.x_to_hide');if(_L4.length>0){var _L5=_L4[0];_L5.listen('click',this.deleteSocialPoll.bind(this));}},_showFriends:function(){var _L0=DOM.scry($('answers_'+this.poll_id),'div.friends');for(var i=0;i<_L0.length;i++){var _L2=_L0[i];if(_L2.childNodes.length>0)if(!shown(_L2)){animation(_L2).show().from('height',0).to('height','auto').duration(200).go();}else animation(_L2).to('height',0).duration(200).hide().go();}return false;},_vote:function(_L0){var _L1=_L0.value;var _L2=$('choices_'+this.poll_id);var _L3=DOM.scry(_L2,'input.inputradio');var _L4=0;var _L5=Vector2.getElementPosition(_L0);var _L6=Vector2.getElementPosition(_L2);var _L7=new Vector2(_L4,_L5.y-_L6.y,'document');for(var i=0;i<_L3.length;i++)_L3[i].disabled=true;var _L9=_L2.find('img.submit_progress');_L7.setElementPosition(_L9);_L0.setStyle('visibility','hidden');_L9.removeClass('hidden');new AsyncRequest().setURI("/ajax/polls/social_poll_vote.php").setMethod('POST').setData({poll_id:this.poll_id,vote:_L1}).setHandler(this.socialPollShowResults.bind(this)).setErrorHandler(this._socialPollAjaxFailureHandler.bind(this)).setTransportErrorHandler(this._socialPollAjaxFailureHandler.bind(this)).send();return false;},_socialPollAjaxFailureHandler:function(_L0){var _L1=$('choices_'+this.poll_id);var _L2=_L1.find('img.submit_progress');_L2.addClass('hidden');},socialPollShowResults:function(_L0){var _L1=$('choices_'+this.poll_id);var _L2=_L1.find('img.submit_progress');_L2.addClass('hidden');DOM.replace($('choices_'+this.poll_id),HTML(_L0.getPayload()));this.animatePollResults();show($('who_voted_'+this.poll_id));},animatePollResults:function(){var _L0=DOM.scry($('answers_'+this.poll_id),'div.result_bar');for(var i=0;i<_L0.length;i++){var bar=_L0[i];var _L3=bar.offsetWidth;bar.setStyle('width','0px');animation(bar).from('width',0).to('width',_L3).duration(500).ease(animation.ease.both).go();}},deleteSocialPoll:function(){new Dialog().setTitle(_tx("Delete Poll")).setBody(_tx("Are you sure you want to delete this poll? This action cannot be undone.")).setButtons([Dialog.OK,Dialog.CANCEL]).setHandler(this._deleteSocialPoll.bind(this)).show();},_deleteSocialPoll:function(){var _L0=$('pollrow_'+this.poll_id).find('div.polltitle h3');DOM.setContent(_L0,_tx("Deleting Poll..."));hide(ge('answers_'+this.poll_id));hide(ge('choices_'+this.poll_id));hide(ge('who_voted_'+this.poll_id));hide(ge('vote_count_'+this.poll_id));var _L1=DOM.find($('delete_'+this.poll_id),'a.x_to_hide');_L1.setStyle('background','url(/images/loaders/indicator_blue_small.gif?8:111099)'+' no-repeat scroll center');_L1.setStyle('width','16px');var _L2=new AsyncRequest().setURI('/ajax/polls/social_poll_delete.php').setMethod('POST').setData({poll_id:this.poll_id}).setHandler(this._deleteSocialPollAjaxHandler.bind(this)).setErrorHandler(this._deleteSocialPollAjaxFailureHandler.bind(this)).send();},_deleteSocialPollAjaxHandler:function(_L0){var _L1=$('pollrow_'+this.poll_id);DOM.empty(_L1);hide(_L1);return false;},_deleteSocialPollAjaxFailureHandler:function(_L0){hide($('delete_'+this.poll_id));}});

if (window.Bootloader) { Bootloader.done(["js\/polls\/social_poll.js"]); }