var accounts;var account;function init_home(){login(function(){get_authorized_accounts(function(a){accounts=a;if(accounts.length==0){show_authorize()}else{$profile_panel.show();$authorize_panel.hide();var b=new TextButton("update","post update",post_status);$(b).css("float","right");$(".profile_buttons",$profile_panel).append(b);$(".profile_buttons",$profile_panel).append(new TextButton("reconnect","connect to another twitter account",show_authorize));$(".left_arrow",$profile_panel).click(pre_account);$(".right_arrow",$profile_panel).click(next_account);show_profile(accounts[0]);update_buttons()}});$("#close-message-panel").bind("click",function(){$("#message-panel").hide();adjust_height()});$(document).bind("post-status",function(b,a){if(a.error){show_error(a.data)}});$(document).bind("pre-post-status",function(){show_message(null)});$(document).bind("post-post-status",function(){$("#status_textarea").val("input status here");$(".home-status-counter").html("");show_message("status updated!");setTimeout(function(){show_message(null)},5000)});$(document).ajaxError(function(c,b,a){show_error("ajax error");$("#status_textarea").attr("disabled",false)});$("#status_textarea").keyup(function(){$(".home-status-counter").html(140-$("#status_textarea").val().length)});$("#status_textarea").focus(function(){if($("#status_textarea").val()=="input status here"){setTimeout(function(){$("#status_textarea").select()},100)}});$("#status_textarea").blur(function(){if($("#status_textarea").val()==""){$("#status_textarea").val("input status here");$(".home-status-counter").html("")}});$(".delete-account",$profile_panel).click(remove_account);init_idle_checker()})}function post_status(){if($("#status_textarea").val()&&$("#status_textarea").val()!="input status here"){post_update(account,$("#status_textarea").val(),null,"post-status")}}function show_authorize(){get_authorize_url(function(a){if(counter_timer){clearInterval(counter_timer)}if(a&&a.url){$profile_panel.hide();$authorize_panel.show();$("#authorize_url").attr("href",a.url);adjust_height()}else{}},"get-authorize")}function pre_account(){var a=accounts.indexOf(account);if(a>0){show_profile(accounts[a-1])}update_buttons()}function next_account(){var a=accounts.indexOf(account);if(a<accounts.length-1){show_profile(accounts[a+1])}update_buttons()}var counter_timer;var counter_interval=180000;function show_profile(a){account=a;$(".profile_image",$profile_panel).html('<img class="profile_thumb" src="'+a.profile_image_url+'" title="go to home"/>');$(".profile_image>.profile_thumb",$profile_panel).unbind();$(".profile_image>.profile_thumb",$profile_panel).click(function(){show_account_in_canvas(a)});$(".profile_name",$profile_panel).html(a.name);$(".profile_name",$profile_panel).unbind();$(".profile_name",$profile_panel).click(function(){show_account_in_canvas(a)});$(".unread_counter",$profile_panel).html("");$(".unread_counter",$profile_panel).unbind();$(".unread_counter",$profile_panel).click(function(){show_account_in_canvas(a)});adjust_height()}var unread_since;var unread_num=0;function get_unread_counter(){get_unread(account,unread_since,function(a){if(a.unread_since!=0){unread_since=a.unread_since}if(a.reset){unread_num=a.num}else{unread_num+=a.num}if(unread_num>100){$(".unread_counter",$profile_panel).html("(100+)");counter_interval=600000;if(counter_timer){clearInterval(counter_timer)}counter_timer=setTimeout(get_unread_counter,counter_interval);return}if(unread_num>0){$(".unread_counter",$profile_panel).html("("+unread_num+")")}else{$(".unread_counter",$profile_panel).html("")}});if(is_idle){counter_interval=Math.min(counter_interval*2,1800000)}else{counter_interval=180000}counter_timer=setTimeout(get_unread_counter,counter_interval);is_idle=true}function show_account_in_canvas(a){gadgets.views.requestNavigateTo(gadgets.views.getSupportedViews()["canvas"],{user_id:user_id,sid:sid,screen_name:a.screen_name,profile_image_url:a.profile_image_url})}function remove_account(){if(account&&window.confirm("Are you sure to remove connection to "+account.name+"?")){delete_account(account,function(){accounts.remove(account);if(accounts.length>0){show_profile(accounts[0]);update_buttons()}else{show_authorize()}},"delete-account")}}function update_buttons(){var a=accounts.indexOf(account);if(a>0){$(".left_arrow",$profile_panel).removeClass("disable")}else{$(".left_arrow",$profile_panel).addClass("disable")}if(a<accounts.length-1){$(".right_arrow",$profile_panel).removeClass("disable")}else{$(".right_arrow",$profile_panel).addClass("disable")}};