	shoutbox = function (sid) {
		var sounds = true;
		
		var num = 1;
  		var last_date = 0;
  		var added = false;
  		var swfhtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="" id="snd" width="0" height="0">'
		+'<param name="movie" value="/shoutbox.swf">'
		+'<param name="play" value="true">'
		+'<embed play="true" name="snd" src="/shoutbox.swf" quality="high" '
		+'width="0" height="0" type="application/x-shockwave-flash"></embed>'
	+'</object>';
		
		check = function (msg)
		{
			checking = true;
			clearTimeout(tm);
			$.getJSON("/shoutbox.php?last_date="+last_date+(msg?"&m="+urlencode(msg):"")+(sid?"&sid="+sid:""), readjson);
		}
		readjson = function (msg, status)
		{
			$('#throbber').hide();
			if (((msg.m.length>0 && !added) || (msg.m.length>1 && added)) && sounds)
			{
				$('#snd').remove();
				$('#shoutbox_frame').after(swfhtml);
			}
			for (i=msg.m.length-1;i>=0;i--)
			{
				num++;
				last_date = msg.ld;
				name = msg.m[i].login;
				rname = msg.m[i].rlogin;
				$('#shoutbox_frame').prepend('<li class="line-'+(num%2)+'"><a class="bold" target="_parent" title="Przejdź do profilu użytkownika '+name+'" href="/profile/'+rname+'">'+name+'</a> ('+msg.m[i].date+') <p>'+unescape(msg.m[i].msg)+'</p></li>');
			}
			added = false;
			clearTimeout(tm);
			tm = setTimeout('check("")', 4000);
			checking = false;
		}
		
		submit = function()
		{
  			clearTimeout(tm);
  			$('#throbber').show();
  			added = true;
  			if (checking) {
				setTimeout('submit()', 20);  
			} else {
 	 			check($('textarea[name=smessage]').val());
  				$('textarea[name=smessage]').val('').focus();
  			}
  			return false;
		}
		var tm = setTimeout('check(false)', 0);
  		$('#shoutbox-form').submit(submit);
	}
	
	urlencode = function (str) {
		return encodeURIComponent(str);//.replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
	}