$(document).ready(function(){
var
msgCount = 0,
checkSchedule = null,
soundObj = '<object data="' + soundFile + '" type="application/x-mplayer2" width="0" height="0"> <param name="filename" value="' + soundFile + '"> <param name="autostart" value="1"> </object>',
ieSound = $('<bgsound src="" />'),
soundDiv = $('<div></div>');

$('#msgChatForm').submit(function(ev){
var
name = $('#msgName').val(),
msg = $('#msgEdit').val();
if (name && msg) {
var cd = new Date();
var date = dateFormat(cd, ' (m/d/yyyy h:MMtt Z)');
var url = 'msgSub.js.php?msg=' + escape(msg + date) + '&name=' + escape(name) + '&msgFile=' + msgFile;
$('#msgSpan').load(url, function(){
$('#msgEdit').val('').focus();
});
}
ev.preventDefault();
});

$('#msgChatForm').append('<span style="font-size: 0pt; height: 0px; width: 0px; position: absolute; overflow: hidden; z-index: -1000;" role="alert" id="screenReaderMsgHolder"></span>');

checkSchedule = setInterval(function(){
msgCount++;
var url = 'msgGet.js.php?msgCount=' + escape(msgCount) + '&msgFile=' + msgFile;
$('#msgSpan').load(url, function(){
if ($('#screenReaderMsgHolder').html() != $('#gs_msgChatLatestMessage').html()) {
if (playSound && $('#screenReaderMsgHolder').html()) {
if ($.support.cssFloat) soundDiv.html(soundObj);
else ieSound.attr('src', soundFile);
}
$('#screenReaderMsgHolder').html($('#gs_msgChatLatestMessage').html());
}
});
}, 2500);

if (playSound) {
if ($.support.cssFloat) $('body').append(soundDiv);
else $('body').append(ieSound);
}

});