// JavaScript Document

//var timeout = <?= $shoutbox_refresh ?>;
var timeout = 15;

try
{
  if ( jQuery )
  {
    // Set timer for updating shoutbox
    jQuery(document).ready(
      function()
      {
        doShoutBoxUpdate();
      }
    );
  }
}
catch ( e ) {
//  alert( e );
}

function doShoutBoxUpdate()
{
  try
  {
//  var url = '/extra/shoutbox.php';
//  var url = '/shoutbox/messages';
//    var now = new Date();
//    var url = '/extra/shoutbox.php?' + String( Math.floor( now.getMilliseconds() * Math.random() * 100000 ) );
    var url = '/extra/shoutbox.php?' + String( Math.floor( Math.random() * 100000 ) );

    new Ajax.Updater(
      'shoutbox-items',
      url,
      {
        method: 'get',
        requestHeaders: [ 'Connection', 'close' ]
      }
    );

    setTimeout( doShoutBoxUpdate, timeout * 1000 );
  }
  catch ( e ) {}
}

function beforeMessageSent()
{
  try
  {
    jQuery( '#shoutbox-form' ).hide();
    jQuery( '#shoutbox-loader' ).show();
  }
  catch ( e ) {}
}

function afterMessageSent()
{
  try
  {
    doShoutBoxUpdate();

    jQuery( 'textarea#ShoutboxMessage' ).val( '' );
    jQuery( '#shoutbox-loader' ).hide();
    jQuery( '#shoutbox-form' ).show();
  }
  catch ( e ) {}
}
