function trackPageview(url){if(window._gaq===undefined)return;var cmd=['_trackPageview'];url&&cmd.push(url);_gaq.push(cmd)}
function trackEvent(category,action,label,value){if(window._gaq===undefined)return;var cmd=['_trackEvent',category,action];label&&cmd.push(label);value&&cmd.push(value);_gaq.push(cmd)};(function($){var open=false;var callback=null;var $window=$(window),$overlay,$dialog,$dialog_content,$dialog_close;$.dialog=function(url,cb){$overlay.addClass('loading').show();$.get(url,function(response){if(response[0]=='{')response=$.parseJSON(response);if(typeof response=='string'){$dialog_content.html(response);$dialog.removeClass('cloud');$overlay.removeClass('loading');position()};if(response.show_cloud)$.cloud($('#cc_'+response.show_cloud).html());if(response.cloud_content)$.cloud(response.cloud_content)});if(cb)callback=cb;trackEvent('dialog',url.replace(/^\/(.+)(\?.+)?$/,'$1'));return this};$.cloud=function(html,cb){$dialog.addClass('cloud');$overlay.show();$dialog_content.html(html);position();if(cb)callback=cb;return this}
function position(){$dialog.css({marginTop:Math.max(-$dialog.height()/2,-$window.height()/2),marginLeft:-$dialog.width()/2,visibility:'visible'});open=true};$.dialog.set_content=function(html){$dialog_content.html(html);position()};$.dialog.close=$.cloud.close=function(){$dialog.css('visibility','hidden').removeClass('cloud');$dialog_content.empty();$overlay.hide();open=false;callback=null};$.dialog.complete=$.cloud.complete=function(){if(callback)callback.apply(this,arguments);this.close()};$(function(){$overlay=$('<div id="dialog_overlay"></div>').hide();$dialog=$('<div id="dialog"></div>').append($dialog_content=$('<div id="dialog_content"></div>'),$dialog_close=$('<div id="dialog_close">✕</div>')).css('visibility','hidden');$('body').append($overlay,$dialog);$dialog_close.click($.dialog.close);$(document).bind('keydown',function(e){if(open&&e.which==27){e.preventDefault();$.dialog.close()}})})})(jQuery);(function($){$.fn.showOverlay=function(){var offset=this.offset();var overlay=$('<div class="overlay"></div>').css({left:offset.left,top:offset.top,width:this.outerWidth(),height:this.outerHeight()}).appendTo('body');this.data('overlay',overlay);return this};$.fn.showLoading=function(){this.showOverlay().data('overlay').addClass('loading');return this};$.fn.hideOverlay=$.fn.hideLoading=function(){this.data('overlay').remove();return this}})(jQuery);(function($){$.fn.countdown=function(){var timer=this;var ts=timer.data('ts');var format=timer.data('format')||'h:m:s';setInterval((function(){var h,m,s;var diff=ts-Math.round((new Date()).getTime()/1000);if(diff>0){h=Math.floor(diff/3600);m=Math.floor((diff%3600)/60);s=diff%60}else h=m=s=0;timer.text(format.replace('h',h).replace('m',(m>9?m:'0'+m)).replace('s',(s>9?s:'0'+s)));return arguments.callee})(),1000)}})(jQuery);jQuery.cookie=function(key,value,options){if(arguments.length>1&&String(value)!=='[object Object]'){options=jQuery.extend({},options);if(value===null||value===undefined)options.expires=-1;if(typeof options.expires==='number'){var seconds=options.expires,t=options.expires=new Date();t.setTime(t.getTime()+(t.getTimezoneOffset()*-60)+seconds*1000)};value=String(value);return (document.cookie=[encodeURIComponent(key),'=',options.raw?value:encodeURIComponent(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''))};options=value||{};var result,decode=options.raw?function(s){return s}:decodeURIComponent;return (result=new RegExp('(?:^|; )'+encodeURIComponent(key)+'=([^;]*)').exec(document.cookie))?decode(result[1]):null};$('body').delegate('a[rel="dialog"]','click',function(){$.dialog($(this).attr('href'));return false}).delegate('[rel="cloud"]','click',function(){$.cloud($('#cc_'+$(this).data('cc')).html());trackEvent('cloud',$(this).data('cc'));return false});$(function(){var timeout;var start_blinking=(function(){clearTimeout(timeout);var indicators=$('header nav .count');(function(){indicators.toggleClass('invisible');timeout=setTimeout(arguments.callee,indicators.hasClass('invisible')?500:1000)})();return arguments.callee})();if($('body').hasClass('unauth'))return;var orig_title=document.title;var messages=$('header nav .messages');setInterval(function(){$.get('/update',function(response){if(!messages.hasClass('current')){if(response.unread_chats_c>0)document.title='('+response.unread_chats_c+') '+orig_title;else document.title=orig_title;if(response.unread_chats_i){messages.find('i').remove();messages.children('a').append(response.unread_chats_i);start_blinking()}};$('#n').replaceWith(response.notifs);$('#c').replaceWith(response.connections);$('#action .countdown').countdown();$('#quest .countdown').countdown()},'json')},20000)});$('#success_msg .close').click(function(){$('#success_msg').slideUp()});$(function(){$('.countdown').each(function(){$(this).countdown()})});$('aside').delegate('#quest .actions a','click',function(){$.get($(this).attr('href'),function(response){$('#quest').replaceWith(response);$('#quest .countdown').countdown()});return false}).delegate('#notifs .button.thank','click',function(){$.get($(this).attr('href'));$(this).siblings('.del').click();return false}).delegate('#notifs .del','click',function(){$.get($(this).attr('href'));$(this).parent().slideUp('fast',function(){$(this).remove();if($('#notifs li').length==0)$('#notifs').remove()});$('#notifs li:nth-child(5)').slideDown('fast');return false});$('#chat_proposal .more').live('click',function(){var proposal=$('#chat_proposal').showLoading();$.get('/propose_chat',function(response){proposal.hideLoading();$('#chat_proposal').replaceWith(response)})});(function(){var promo=$('#informer_promo').hide();if(promo.length)$(function(){setTimeout(function(){promo.slideDown()},1000)})})();(function(){var promo_blocks=$('.promo:not(.expanded)').hide();if(promo_blocks.length)$(function(){setTimeout(function(){promo_blocks.slideDown()},1000)});$('#main').delegate('.promo .close','click',function(){var block=$(this).parent().slideUp();$.cookie('hide_'+block.attr('id'),true,{expires:2*3600});trackEvent('promo','close',block.attr('id').slice(0,-6));return false})})();$('#main').delegate('.pa_add_to_favs a, .pa_block a','click',function(){$('.pa_more').removeClass('opened');$.post($(this).attr('href'),$.cloud);return false}).delegate('.pa_more','click',function(event){if($(this).hasClass('opened'))return;event.stopPropagation();$('.pa_more').removeClass('opened');$(this).addClass('opened');$(document).click(function(){$('.pa_more').removeClass('opened');$(document).unbind('click',arguments.callee)})});$(document).keypress(function(e){if(e.which==99)$('#control_panel').toggle()});var init_signup=function(){$('#main').delegate('#signup_form','submit',function(){var button=$(this).find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(response){button.hideLoading();$('#signup_form').replaceWith(response);$('.homepage_people.right').fadeTo('fast',0.25);focus()});return false}).delegate('#user_city_name','click focus',function(){$.dialog('/geo',function(id,city,country){$('#user_city_id').val(id);$('#user_city_name').val(city+', '+country)})}).delegate('#quick_city_select span','click',function(){$('#user_city_id').val($(this).data('id'));$('#user_city_name').val($(this).text()+', '+$(this).data('country'))});var focus=function(){var email=$('#user_email');if(email.length&&(!email.val()||email.next('.error').length))email.focus();else{var name=$('#user_name');if(!name.val()||name.next('.error').length)name.focus()}};focus()};var init_complete_signup=function(){$('#main').delegate('#complete_signup .toggle','click',function(){$('#email_correction_form').fadeToggle()}).delegate('#email_correction_form','submit',function(){var button=$(this).find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(response){button.hideLoading();$('#complete_signup').replaceWith(response)});return false})};var init_signin=function(){$('#main').delegate('#signin_form','submit',function(){var button=$(this).find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(response){button.hideLoading();$('#signin_form').replaceWith(response);$('.homepage_people.right').fadeTo('fast',0.25);focus()});return false});var focus=function(){var email=$('#user_email');if(!email.val()||email.next('.error').length)email.focus();else $('#user_pwd').focus()};focus()};var init_renew_password=function(){$('#main').delegate('#renew_password form','submit',function(){var button=$(this).find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(response){button.hideLoading();$('#renew_password').replaceWith(response);focus()});return false});var focus=function(){$('#renew_password input:first').focus()};focus()};var init_mine_profile=function(){$('#wish, #wish_editor_cancel').click(function(){$('#wish, #wish_editor').toggle();if(!$('#wish_editor').is(':hidden'))$('#wish_text').select()});$('#wish_editor').submit(function(){var button=$(this).find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(response){$('#wish em').html(response);$('#wish, #wish_editor').toggle();button.hideLoading()});return false});$('#profile').delegate('.section .edit','click',function(){if($(this).attr('href')=='/user/location'){$.dialog('/geo',function(id){$.post('/user/location',{city_id:id},function(response){if(response.success)$('#location').html(response.html)},'json')});return false};$('.info_editor .cancel').click();var link=$(this).showLoading();var section=$(this).closest('.section');$.get($(this).attr('href'),function(response){section.hide();link.hideLoading();section.before(response);$('.info_editor textarea:empty').focus()});return false}).delegate('.info_editor','submit',function(){var editor=$(this);var button=editor.find('button:submit').showLoading();$.post(editor.attr('action'),editor.serialize(),function(response){button.hideLoading();if(response.success){editor.next('.section').html(response.html).show();editor.remove()}else editor.replaceWith(response.html)},'json');return false}).delegate('.info_editor .cancel','click',function(){var editor=$(this).closest('.info_editor');editor.next('.section').show();setTimeout(function(){editor.remove()},0)});var current_profile_bg=$('#profile_bgs .current').attr('rel');$('#profile_bgs').delegate('a','click',function(){var bg=$(this).attr('rel');$('#profile_bgs .selected').removeClass('selected');$(this).addClass('selected');$('#profile_decor .actions').toggle(bg!=current_profile_bg);$('html').attr('id','bg_'+bg);return false});$('#profile_decor button').click(function(){$('#profile_decor .actions').hide();$('#profile_bgs .current').removeClass('current');var selected=$('#profile_bgs .selected').toggleClass('selected current');selected.parent().prependTo('#profile_bgs');$.post(selected.attr('href'))});$('#profile_decor .cancel').click(function(){$('#profile_decor .actions').hide();$('#profile_bgs .selected').removeClass('selected');$('html').attr('id','bg_'+current_profile_bg)})};var init_profile=function(){};var init_photos=function(){$('#photos').sortable({containment:'parent',items:'li:not(.add_more)',placeholder:'placeholder',forcePlaceholderSize:true,tolerance:'pointer',revert:200,update:function(event,ui){var new_order=[];$('#photos li:not(.add_more)').each(function(){new_order.push($(this).data('id'))});$.post(location.pathname,{new_order:new_order})}});$('#photos .rotate').click(function(){var photo=$(this).parent().showLoading();$.post($(this).attr('href'),function(response){var img=photo.find('img');var w=img.width(),h=img.height();img.attr('src',img.attr('src').replace(/(\?\d+)?$/,'?'+(new Date()).getTime())).attr('width',Math.round(h*response.new_ratio));photo.hideLoading()});return false});$('#photos .delete').click(function(){if(!confirm('Удалить выбранную фотографию?'))return false;var photo=$(this).parent().showLoading();$.post($(this).attr('href'),function(){photo.hideLoading().remove()});return false})};var init_search=function(){var ajax_request;$('#main').delegate('#location','click focus',function(){$.dialog('/geo?search=1',function(country_id,region_id,city_id){$('#search_form input[name="country_id"]').val(country_id||'');$('#search_form input[name="region_id"]').val(region_id||'');$('#search_form input[name="city_id"]').val(city_id||'');$('#search_form').submit()});return false}).delegate('#search_type_toggle a[href^="/search"]','click',function(){if($('#extra_fields .active').length){if(confirm('Очистить расширенные критерии поиска?')){$('#extra_fields .reset').click();$('#search_form').submit()}else return false};$('#search_type_toggle a').html($('#extra_fields').is(':hidden')?'<span>Простой поиск</span><i class="triangle up"></i>':'<span>Расширенный поиск</span><i class="triangle down"></i>');$('#extra_fields').slideToggle();trackEvent('search','type_switch',$('#extra_fields').is(':hidden')?'advanced':'simple');return false}).delegate('#extra_fields .criterion','change',function(){var value=$(this).val();var field=$(this).closest('.field').toggleClass('active',!!value);field.find('.extra_field_options').appendTo('#extra_field_options_container');$('#'+value).appendTo(field);update_search_form_state()}).delegate('#extra_fields .reset','click',function(){var field=$(this).closest('.field').removeClass('active');field.find('select').val('');field.find('.extra_field_options').appendTo('#extra_field_options_container')}).delegate('#search_form','submit',function(){$('#search').showOverlay().addClass('loading');if(ajax_request)ajax_request.abort();ajax_request=$.post($(this).attr('action'),$(this).serialize(),function(response){$('#search').hideOverlay().replaceWith(response);update_search_form_state()});return false}).delegate('#search_filter a, #search_result .pager a','click',function(){History.pushState(null,null,$(this).attr('href'));return false});$(window).bind('statechange',function(){$('#search_result').showOverlay();$('#search').addClass('loading');var url=History.getState().url;ajax_request=$.get(url,function(response){$('#search_result').hideOverlay();$('#search').replaceWith(response);update_search_form_state();$(window).scrollTop($('#main').offset().top);trackPageview(url)})});var update_search_form_state=function(){$('#extra_fields .criterion option').removeAttr('disabled');$('#extra_fields .criterion').each(function(){if($(this).val()=='')return;$('#extra_fields .criterion[name!="'+$(this).attr('name')+'"] option[value="'+$(this).val()+'"]').attr('disabled','disabled')})};update_search_form_state()};var init_encounters=function(){$('#encounters').delegate('#encounter_answers a','click',function(){$('#encounter_person').showLoading();$.post($(this).attr('href'),{id:$('#encounter_person').data('id')},function(response){if(response.person){var next=$('#next_people li:not(:animated)').eq(0);var offset=next.outerWidth(true);next.animate({marginLeft:-offset,opacity:0},{speed:offset,complete:function(){$(this).remove()}});$('#encounter_person').hideLoading().replaceWith(response.person)}else $('#encounter_person').hideLoading();if(response.quest_html){$('#quest').replaceWith(response.quest_html);$('#quest .countdown').countdown()};if(response.next_people_tail)$(response.next_people_tail).hide().appendTo('#next_people ul').fadeIn();else if($('#next_people li').length==0)$('#next_people').addClass('hidden');if(response.you_want){var you_want_count=$('#connections a[href="/connections/you_want"] .count');you_want_count.text(parseInt(you_want_count.text())+1)};if(response.mutual){var mutual_count=$('#connections a[href="/connections/mutual"] .count');mutual_count.text(parseInt(mutual_count.text())+1)};if(response.cloud_content)$.cloud(response.cloud_content)},'json');return false}).delegate('#encounter_more_photos a','click',function(){var item=$(this).parent();if(item.hasClass('current'))return false;var width=$(this).data('width');var offset=width>$('#encounter_photo').width()?' style="margin-left: -'+Math.round((width-$('#encounter_photo').width())/2)+'px;"':'';$('#encounter_photo').html('<img src="'+$(this).data('url')+'" width="'+width+'" height="'+$(this).data('height')+'"'+offset+'>');$('#encounter_more_photos li').removeClass('current');item.addClass('current');if(item.prev().length){var offset=$('#encounter_more_photos').scrollLeft()+item.prev().position().left;$('#encounter_more_photos').animate({scrollLeft:offset},{speed:offset})};return false})};var init_map=function(){window.map=new YMaps.Map($('#map')[0]);map.enableScrollZoom();map.enableHotKeys({smooth:true});map.enableRightButtonMagnifier({smooth:true});map.setCenter(new YMaps.GeoPoint(lng,lat),13);map.addControl(new YMaps.ToolBar());map.addControl(new YMaps.Zoom());var load_people=function(){var b=map.getBounds();var lb=b.getLeftBottom();var rt=b.getRightTop();$.post('/map',{'b[t]':rt.getLng(),'b[r]':rt.getLat(),'b[b]':lb.getLng(),'b[l]':lb.getLat()},function(response){map.removeAllOverlays();$.each(response.people,function(i,p){var style=new YMaps.Style();style.iconStyle=new YMaps.IconStyle();style.iconStyle.href='http://i.yabadu.ru/48x48/'+p.photo;style.iconStyle.size=new YMaps.Point(24,24);style.iconStyle.offset=new YMaps.Point(-12,-12);var placemark=new YMaps.Placemark(new YMaps.GeoPoint(p.lng,p.lat),{style:style});placemark.setBalloonContent('<a href="/'+p.id+'"><img src="http://i.yabadu.ru/120x120/'+p.photo+'" width="120" height="120">'+p.name+'</a>');map.addOverlay(placemark)})},'json')};YMaps.Events.observe(map,map.Events.DragEnd,load_people);YMaps.Events.observe(map,map.Events.SmoothZoomEnd,load_people);if(navigator.geolocation)navigator.geolocation.getCurrentPosition(function(pos){lat=pos.coords.latitude;lng=pos.coords.longitude;map.setCenter(new YMaps.GeoPoint(lng,lat),13);$.post('/map',{lat:lat,lng:lng});load_people()},function(error){},{enableHighAccuracy:true});else load_people()};var init_rate=function(){$('#encounters').delegate('#rating a','click',function(){$('#encounter_person').showLoading();$.post($(this).attr('href'),{id:$('#encounter_person').data('id')},function(response){if(response.person)$('#encounter_person').hideLoading().replaceWith(response.person);else $('#encounter_person').hideLoading();if(response.cloud_content)$.cloud(response.cloud_content);if(response.quest_html){$('#quest').replaceWith(response.quest_html);$('#quest .countdown').countdown()};if(response.wallet_credits)$('#user_tools .wallet a').text(response.wallet_credits);if(response.fill_wallet)$.dialog('/wallet/fill')},'json');return false}).delegate('#encounter_more_photos a','click',function(){var item=$(this).parent();if(item.hasClass('current'))return false;var width=$(this).data('width');var offset=width>$('#encounter_photo').width()?' style="margin-left: -'+Math.round((width-$('#encounter_photo').width())/2)+'px;"':'';$('#encounter_photo').html('<img src="'+$(this).data('url')+'" width="'+width+'" height="'+$(this).data('height')+'"'+offset+'>');$('#encounter_more_photos li').removeClass('current');item.addClass('current');if(item.prev().length){var offset=$('#encounter_more_photos').scrollLeft()+item.prev().position().left;$('#encounter_more_photos').animate({scrollLeft:offset},{speed:offset})};return false})};var init_duels=function(){$('#main').delegate('#duel .choice, #skip','click',function(){$('#duel').showLoading();$.post($(this).attr('href'),function(response){if(response.duel)$('#duel').hideLoading().replaceWith(response.duel);else $('#duel').hideLoading();if(response.quest_html){$('#quest').replaceWith(response.quest_html);$('#quest .countdown').countdown()}},'json');return false})};var init_chats=function(){$('#main').delegate('#chats .pa_delete a','click',function(){$.get($(this).attr('href'));$(this).parents('#chats > li').slideUp();return false});$('#main').delegate('#chats_filter a, .pager a','click',function(){History.pushState(null,null,$(this).attr('href'));return false});$(window).bind('statechange',function(){$('#chats').showOverlay();var url=History.getState().url;$.get(url,function(response){$('#chats').hideOverlay();$('#main').html(response);$(window).scrollTop($('#main').offset().top)})})};var init_chat=function(){var interlocutor=$('#chat .person');var messages=$('#chat_messages');var chat_form=$('#chat_form');if(chat_form.length){if($('body').hasClass('vk'))messages.scrollTop(messages[0].scrollHeight);else $(window).bind('resize',function(){var height=Math.max($(window).height()-messages.offset().top-$('#chat_form').outerHeight()-40,420);messages.height(height).scrollTop(messages[0].scrollHeight)}).trigger('resize');var msg_body=$('#chat_form textarea[name="body"]');msg_body.focus();msg_body.keypress(function(e){if(e.which==13&&!e.shiftKey){e.preventDefault();$('#chat_form').submit()}});$('#chat_form').submit(function(){$(this).showLoading();var body=$.trim(msg_body.val());if(body){msg_body.blur();$.post($(this).attr('action'),$(this).serialize(),function(response){if(response.success){$('#first_msg_precept, #last_msg_status').remove();$(response.html).hide().appendTo(messages).fadeIn();var height=messages[0].scrollHeight;messages.animate({scrollTop:height},{speed:height-messages.scrollTop()});msg_body.val('').focus()};$('#chat_form').hideLoading()},'json');var photo_id=$('#chat_form input[name="photo_id"]');if(photo_id.length){photo_id.next('a').remove();photo_id.next('h2').text('Напишите сообщение');photo_id.remove();History.pushState(null,null,$(this).attr('action'))}}else msg_body.val('').focus();return false});var orig_title=document.title.split(' — ');var window_is_active=false;var new_messages_count=0;$(window).focus(function(){window_is_active=true;new_messages_count=0;document.title=orig_title.join(' — ')});$(window).blur(function(){window_is_active=false});var calc_update_timeout=function(){var online=interlocutor.children('.online');return online.length?4000:30000};var update=function(){$.get($('#chat_form').attr('action')+'?update=1',function(response){if(response.p_status){interlocutor.children('.online').remove();interlocutor.append(response.p_status)};if(response.html){$('#last_msg_status').remove();$(response.html).hide().appendTo(messages).fadeIn();if(!window_is_active){new_messages_count+=response.new_messages;document.title='('+new_messages_count+') '+orig_title[1]}};if(response.last_msg_status){var status=$('#last_msg_status');if(status.length)status.replaceWith(response.last_msg_status);else messages.append(response.last_msg_status)};if(response.html||response.last_msg_status){var height=messages[0].scrollHeight;messages.animate({scrollTop:height},{speed:height-messages.scrollTop()})};setTimeout(update,calc_update_timeout())},'json')};setTimeout(update,calc_update_timeout());$('#emoticons_toggle').click(function(event){event.stopPropagation();$('#emoticons').show();var triangle=$(this).children('.triangle').toggleClass('down up');$(document).click(function(){$('#emoticons').hide();triangle.toggleClass('down up');$(document).unbind('click',arguments.callee)})});$('#emoticons li').hover(function(){$('#emoticon_name').text($(this).data('name'))},function(){$('#emoticon_name').text('Выберите смайлик')}).click(function(){var textarea=$('#chat_form textarea');textarea.val(textarea.val()+' '+$(this).data('code'));$('#emoticons').toggle()})}};var init_connections=function(){$('#main').delegate('#c_people input:checkbox','change',function(){if($('#c_people input:checked').length)$('#c_toolbar button').removeAttr('disabled');else $('#c_toolbar button').attr('disabled','disabled');if($('#c_people input:not(:checked)').length)$('#c_toolbar input:checkbox').removeAttr('checked');else $('#c_toolbar input:checkbox').attr('checked','checked')}).delegate('#c_toolbar input:checkbox','change',function(){if($(this).is(':checked'))$('#c_people input:checkbox').attr('checked','checked');else $('#c_people input:checkbox').removeAttr('checked');$('#c_people input:checkbox').eq(0).change()}).delegate('#c_people_form','submit',function(){$.post($(this).attr('action'),$(this).serialize(),function(response){$('#main').html(response.html);$('aside').html(response.aside)},'json');return false}).delegate('.pager a','click',function(){History.pushState(null,null,$(this).attr('href'));return false});$(window).bind('statechange',function(){var url=History.getState().url;$.get(url,function(response){$('#main').html(response.html);$('aside').html(response.aside);$(window).scrollTop($('#main').offset().top)},'json')});$('#c_people input:checkbox').eq(0).change()};var init_connections_want_you=function(){$('#main').delegate('#c_people .your_answer a','click',function(){$(this).closest('ul').showLoading();$.post($(this).attr('href'),function(response){location.reload()});return false})};var init_import=function(){$('#main').delegate('#import_main h2','click',function(){if($(this).hasClass('collapsed')){$('#import_main h2').toggleClass('collapsed');$('#import_main form').slideToggle()}}).delegate('#import_main form','submit',function(){$('#import_main').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(response){$('#import_main').hideLoading();$('#import').replaceWith(response)});return false}).delegate('#import_contacts .how_it_works','mouseover',function(){var tip=$('#import_contacts .tip');if($(this).hasClass('top'))tip.css({top:98,bottom:'auto'});else tip.css({top:'auto',bottom:46});tip.removeClass('hidden')}).delegate('#import_contacts .how_it_works','mouseout',function(){$('#import_contacts .tip').addClass('hidden')})};var init_invisibility_settings=function(){var actions=$('#settings form .actions').hide();$('#settings form').change(function(){actions.fadeIn()}).submit(function(){var button=actions.find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(){location.reload()});return false})};var init_notification_settings=function(){var actions=$('#settings form .actions').hide();$('#settings form').change(function(){actions.fadeIn()}).submit(function(){var button=actions.find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(){button.hideLoading();actions.fadeOut()});return false})};var init_settings=function(){$('#main').delegate('#settings form','submit',function(){var button=$(this).find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(response){button.hideLoading();$('#settings').replaceWith(response)});return false})};var init_feedback=function(){$('#main').delegate('#feedback_form','submit',function(){var button=$(this).find('button:submit').showLoading();$.post($(this).attr('action'),$(this).serialize(),function(response){button.hideLoading();$('#feedback').replaceWith(response)});return false});$('#feedback_form textarea').focus()};$.each(init_requests,function(i,item){window['init_'+item]()})
