document.observe("dom:loaded",function(){new Fabtabs('tabs',{hover:false});new SMC.addFriend('add-friend');new SMC.removeFriend('remove-friend');});SMC.Friend={initialize:function(C,status){this.el_friend=$(C);if(!this.el_friend)return;this.status={is_added_friend:false,is_mutual:false,need_confirm:false};Object.extend(this.status,status||{});this.el_friend.observe('click',function(event){this.__getFirstCallNamespace();this.__jsonRequest();}.bind(this));},__getFirstCallNamespace:Prototype.emptyFunction,__jsonRequest:function(){this.status.is_sending=true;SMC.livebox.loading();new Ajax.Request("/common/mytravel.php",{method:'GET',parameters:'namespace='+this.namespace+'&permalink='+SMC.User.profile.username,onSuccess:function(transport,json)
{if(!json.error&&json.status){Object.extend(this.status,json.status||{});this.__updateStatus(json.text);}else if(json.error){if(!json.error.login){SMC.livebox.update(json.text,{error:true});}else this.__ajaxError(json.text);}
else this.__ajaxError({body:SMC.I18n.undefined_error,title:'Error!'});}.bind(this),onFailure:function(){this.__ajaxError({body:SMC.I18n.undefined_error,title:'Error!'});}.bind(this)});},__ajaxError:function(json){SMC.Callback=Prototype.emptyFunction;SMC.livebox.update(json,{error:true,buttons:1});}};SMC.addFriend=Class.create(Object.extend(SMC.Friend,{__getFirstCallNamespace:function(){this.namespace='check_friend';},__updateStatus:function(json){if(!this.status.is_mutual&&!this.status.is_added_friend){SMC.livebox.update(Object.extend(json,{action_name:!this.status.need_confirm?SMC.I18n.send_request:SMC.I18n.accept}),{buttons:2,error:false});SMC.Callback=function(param){if(param){this.namespace='add_friend';this.__jsonRequest();}}.bind(this);}
else{SMC.Callback=Prototype.emptyFunction;SMC.livebox.update(json,{buttons:1,error:false});this.el_friend.replace('<span class="added-friend">'+SMC.I18n.added_friend+'</span>');}}}));SMC.removeFriend=Class.create(Object.extend(SMC.Friend,{__getFirstCallNamespace:function(){this.namespace='request_delete_friend';},__updateStatus:function(json){if(this.status.is_mutual){SMC.livebox.update(Object.extend(json,{action_name:SMC.I18n.deleted}),{buttons:2,error:false});SMC.Callback=function(param){if(param){this.namespace='remove_friend';this.__jsonRequest();}}.bind(this);}else{SMC.Callback=Prototype.emptyFunction;SMC.livebox.update(json,{buttons:1,error:false});window.location.href=window.location.href;}}}));
