
$(document).ready(function(){
	$('.twtr-hd').addClass("hidden");
	
});

MsTaken = {
  submit: function() {
    if (twitter_logged_in) {
      MsTaken.tweet();
    } else {
      MsTaken.auth_then_tweet();
    }
  },
  auth_then_tweet: function() {
    MsTaken.authWindow = window.open('/twitter/auth.php', 'Twitter Authentication', 
      'menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,width=800,height=400');
    if (!MsTaken.authWindow) {
      alert('please enable popups.');
    }
    else {
      $('#twt_status').html('waiting for authentication...');
      MsTaken.authTimer = window.setInterval(MsTaken.poll_window, 300);
    }
  },
  poll_window: function() {
    if (!MsTaken.authWindow || MsTaken.authWindow.closed) {
      window.clearInterval(MsTaken.authTimer);
      $('#twt_status').html('authenticated!');
      twitter_logged_in = true;
      MsTaken.tweet();
    }
  },
  tweet: function() {
    $.post('/twitter/tweet.php', {status:$('#twt_content').val()}, MsTaken.tweet_callback, "json");
    $('#twt_status').html('Sending your tweet...');
  },
  tweet_callback: function(data, textstatus) {
    $('#twt_content').val('');
    $('#twt_status').html('');
    $('#twt_form').hide();
    $('#twt_confirm').show();
  }
};

