/*    HTTP Host:  b.static.ak.fbcdn.net                                        */
/*    Generated:  March 25th 2009 3:28:52 PM PDT                               */
/*      Machine:  10.16.140.110                                                */
/*       Source:  Global Cache                                                 */
/*     Location:  js/emu/util.js h:26we37zz                                    */
/*       Locale:  en_US                                                        */
/*         Path:  js/emu/util.js                                               */


function EmuUIController(adId,frameId,state){this.adId=adId;this.frameId=frameId;this.state=state;this.emuFrame=$('emu_'+this.adId+'_'+this.frameId);DOMStorage.setData(this.emuFrame,'emuUIController',this);this._init();}
copy_properties(EmuUIController.prototype,{_init:abstractMethod,_getMoreUserContentText:abstractMethod,_initHiddenToggler:function(){var toggleLinks=DOM.scry(this.emuFrame,'a.UIMutableFilterList_Toggle');for(var i=0;i<toggleLinks.length;i++){toggleLinks[i].listen('click',this._toggleHidden.bind(this));}},_toggleHidden:function(){var hiddenDiv=DOM.find(this.emuFrame,'div.hidden_user_content');var showLink=DOM.find(this.emuFrame,'a.UIMutableFilterList_Show');var hideLink=DOM.find(this.emuFrame,'a.UIMutableFilterList_Hide');if(!shown(hiddenDiv)){animation(hiddenDiv).show().from('height',0).to('height','auto').from('opacity',0).to('opacity',1).duration(200).ease(animation.ease.both).go();showLink.addClass('hidden');hideLink.removeClass('hidden');}else{animation(hiddenDiv).to('height',0).from('opacity',1).to('opacity',0).hide().duration(200).ease(animation.ease.both).blind().go();showLink.removeClass('hidden');hideLink.addClass('hidden');}
return false;}});copy_properties(EmuUIController,{getController:function(adId,frameId){var emuFrame=$('emu_'+adId+'_'+frameId);var ret=DOMStorage.getData(emuFrame,'emuUIController');return ret;}});function CommentableEmuUIController(adId,frameId,state){this.parent.construct(this,adId,frameId,state);}
CommentableEmuUIController.extend('EmuUIController');copy_properties(CommentableEmuUIController.prototype,{_getCommentInput:abstractMethod,_init:function(){this._initCommentHandlers();this._initHiddenToggler();},_initCommentHandlers:function(){var commentInput=this._getCommentInput();if(commentInput){commentInput.listen('focus',this._commentOnFocus.bind(this));}
var submitBtn=DOM.scry(this.emuFrame,'input.submit_post')[0];if(submitBtn){submitBtn.listen('click',this._commentOnSubmit.bind(this));}},_commentOnFocus:function(){var submitBtn=DOM.find(this.emuFrame,'input.submit_post');submitBtn.disabled=false;submitBtn.removeClass('hidden');},_commentOnSubmit:function(evt){var commentInput=this._getCommentInput();var comment=commentInput.value;var placeholder=commentInput.getControl().getPlaceholderText();if(!comment||(comment==placeholder)){$E(evt).kill();}else{var progress=DOM.find(this.emuFrame,'img.submit_progress');progress.removeClass('hidden');}}});function emu_delete_video_comment(video_id,comment_id){new Dialog().setTitle(_tx("Delete Comment")).setBody(_tx("Are you sure you want to delete this comment?")).setButtons([{name:'delete',label:_tx("Delete"),handler:bind(this,function(){new AsyncRequest().setURI('/ajax/motion_comment.php').setData({v:video_id,d:comment_id}).setHandler(function(response){hide($('comment_'+comment_id));}).send();})},Dialog.CANCEL]).show();}
function CommentEmuUIController(adId,frameId,state){this.parent.construct(this,adId,frameId,state);return this;}
CommentEmuUIController.extend('CommentableEmuUIController');copy_properties(CommentEmuUIController.prototype,{_getMoreUserContentText:function(numHidden){if(numHidden==1){return _tx("1 more comment");}else{return _tx("{count} more comments",{'count':numHidden});}},_getCommentInput:function(){return DOM.scry(this.emuFrame,'input[name="comment"]')[0];}});function GiftEmuUIController(adId,frameId,state){this.parent.construct(this,adId,frameId,state);return this;}
GiftEmuUIController.extend('CommentableEmuUIController');copy_properties(GiftEmuUIController.prototype,{_init:function(){this.parent._init();this._adjustGiftsInIE6();},_adjustGiftsInIE6:function(){if(!(ua.ie()<7)){return;}
var giftImgs=DOM.scry(this.emuFrame,'img.wall_mini_gift_image');var hiddenDiv=DOM.scry(this.emuFrame,'div.hidden_user_content')[0];if(hiddenDiv){hiddenDiv.removeClass('hidden');}
for(var i=0;i<giftImgs.length;i++){var giftImg=giftImgs[i];giftImg.setStyle('width',giftImg.offsetWidth+1+'px');giftImg.setStyle('height',giftImg.offsetHeight+1+'px');adjustImage(giftImg);}
if(hiddenDiv){hiddenDiv.addClass('hidden');}},_getMoreUserContentText:function(numHidden){if(numHidden==1){return _tx("1 more gift");}else{return _tx("{count} more gifts",{'count':numHidden});}},_getCommentInput:function(){return DOM.scry(this.emuFrame,'textarea[name="gift_message"]')[0];}});copy_properties(GiftEmuUIController,{onFriendTokenAdded:function(formId,token){var formDiv=$(formId);var giftTo=DOM.find(formDiv,'input[name="gift_to"]');giftTo.value=token.i;CSS.removeClass(DOM.find(formDiv,'div.gift_form_wrapper'),'hidden');CSS.removeClass(DOM.find(formDiv,'div.gift_form_submit'),'hidden');},onFriendTokenRemoved:function(formId,token){var formDiv=$(formId);var giftTo=DOM.find(formDiv,'input[name="gift_to"]');giftTo.value=null;}});function InviteEmuUIController(adId,frameId,state){this.parent.construct(this,adId,frameId,state);return this;}
InviteEmuUIController.extend('CommentableEmuUIController');copy_properties(InviteEmuUIController.prototype,{_init:function(){this.parent._init();},_getCommentInput:function(){return DOM.scry(this.emuFrame,'input[name="email_list"]')[0];}});function ContactImporterEmuUIController(adId,frameId,state){this.parent.construct(this,adId,frameId,state);return this;}
ContactImporterEmuUIController.extend('EmuUIController');copy_properties(ContactImporterEmuUIController.prototype,{_init:function(){var elems=DOM.scry($('home_sponsor_nile'),'a.CIEmu_Link');for(var i=0;i<elems.length;i++){elems[i].listen('click',function(event){$(event).kill();$('address_book_login_form').submit();});}}});function EventEmuUIController(adId,frameId,state){this.parent.construct(this,adId,frameId,state);return this;}
EventEmuUIController.extend('CommentableEmuUIController');copy_properties(EventEmuUIController,{EVENT_STATE_INITIAL:1,EVENT_STATE_JUST_RSVP:2});copy_properties(EventEmuUIController.prototype,{_init:function(){var changeRSVPLink=DOM.scry(this.emuFrame,'a.rsvp_change')[0];if(changeRSVPLink){changeRSVPLink.listen('click',this._change_rsvp.bind(this));}
var rsvpRadios=DOM.scry(this.emuFrame,'input[name="rsvp_status_dummy"]');if(rsvpRadios){for(var i=0;i<rsvpRadios.length;i++){var radio=rsvpRadios[i];radio.listen('click',this._rsvp.bind(this,radio));}}
if(this.state==EventEmuUIController.EVENT_STATE_JUST_RSVP){this._updateRsvpStatusBg();this._initCommentHandlers();}
this._initHiddenToggler();},_change_rsvp:function(){var rsvpStatus=DOM.find(this.emuFrame,'div.rsvp_status');var rsvpInputs=DOM.find(this.emuFrame,'div.rsvp_inputs');var rsvpChange=DOM.find(this.emuFrame,'a.rsvp_change');CSS.addClass(rsvpStatus,'hidden');CSS.addClass(rsvpChange,'hidden');CSS.removeClass(rsvpInputs,'hidden');return false;},_rsvp:function(radioInput){var rsvpInputs=DOM.find(this.emuFrame,'div.rsvp_inputs');var progress=DOM.find(this.emuFrame,'img.rsvp_progress');var data={'linkId':3,'linkParam':radioInput.value}
emu_Client.getClient(this.adId).onEvent(this.frameId,emu_Client.constants.EMU_FRAME_EVENT_CLICK,data);CSS.addClass(rsvpInputs,'hidden');CSS.removeClass(progress,'hidden');},_updateRsvpStatusBg:function(){var statusPhrase=DOM.find(this.emuFrame,'span.rsvp_status_phrase');animation(statusPhrase).to('backgroundColor','#FFFFFF').from('#FFE8CC').duration(3000).go();},_getCommentInput:function(){return DOM.scry(this.emuFrame,'textarea[name="rsvp_comment"]')[0];},_getMoreUserContentText:function(numHidden){if(numHidden==1){return _tx("1 more RSVP from a friend");}else{return _tx("{count} more RSVPs from friends",{'count':numHidden});}}});copy_properties(EventEmuUIController,{onFriendTokenAdded:function(formId,token){var formDiv=$(formId);CSS.removeClass(DOM.find(formDiv,'div.invite_form_message'),'hidden');CSS.removeClass(DOM.find(formDiv,'div.invite_form_submit'),'hidden');}});function FanEmuUIController(adId,frameId,state){this.parent.construct(this,adId,frameId,state);return this;}
FanEmuUIController.extend('EmuUIController');copy_properties(FanEmuUIController.prototype,{_init:function(){this._initHiddenToggler();},_getMoreUserContentText:function(numHidden){numHidden-=3;if(numHidden==1){return _tx("1 more fan");}else{return _tx("{count} more fans",{'count':numHidden});}},justFanned:function(){var fanText=DOM.find(this.emuFrame,'div.fan_link');fanText.setStyle('backgroundColor','#fffccc');animation(fanText).duration(3000).checkpoint().to('backgroundColor','#FFFFFF').duration(1000).go();}});function PollEmuUIController(adId,frameId,state,isNile){this.isNile=isNile;this.parent.construct(this,adId,frameId,state);return this;}
PollEmuUIController.extend('EmuUIController');copy_properties(PollEmuUIController,{STATE_INITIAL:1,STATE_JUST_ANSWERED:2,STATE_ANSWERED:3,MAX_RESULT_WIDTH:230});copy_properties(PollEmuUIController.prototype,{showResults:function(results){var leadingResult=null;var leadingPercent=-1;var resultStyles={};for(var resultId in results){if(results[resultId]>leadingPercent){leadingResult=resultId;leadingPercent=results[resultId];}}
for(var resultId in results){var percent=results[resultId];var width=Math.round(percent/leadingPercent*PollEmuUIController.MAX_RESULT_WIDTH);var className='not_lead_result';if(resultId==leadingResult){className='lead_result';}
resultStyles[resultId]={'width':width,'className':className}}
for(var resultId in resultStyles){var barDiv=this._findHelper(DOM.find,'#poll_result_'+resultId+' .result_bar');var styles=resultStyles[resultId];var width=styles.width+'px';barDiv.setStyle('width',0);barDiv.addClass(styles.className);if(this.state==PollEmuUIController.STATE_JUST_ANSWERED){animation(barDiv).from('width',0).to('width',width).duration(500).ease(animation.ease.both).go();}else if(this.state==PollEmuUIController.STATE_ANSWERED){barDiv.setStyle('width',width);}}},_init:function(){if(this.state==PollEmuUIController.STATE_INITIAL){this._initAnswerRadios();}else{var friendCountLink=DOM.scry(this.emuFrame,'a.friend_count_link')[0];if(friendCountLink){friendCountLink.listen('click',this._onShowFriendsClick.bind(this));}}},_initAnswerRadios:function(){var answerRadios=this._findHelper(DOM.scry,'input[name="answer"]');if(answerRadios){for(var i=0;i<answerRadios.length;i++){var radio=answerRadios[i];radio.listen('click',this._onAnswer.bind(this,radio));}}},_onShowFriendsClick:function(){var friendVotePics=this._findHelper(DOM.scry,'div.friend_vote_pics');for(var i=0;i<friendVotePics.length;i++){var friendVotePic=friendVotePics[i];if(!shown(friendVotePic)){animation(friendVotePic).from('height',0).to('height','auto').duration(200).show().go();}else{animation(friendVotePic).to('height',0).duration(200).hide().go();}}
return false;},_onAnswer:function(radioInput){var answerId=radioInput.value;var container=this._findHelper(DOM.find,'div.answer_form');var progress=this._findHelper(DOM.find,'img.submit_progress');var radioArr=DOM.scry(container,'input.inputradio');var OFFSET_X=8;var radioVector=Vector2.getElementPosition(radioInput);var containerVector=Vector2.getElementPosition(container);var progressVector=new Vector2(OFFSET_X,radioVector.y-containerVector.y,'document');for(var i=0;i<radioArr.length;i++){radioArr[i].disabled=true;}
progressVector.setElementPosition(progress);radioInput.setStyle('visibility','hidden');progress.removeClass('hidden');var data={'linkId':2,'linkParam':answerId};emu_Client.getClient(this.adId).onEvent(this.frameId,emu_Client.constants.EMU_FRAME_EVENT_CLICK,data);},_findHelper:function(func,ele){if(!this.isNile){return func.call(null,this.emuFrame,ele);}
var poll_results=DOM.scry($('emu_'+this.adId),'div.poll_results');if(poll_results.length>0){return func.call(null,this.emuFrame,ele);}else{var radios_as_copy=ge('emu_poll_itb_'+this.adId);return func.call(null,radios_as_copy,ele);}}});

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