$(function() {

      $('#channel').change(function() {
                               changeChannel($(this).val());
                           });
      
      function changeChannel(hash)
      {
          window.location.hash = '#' + hash;
          $('#content').load('stream.php?hash=' + hash, [], function() {
                                 $('#tweetform').ajaxForm(function() {
                                                              $('#tweet').val('');
                                                              $('#tweet').focus();
                                                          });
                                 $('#tweet').focus();
                             });
      }
      
      
      $(document).ready(function() {
                            var hash = window.location.hash;
                            if (!hash || hash.length<=1) {
                                hash = first_channel;
                            } else {
                                hash = hash.substr(1);
                            }
                            changeChannel(hash);
                            $('#channel').val(hash);

                            });

});