String.prototype.sReplace = function(find, replace) {
	return this.split(find).join(replace);
};

String.prototype.repeat = function(times) {
	var rep = new Array(times + 1);
	return rep.join(this);
}

  function smiley(s) {
        if (document.forms['ys-post-form'].elements['ys-input-message'].value == 'Tekstas')
            document.forms['ys-post-form'].elements['ys-input-message'].value = s + ' ';
        else
            document.forms['ys-post-form'].elements['ys-input-message'].value = document.forms['ys-post-form'].elements['ys-input-message'].value + ' ' + s + ' ';
        document.forms['ys-post-form'].elements['ys-input-message'].focus();
    }

var YShout = function() {
	var self = this;
	var args = arguments;
	$(document).ready(function() {
		self.init.apply(self, args);
	});
} 

var yShout;

YShout.prototype = {
	animSpeed: 300,
	p: [],
		
	init: function(options) {
		yShout = this;
		var self = this;
		
		this.initializing = true;
		
		var dOptions = {
			yPath: '/yshout/',
			log: 1
		};

		this.options = jQuery.extend(dOptions, options);

		this.postNum = 0;
		this.floodAttempt = 0;	
		
		// Correct for missing trailing /
		if ((this.options.yPath.length > 0) && (this.options.yPath.charAt(this.options.yPath.length - 1) != '/'))
			this.options.yPath += '/';
		
		if (this.options.yLink) {
			if (this.options.yLink.charAt(0) != '#')
				this.options.yLink = '#' + this.options.yLink;
		
			$(this.options.yLink).click(function() {
				self.openYShout.apply(self);
				return false;
			});
		}
		
		// Load YShout from a link, in-page
		if (this.options.h_loadlink) {
			$(this.options.h_loadlink).click(function() {
				$('#yshout').css('display', 'block');
				$(this).unbind('click').click(function() { return false; });
				return false;
			});
			this.load(true);
		} else
			this.load();
		

	},
	
	load: function(hidden) {
		if ($('#yshout').length == 0) return;

		if (hidden) $('#yshout').css('display', 'none');
		
		this.ajax(this.initialLoad, { 
			reqType: 'init',
			yPath: this.options.yPath,
			log: this.options.log
		});
	},
	
	initialLoad: function(updates) {
		if (updates.yError) alert('There appears to be a problem: \n' + updates.yError + '\n\nIf you haven\'t already, try chmodding everything inside the YShout directory to 777.');
		this.d('In initialLoad');
		var self = this;
		
		this.prefs = jQuery.extend(updates.prefs, this.options.prefs);
		this.initForm();
		this.initRefresh();
		this.initLinks();
		if (this.prefs.flood) this.initFlood();

		if (updates.nickname)
			$('#ys-input-nickname')
				.removeClass('ys-before-focus')
				.addClass( 'ys-after-focus')
				.val(updates.nickname);

		if (updates)
			this.updates(updates);
	
		
		if (!this.prefs.doTruncate) {
			$('#ys-posts').css('height', $('#ys-posts').height + 'px');
		}

		if (!this.prefs.inverse) {
			var postsDiv = $('#ys-posts')[0];
			postsDiv.scrollTop = postsDiv.scrollHeight;
		}

		this.markEnds();
		
		this.initializing = false;
	},

	initForm: function() {
		this.d('In initForm');

		var yPath = '/yshout/';
		var SmPath ='/yshout/';
		var smileys = 
				'<div id="theLayer" onClick="javascript:hideMe();" style="visibility:hidden;position:absolute;width:210px;height:233px;bottom:50;left:50%;background-image:url(\'/yshout/b.png\');display:block;z-index:3">'+
'<table>'+

'<tr>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/air_kiss.gif" onclick="javascript:smiley(\'(air_kiss)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/bad.gif" onclick="javascript:smiley(\'(bad)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/biggrin.gif" onclick="javascript:smiley(\'(biggrin)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/blum.gif" onclick="javascript:smiley(\'(blum)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/blum3.gif" onclick="javascript:smiley(\'(blum3)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/blush.gif" onclick="javascript:smiley(\'(blush)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/boredom.gif" onclick="javascript:smiley(\'(boredom)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td></tr>'+
'<tr>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/crazy.gif" onclick="javascript:smiley(\'(crazy)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/dirol.gif" onclick="javascript:smiley(\'(dirol)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/good.gif" onclick="javascript:smiley(\'(good)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/heart.gif" onclick="javascript:smiley(\'(heart)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/i-m_so_happy.gif" onclick="javascript:smiley(\'(i-m_so_happy)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/laugh1.gif" onclick="javascript:smiley(\'(laugh1)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/laugh2.gif" onclick="javascript:smiley(\'(laugh2)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td></tr>'+
'<tr>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/laugh3.gif" onclick="javascript:smiley(\'(laugh3)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/laugh4.gif" onclick="javascript:smiley(\'(laugh4)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/lol.gif" onclick="javascript:smiley(\'(lol)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/lol2.gif" onclick="javascript:smiley(\'(lol2)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/man_in_love.gif" onclick="javascript:smiley(\'(man_in_love)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/mosking.gif" onclick="javascript:smiley(\'(mosking)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/on_the_quiet.gif" onclick="javascript:smiley(\'(on_the_quiet)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td></tr>'+
'<tr>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/paratrooper.gif" onclick="javascript:smiley(\'(paratrooper)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/prankster2.gif" onclick="javascript:smiley(\'(prankster2)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/rtfm.gif" onclick="javascript:smiley(\'(rtfm)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/sad.gif" onclick="javascript:smiley(\'(sad)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/sarcastic.gif" onclick="javascript:smiley(\'(sarcastic)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/sarcasticblum.gif" onclick="javascript:smiley(\'(sarcasticblum)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/secret.gif" onclick="javascript:smiley(\'(secret)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td></tr>'+
'<tr>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/shok.gif" onclick="javascript:smiley(\'(shok)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/shout.gif" onclick="javascript:smiley(\'(shout)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/smile.gif" onclick="javascript:smiley(\'(smile)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/soldier.gif" onclick="javascript:smiley(\'(soldier)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/sorry.gif" onclick="javascript:smiley(\'(sorry)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/sorry2.gif" onclick="javascript:smiley(\'(sorry2)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/spiteful.gif" onclick="javascript:smiley(\'(spiteful)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td></tr>'+
'<tr>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/swoon.gif" onclick="javascript:smiley(\'(swoon)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/this.gif" onclick="javascript:smiley(\'(this)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/to_pick_ones_nose2.gif" onclick="javascript:smiley(\'(to_pick_ones_nose2)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/to_take_umbrage.gif" onclick="javascript:smiley(\'(to_take_umbrage)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/treaten.gif" onclick="javascript:smiley(\'(treaten)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/umnik2.gif" onclick="javascript:smiley(\'(umnik2)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/vava.gif" onclick="javascript:smiley(\'(vava)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td></tr>'+
'<tr>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/wacko.gif" onclick="javascript:smiley(\'(wacko)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/wacko2.gif" onclick="javascript:smiley(\'(wacko2)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/whistle3.gif" onclick="javascript:smiley(\'(whistle3)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/wink.gif" onclick="javascript:smiley(\'(wink)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/wink2.gif" onclick="javascript:smiley(\'(wink2)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/wink3.gif" onclick="javascript:smiley(\'(wink3)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td>'+
'<td style="width:27px;height:27px;"> <img src="' + SmPath + 'smailai2/yes.gif" onclick="javascript:smiley(\'(yes)\');javascript:hideMe();" style="cursor: pointer;" class="smailas"/></td></tr>'+




'</table><a href="javascript:hideMe();" style="color:#FFF"> [ X ] </a></div>'+

'<div class="ys-smiley-bar">' +
					

					'<img src="' + SmPath + 'smileys/nod.gif" onclick="javascript:smiley(\'(nod)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0145-shake.gif" onclick="javascript:smiley(\'(shake)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0142-happy.gif" onclick="javascript:smiley(\'(happy)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0119-puke.gif" onclick="javascript:smiley(\'(puke)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0150-handshake.gif" onclick="javascript:smiley(\'(handshake)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0116-evilgrin.gif" onclick="javascript:smiley(\'(grin)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0128-hi.gif" onclick="javascript:smiley(\'(wave)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0102-bigsmile.gif" onclick="javascript:smiley(\':D\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0103-cool.gif" onclick="javascript:smiley(\'8)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0127-lipssealed.gif" onclick="javascript:smiley(\':x\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0108-speechless.gif" onclick="javascript:smiley(\':|\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0110-tongueout.gif" onclick="javascript:smiley(\':P\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0101-sadsmile.gif" onclick="javascript:smiley(\':(\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0100-smile.gif" onclick="javascript:smiley(\':)\');" style="cursor: pointer;" /> ' +
					'<img src="' + SmPath + 'smileys/emoticon-0105-wink.gif" onclick="javascript:smiley(\';)\');" style="cursor: pointer;" /> ' +


				'</div>';

		var inputUsername = this.options.inputUsername ? this.options.inputUsername : false;

		var postForm = 
			'<form id="ys-post-form"><fieldset>'+smileys+
			       '<input id="ys-input-message" value="' + this.prefs.defaultMessage + '" type="text" accesskey="M" maxlength="' + this.prefs.messageLength + '" class="ys-before-focus" />' +
				'<input id="ys-input-submit" value="' + (this.options.constSubmit ? this.options.constSubmit : this.prefs.defaultSubmit) + '" accesskey="S" type="submit" />' +
				(this.prefs.postFormLink == 'cp' ? '<a title="' + (this.options.constControlPanel ? this.options.constControlPanel : 'View YShout Control Panel') + '" class="ys-post-form-link" id="ys-cp-link" href="' + yPath + 'cp/">' + (this.options.constAdminCP ? this.options.constAdminCP : 'Admin CP') + '</a>' : '') +
				(this.prefs.postFormLink == 'history' ? '<a title="' + (this.options.constHistoryViewer? this.options.constHistoryViewer : 'View YShout History') + '" class="ys-post-form-link" id="ys-history-link" href="' + yPath + 'history/?log=' + (this.options.log ? this.options.log : '1') + '&offset=' + (this.options.timeOffset ? this.options.timeOffset : '0') + '&language=' + (this.options.constLanguage ? this.options.constLanguage : 'english') + '">' + (this.options.constHistory ? this.options.constHistory : 'Istorija') + '</a>' : '') +
			'<a onClick="javascript:showMe();" onMouseOver="javascript:showMe();" style="color:#FFF;margin-left:5px;line-height:16px;"><img src="/yshout/sico.gif" alt="Smailai" style="margin-top:3px;"/></a></fieldset></form>';
		
if(this.prefs.allowGuests) var postForm='';
		var postsDiv = '<div id="ys-posts"></div>';

		if (this.prefs.inverse) $('#yshout').html(postForm + postsDiv);
		else $('#yshout').html(postsDiv + postForm);
		
		$('#ys-posts')
			.before('<div id="ys-before-posts"></div>')
			.after('<div id="ys-after-posts"></div>');
		
		$('#ys-post-form')
			.before('<div id="ys-before-post-form"></div>')
			.after('<div id="ys-after-post-form"></div>');
		
		var self = this;

		var defaults = { 
			'ys-input-nickname': self.prefs.defaultNickname, 
			'ys-input-message': self.options.constMessage ? self.options.constMessage : self.prefs.defaultMessage
		};

		var keypress = function(e) { 
			var key = window.event ? e.keyCode : e.which; 
			if (key == 13 || key == 3) {
				self.send.apply(self);
				return false;
			}
		};

		var focus = function() { 
			if (this.value == defaults[this.id])
				$(this).removeClass('ys-before-focus').addClass( 'ys-after-focus').val('');
		};

		var blur = function() { 
			if (this.value == '')
				$(this).removeClass('ys-after-focus').addClass('ys-before-focus').val(defaults[this.id]); 
		};

		$('#ys-input-message').keypress(keypress).focus(focus).blur(blur);
		$('#ys-input-nickname').keypress(keypress).focus(focus).blur(blur);

		$('#ys-input-submit').click(function(){ self.send.apply(self) });
		$('#ys-post-form').submit(function(){ return false });
	},

	initRefresh: function() {
		var self = this;
		if (this.refreshTimer) clearInterval(this.refreshTimer)
		this.refreshTimer = setInterval(function() {
			self.ajax(self.updates, { reqType: 'refresh' });
		}, this.prefs.refresh); // ! 3000..?
	},

	initFlood: function() {
		this.d('in initFlood');
		var self = this;
		this.floodCount = 0;
		this.floodControl = false;

		this.floodTimer = setInterval(function() {
			self.floodCount = 0;
		}, this.prefs.floodTimeout);
	},

	initLinks: function() {
		if ($.browser.msie) return;
		
		var self = this;

		$('#ys-cp-link').click(function() {
			self.openCP.apply(self);
			return false;
		});

		$('#ys-history-link').click(function() {
			self.openHistory.apply(self);
			return false;
		});

	},
	
	openCP: function() {
		var self = this;
		if (this.cpOpen) return;
		this.cpOpen = true;
		
		var url = this.options.yPath + 'cp/';

		$('body').append('<div id="ys-overlay"></div><div class="ys-window" id="ys-cp"><a title="Close Admin CP" href="#" id="ys-closeoverlay-link">Close</a><a title="Istorija" href="#" id="ys-switchoverlay-link">Istorija</a><object class="ys-browser" id="cp-browser" data="' + url +'" type="text/html">Something went horribly wrong.</object></div>');

		$('#ys-overlay, #ys-closeoverlay-link').click(function() { 
			self.reload.apply(self, [true]);
			self.closeCP.apply(self);
			return false; 
		}); 
		
		$('#ys-switchoverlay-link').click(function() { 
			self.closeCP.apply(self);
			self.openHistory.apply(self);
			return false;
		});

	},

	closeCP: function() {
		this.cpOpen = false;
		$('#ys-overlay, #ys-cp').remove();
	},

	openHistory: function() {
		var self = this;
		if (this.hOpen) return;
		this.hOpen = true;
		var url = this.options.yPath + 'history/?log=' + (this.options.log ? this.options.log : '1') + '&offset=' + (this.options.timeOffset ? this.options.timeOffset : '0') + '&language=' + (this.options.constLanguage ? this.options.constLanguage : 'english');
		$('body').append('<div id="ys-overlay"></div><div class="ys-window" id="ys-history"><a title="Uzverti langa" href="#" id="ys-closeoverlay-link">U&#382;daryti</a><a title="Personalui" href="#" id="ys-switchoverlay-link">Personalui</a><object class="ys-browser" id="history-browser" data="' + url +'" type="text/html">Something went horribly wrong.</object></div>');

		$('#ys-overlay, #ys-closeoverlay-link').click(function() { 
			self.reload.apply(self, [true]);
			self.closeHistory.apply(self);
			return false; 
		}); 

		$('#ys-switchoverlay-link').click(function() { 
			self.closeHistory.apply(self);
			self.openCP.apply(self);
			return false;
		});

	},

	closeHistory: function() {
		this.hOpen = false;
		$('#ys-overlay, #ys-history').remove();
	},
	
	openYShout: function() {
		var self = this;
		if (this.ysOpen) return;
		this.ysOpen = true;
		url = this.options.yPath + 'example/yshout.html';

		$('body').append('<div id="ys-overlay"></div><div class="ys-window" id="ys-yshout"><a title="Close YShout" href="#" id="ys-closeoverlay-link">Close</a><object class="ys-browser" id="yshout-browser" data="' + url +'" type="text/html">Something went horribly wrong.</object></div>');
	
		$('#ys-overlay, #ys-closeoverlay-link').click(function() { 
			self.reload.apply(self, [true]);
			self.closeYShout.apply(self);
			return false; 
		}); 
	},

	closeYShout: function() {
		this.ysOpen = false;
		$('#ys-overlay, #ys-yshout').remove();
	},
	
	send: function() {
		if (!this.validate()) return;
		if (this.prefs.flood && this.floodControl) return;

		var  postNickname = $('#ys-input-nickname').val(), postUserID = $('#ys-input-userid').val(), postColor = $('#ys-input-color').val(), postMessage = $('#ys-input-message').val();

		if (postMessage == '/cp')
			this.openCP();
		else if (postMessage == '/history')
			this.openHistory();
		else
			this.ajax(this.updates, {
				reqType: 'post',
				nickname: postNickname,
				userid: postUserID,
				color: postColor,
				message: postMessage
			});

		$('#ys-input-message').val('')

		if (this.prefs.flood) this.flood();
	},

	validate: function() {
		var nickname = $('#ys-input-nickname').val(),
			userid = $('#ys-input-userid').val(),
			color = $('#ys-input-color').val(),
			message = $('#ys-input-message').val(),
			error = false;

		if (this.options.inputUsername && nickname != this.options.inputUsername) {
			alert('You can\'t change your username.');
			error = true;
		}

		if (this.options.inputUserID && userid != this.options.inputUserID) {
			alert('You can\'t change your user ID.');
			error = true;
		}

	


		var showInvalid = function(input) {
			$(input).removeClass('ys-input-valid').addClass('ys-input-invalid')[0].focus();
			error = true;
		}

		var showValid = function(input) {
			$(input).removeClass('ys-input-invalid').addClass('ys-input-valid');
		}

		if (nickname == '' || nickname == this.prefs.defaultNickname)
			showInvalid('#ys-input-nickname');
		else
			showValid('#ys-input-nickname');

		var constMessage = this.options.constMessage ? this.options.constMessage : this.prefs.defaultMessage;
		if (message == '' || message == constMessage)
			showInvalid('#ys-input-message');
		else
			showValid('#ys-input-message');

		return !error;
	},

	flood: function() {
		var self = this;
		this.d('in flood');
		if (this.floodCount < this.prefs.floodMessages) {
			this.floodCount++;
			return;
		}

		this.floodAttempt++;
		this.disable();

		if (this.floodAttempt == this.prefs.autobanFlood)
			this.banSelf('Jus esate uzbanintas!');
			
		setTimeout(function() {
			self.floodCount = 0;
			self.enable.apply(self);
		}, this.prefs.floodDisable);
	},

	disable: function () {
		$('#ys-input-submit')[0].disabled = true;
		this.floodControl = true;
	},

	enable: function () {
		$('#ys-input-submit')[0].disabled = false;
		this.floodControl = false;
	},
	
	findBySame: function(ip) {
		if (!$.browser.safari) return;
		
		var same = [];
		for (var i = 0; i < this.p.length; i++)
			if (this.p[i].adminInfo.ip == ip) 
				same.push(this.p[i]);
		
		for (var i = 0; i < same.length; i++) {
			$('#' + same[i].id).fadeTo(this.animSpeed, .8).fadeTo(this.animSpeed, 1);
		}
	},
	
	updates: function(updates) {
		if (!updates) return;
		if (updates.prefs) this.prefs = updates.prefs;
		if (updates.posts) this.posts(updates.posts);
		if (updates.banned) this.banned();
	},

	banned: function() {
		var self = this;
		clearInterval(this.refreshTimer);
		clearInterval(this.floodTimer);
		if (this.initializing)
			$('#ys-post-form').css('display', 'none');
		else
			$('#ys-post-form').fadeOut(this.animSpeed);
		
		if ($('#ys-banned').length == 0) {
			$('#ys-input-message')[0].blur();
			$('#ys-posts').append('<div id="ys-banned"><span>Jus uzbanintas, spauskite <a href="#" id="ys-unban-self">cia</a> jei esate administratorius, jei ne, tuomet laukite, kol nustos galioti apribojimai</span></div>');

			$('#ys-banned-cp-link').click(function() {
				self.openCP.apply(self);
				return false;
			});
			
			$('#ys-unban-self').click(function() {
				self.ajax(function(json) {
					if (!json.error)
						self.unbanned();
					 else if (json.error == 'admin')
						alert('Jus neesate administratorius, bano nuimti nepavyko!');
				}, { reqType: 'unbanself' });
				return false;
			});
		}		
	},

	unbanned: function() {
		var self = this;
		$('#ys-banned').fadeOut(function() { $(this).remove(); });
		this.initRefresh();
		$('#ys-post-form').css('display', 'block').fadeIn(this.animSpeed, function(){
			self.reload();
		});
	},
	
	posts: function(p) {
		for (var i = 0; i < p.length; i++) {
			this.post(p[i]);
		}
		
		this.truncate();
		
		if (!this.prefs.inverse) {
			var postsDiv = $('#ys-posts')[0];
			postsDiv.scrollTop = postsDiv.scrollHeight;
		}
	},

	post: function(post) {
		var self = this;

		var timeOffset = self.options.timeOffset ? self.options.timeOffset : '0';
		var pad = function(n) { return n > 9 ? n : '0' + n; };
		var date = function(ts) { return new Date((ts - timeOffset) * 1000); };
		var time = function(ts) { 
			var d = date(ts);
			var h = d.getHours(), m = d.getMinutes();

			if (self.prefs.timestamp == 12) {
				h = (h > 12 ? h - 12 : h);
				if (h == 0) h = 12;
			}

			return pad(h) + ':' + pad(m);
		};

		var dateStr = function(ts) {
			var t = date(ts);

		  var Y = t.getFullYear();
		  var M = t.getMonth();
		  var D = t.getDay();
		  var d = t.getDate();
		  var day = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][D];
		  var mon = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
		             'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][M];

		  return day + ' ' + mon + '. ' + d + ', ' + Y;
		};

		var self = this;

		this.postNum++;
		var id = 'ys-post-' + this.postNum;
		post.id = id;
		
		post.message = this.links(post.message);
		post.message = this.smileys(post.message);
//		post.message = this.bbcode(post.message);
		post.message = this.bbcodes(post.message);
		post.message = this.censor(post.message);
		var html = 
			'<div id="' + id + '" class="ys-post' + (post.admin ? ' ys-admin-post' : '') + (post.banned ? ' ys-banned-post' : '') + '">' +
				(this.prefs.timestamp > 0 ? '<span class="ys-post-timestamp">' + time(post.timestamp) + '</span> ' : '') +
				(post.userid != 1 ? '<span class="ys-post-nickname"><a href="./account-details.php?id=' + post.usid + '" target="_blank"' + (post.spalva ? ' style="color:#' + post.spalva + ';"' : '') + '>' + post.nickname + '</a></span>' + this.prefs.nicknameSeparator + ' ' : '<span class="ys-post-nickname"' + (post.color ? ' style="color: ' + post.color + ';"' : '') + '>' + post.nickname + '</span>' + this.prefs.nicknameSeparator + ' ') +
				'<span class="ys-post-message">' + post.message + '</span> ' +
				'<span class="ys-post-info' + (this.prefs.info == 'overlay' ? ' ys-info-overlay' : ' ys-info-inline') + '">' + (post.adminInfo ? '<em>IP:</em> ' + post.adminInfo.ip + ', ' : '') + '<em>Posted:</em> ' + dateStr(post.timestamp) + ' at ' + time(post.timestamp)  + '.</span>' +
				'<span class="ys-post-actions"><a title="Show post information" class="ys-info-link" href="#">Info</a>'  + (post.adminInfo ? ' | <a title="Delete post" class="ys-delete-link" href="#">Delete</a> | ' + (post.banned ? '<a title="Unban user" class="ys-ban-link" href="#">Unban</a>' : '<a title="Ban user" class="ys-ban-link" href="#">Ban</a>') : '') + '</span>' +
			'</div>';
		if (this.prefs.inverse) $('#ys-posts').prepend(html);
		else $('#ys-posts').append(html);
		
		this.p.push(post);

		$('#' + id)
			.find('.ys-post-nickname').click(function() {
				if (post.adminInfo)
					self.findBySame(post.adminInfo.ip);
			}).end()
			.find('.ys-info-link').toggle(
				function() { self.showInfo.apply(self, [id, this]); return false; },
				function() { self.hideInfo.apply(self, [id, this]); return false; })
			.end()
			.find('.ys-ban-link').click(
				function() { self.ban.apply(self, [post, id]); return false; })
			.end()
			.find('.ys-delete-link').click(
				function() { self.del.apply(self, [post, id]); return false; });
			
	},
	
	showInfo: function(id, el) {
		var jEl = $('#' + id + ' .ys-post-info');
		if (this.prefs.info == 'overlay')
			jEl.css('display', 'block').fadeIn(this.animSpeed);
		else
			jEl.slideDown(this.animSpeed);
		
		el.innerHTML ='Close Info'
		return false;
	},
	
	hideInfo: function(id, el) {
		var jEl = $('#' + id + ' .ys-post-info');
		if (this.prefs.info == 'overlay')
			jEl.fadeOut(this.animSpeed);
		else
			jEl.slideUp(this.animSpeed);
			
		el.innerHTML = 'Info';
		return false;
	}, 
	
	ban: function(post, id) {
		var self = this;

		var link = $('#' + id).find('.ys-ban-link')[0];

		switch(link.innerHTML) {
			case 'Ban':
				var pars = {
					reqType: 'ban',
					ip: post.adminInfo.ip,
					nickname: post.nickname
				};

				this.ajax(function(json) {
					if (json.error) {
						switch (json.error) {
							case 'admin':
								self.error('You\'re not an admin. Log in through the Admin CP to ban people.');
								break;
						}
						return;
					}
					//alert('p: ' + this.p + ' / ' + this.p.length);
					if (json.bannedSelf)
						self.banned(); // ?
						
					else 						
						$.each(self.p, function(i) {
							if (this.adminInfo && this.adminInfo.ip == post.adminInfo.ip) 
									$('#' + this.id)
										.addClass('ys-banned-post')
										.find('.ys-ban-link').html('Unban');
						});
						
				}, pars);
				
				link.innerHTML = 'Banning...';
				return false;
				break;
			
			case 'Banning...':
				return false;
				break;
			
			case 'Unban':
				var pars = {
					reqType: 'unban',
					ip: post.adminInfo.ip
				};
	
				this.ajax(function(json) {
					if (json.error) {
						switch(json.error) {
							case 'admin':
								self.error('You\'re not an admin. Log in through the Admin CP to unban people.');
								return;
								break;
						}
					}
					
					$.each(self.p, function(i) {
						if (this.adminInfo && this.adminInfo.ip == post.adminInfo.ip) 
							$('#' + this.id)
								.removeClass('ys-banned-post')
								.find('.ys-ban-link').html('Ban');
					});
					
				}, pars);
	
				link.innerHTML = 'Unbanning...';
				return false;
				break;
				
			case 'Unbanning...':
				return false;
				break;
		}
	},
	
	del: function(post, id) {
		var self = this;
		var link = $('#' + id).find('.ys-delete-link')[0];

		if (link.innerHTML == 'Deleting...') return;
	
		var pars = {
			reqType: 'delete',
			uid: post.uid
		};

		self.ajax(function(json) {
			if (json.error) {
				switch(json.error) {
					case 'admin':
						self.error('You\'re not an admin. Log in through the Admin CP to ban people.');
						return;
						break;
				}
			}
			self.reload();
		}, pars);

		link.innerHTML = 'Deleting...';
		return false;

	},
	
	banSelf: function(reason) {
		var self = this;

		this.ajax(function(json) {
			if (json.error == false)
				self.banned();
		}, {
			reqType: 'banself',
			nickname: $('#ys-input-nickname').val() 
		});
	},

	censor: function(s) {
		var arrayBadwords = this.options.arrayBadwords ? this.options.arrayBadwords : new Array();
		for (var i = 0; i < arrayBadwords.length; ++i)
			s = s.replace(arrayBadwords[i], '<img src="/yshout/smileys/swear.gif" /> ');
		return s;
	},



	bbcodes: function(s) {
		s = s.replace(/\[b\]((\s|.)+?)\[\/b\]/, '<b>$1</b>');
		s = s.replace(/\[i\]((\s|.)+?)\[\/i\]/, '<i>$1</i>');
		s = s.replace(/\[u\]((\s|.)+?)\[\/u\]/, '<u>$1</u>');
		s = s.replace(/\[color=([a-zA-Z]+)\]((\s|.)+?)\[\/color\]/i, '<font color="$1">$2</font>');
		s = s.replace(/\[color=(#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9])\]((\s|.)+?)\[\/color\]/i, '<font color="$1">$2</font>');
		s = s.replace(/\[size=([1-7])\]((\s|.)+?)\[\/size\]/i, '<font size="$1">$2</font>');
		s = s.replace(/\[font=([a-zA-Z ,]+)\]((\s|.)+?)\[\/font\]/i, '<font face="$1">$2</font>');
		return s;
	},

	smileys: function(s) {
		var yp = this.options.yPath;

		var smile = function(str, smiley, image) {
			return str.sReplace(smiley, '<img src="/yshout/' + image + '" />');
		};
s = smile(s, '(nod)',  'smileys/nod.gif');
s = smile(s, '(shake)',  'smileys/emoticon-0145-shake.gif');
s = smile(s, '(happy)',  'smileys/emoticon-0142-happy.gif');
s = smile(s, '(puke)',  'smileys/emoticon-0119-puke.gif');
s = smile(s, '(handshake)','smileys/emoticon-0150-handshake.gif');
s = smile(s, '(grin)',  'smileys/emoticon-0116-evilgrin.gif');
s = smile(s, '(wave)',  'smileys/emoticon-0128-hi.gif');
s = smile(s, ':D',  'smileys/emoticon-0102-bigsmile.gif');
s = smile(s, '8)',  'smileys/emoticon-0103-cool.gif');
s = smile(s, ':x',  'smileys/emoticon-0127-lipssealed.gif');
s = smile(s, ':|',  'smileys/emoticon-0108-speechless.gif');
s = smile(s, ':P',  'smileys/emoticon-0110-tongueout.gif');
 

s = smile(s, ':(',  'smileys/emoticon-0101-sadsmile.gif');
s = smile(s, ':)',  'smileys/emoticon-0100-smile.gif');
s = smile(s, ';)',  'smileys/emoticon-0105-wink.gif');





s = smile(s, '(acute)', '/emocijos/acute.gif');
s = smile(s, '(aggressive)', '/emocijos/aggressive.gif');
s = smile(s, '(air_kiss)', '/emocijos/air_kiss.gif');
s = smile(s, '(angel)', '/emocijos/angel.gif');
s = smile(s, '(bad)', '/emocijos/bad.gif');
s = smile(s, '(bb)', '/emocijos/bb.gif');
s = smile(s, '(beach)', '/emocijos/beach.gif');
s = smile(s, '(beee)', '/emocijos/beee.gif');
s = smile(s, '(big_boss)', '/emocijos/big_boss.gif');
s = smile(s, '(biggrin)', '/emocijos/biggrin.gif');
s = smile(s, '(blum)', '/emocijos/blum.gif');
s = smile(s, '(blum3)', '/emocijos/blum3.gif');
s = smile(s, '(blush)', '/emocijos/blush.gif');
s = smile(s, '(boast)', '/emocijos/boast.gif');
s = smile(s, '(bomb)', '/emocijos/bomb.gif');
s = smile(s, '(boredom)', '/emocijos/boredom.gif');
s = smile(s, '(buba)', '/emocijos/buba.gif');
s = smile(s, '(buba_phone)', '/emocijos/buba_phone.gif');
s = smile(s, '(bye)', '/emocijos/bye.gif');
s = smile(s, '(clapping)', '/emocijos/clapping.gif');
s = smile(s, '(cray)', '/emocijos/cray.gif');
s = smile(s, '(cray2)', '/emocijos/cray2.gif');
s = smile(s, '(crazy)', '/emocijos/crazy.gif');
s = smile(s, '(curtsey)', '/emocijos/curtsey.gif');
s = smile(s, '(dance)', '/emocijos/dance.gif');
s = smile(s, '(dance2)', '/emocijos/dance2.gif');
s = smile(s, '(dance3)', '/emocijos/dance3.gif');
s = smile(s, '(dance4)', '/emocijos/dance4.gif');
s = smile(s, '(dash1)', '/emocijos/dash1.gif');
s = smile(s, '(dash2)', '/emocijos/dash2.gif');
s = smile(s, '(dash3)', '/emocijos/dash3.gif');
s = smile(s, '(declare)', '/emocijos/declare.gif');
s = smile(s, '(diablo)', '/emocijos/diablo.gif');
s = smile(s, '(dirol)', '/emocijos/dirol.gif');
s = smile(s, '(download)', '/emocijos/download.gif');
s = smile(s, '(drinks)', '/emocijos/drinks.gif');
s = smile(s, '(englishen)', '/emocijos/englishen.gif');
s = smile(s, '(feminist)', '/emocijos/feminist.gif');
s = smile(s, '(feministen)', '/emocijos/feministen.gif');
s = smile(s, '(firstmove)', '/emocijos/firstmove.gif');
s = smile(s, '(flirt)', '/emocijos/flirt.gif');
s = smile(s, '(focus)', '/emocijos/focus.gif');
s = smile(s, '(fool)', '/emocijos/fool.gif');
s = smile(s, '(friends)', '/emocijos/friends.gif');
s = smile(s, '(gamer1)', '/emocijos/gamer1.gif');
s = smile(s, '(gamer2)', '/emocijos/gamer2.gif');
s = smile(s, '(gamer3)', '/emocijos/gamer3.gif');
s = smile(s, '(gamer4)', '/emocijos/gamer4.gif');
s = smile(s, '(girl_blum)', '/emocijos/girl_blum.gif');
s = smile(s, '(girl_cray)', '/emocijos/girl_cray.gif');
s = smile(s, '(girl_cray2)', '/emocijos/girl_cray2.gif');
s = smile(s, '(girl_cray3)', '/emocijos/girl_cray3.gif');
s = smile(s, '(girl_crazy)', '/emocijos/girl_crazy.gif');
s = smile(s, '(girl_dance)', '/emocijos/girl_dance.gif');
s = smile(s, '(girl_devil)', '/emocijos/girl_devil.gif');
s = smile(s, '(girl_drink1)', '/emocijos/girl_drink1.gif');
s = smile(s, '(girl_drink3)', '/emocijos/girl_drink3.gif');
s = smile(s, '(girl_drink4)', '/emocijos/girl_drink4.gif');
s = smile(s, '(girl_haha)', '/emocijos/girl_haha.gif');
s = smile(s, '(girl_hide)', '/emocijos/girl_hide.gif');
s = smile(s, '(girl_hospital)', '/emocijos/girl_hospital.gif');
s = smile(s, '(girl_impossible)', '/emocijos/girl_impossible.gif');
s = smile(s, '(girl_in_love)', '/emocijos/girl_in_love.gif');
s = smile(s, '(girl_mad)', '/emocijos/girl_mad.gif');
s = smile(s, '(girl_pinkglassesf)', '/emocijos/girl_pinkglassesf.gif');
s = smile(s, '(girl_prepare_fish)', '/emocijos/girl_prepare_fish.gif');
s = smile(s, '(girl_sad)', '/emocijos/girl_sad.gif');
s = smile(s, '(girl_sigh)', '/emocijos/girl_sigh.gif');
s = smile(s, '(girl_smile)', '/emocijos/girl_smile.gif');
s = smile(s, '(girl_to_take_umbrage)', '/emocijos/girl_to_take_umbrage.gif');
s = smile(s, '(girl_to_take_umbrage2)', '/emocijos/girl_to_take_umbrage2.gif');
s = smile(s, '(girl_wacko)', '/emocijos/girl_wacko.gif');
s = smile(s, '(girl_wink)', '/emocijos/girl_wink.gif');
s = smile(s, '(girl_witch)', '/emocijos/girl_witch.gif');
s = smile(s, '(give_heart)', '/emocijos/give_heart.gif');
s = smile(s, '(give_heart2)', '/emocijos/give_heart2.gif');
s = smile(s, '(give_rose)', '/emocijos/give_rose.gif');
s = smile(s, '(good)', '/emocijos/good.gif');
s = smile(s, '(good2)', '/emocijos/good2.gif');
s = smile(s, '(good3)', '/emocijos/good3.gif');
s = smile(s, '(hang1)', '/emocijos/hang1.gif');
s = smile(s, '(hang2)', '/emocijos/hang2.gif');
s = smile(s, '(hang3)', '/emocijos/hang3.gif');
s = smile(s, '(heart)', '/emocijos/heart.gif');
s = smile(s, '(heat)', '/emocijos/heat.gif');
s = smile(s, '(help)', '/emocijos/help.gif');
s = smile(s, '(hi)', '/emocijos/hi.gif');
s = smile(s, '(hunter)', '/emocijos/hunter.gif');
s = smile(s, '(hysteric)', '/emocijos/hysteric.gif');
s = smile(s, '(i-m_so_happy)', '/emocijos/i-m_so_happy.gif');
s = smile(s, '(ireful1)', '/emocijos/ireful1.gif');
s = smile(s, '(ireful2)', '/emocijos/ireful2.gif');
s = smile(s, '(ireful3)', '/emocijos/ireful3.gif');
s = smile(s, '(king)', '/emocijos/king.gif');
s = smile(s, '(kiss)', '/emocijos/kiss.gif');
s = smile(s, '(kiss2)', '/emocijos/kiss2.gif');
s = smile(s, '(kiss3)', '/emocijos/kiss3.gif');
s = smile(s, '(laugh1)', '/emocijos/laugh1.gif');
s = smile(s, '(laugh2)', '/emocijos/laugh2.gif');
s = smile(s, '(laugh3)', '/emocijos/laugh3.gif');
s = smile(s, '(laugh4)', '/emocijos/laugh4.gif');
s = smile(s, '(lazy)', '/emocijos/lazy.gif');
s = smile(s, '(lol)', '/emocijos/lol.gif');
s = smile(s, '(lol2)', '/emocijos/lol2.gif');
s = smile(s, '(mail1)', '/emocijos/mail1.gif');
s = smile(s, '(mamba)', '/emocijos/mamba.gif');
s = smile(s, '(man_in_love)', '/emocijos/man_in_love.gif');
s = smile(s, '(mda)', '/emocijos/mda.gif');
s = smile(s, '(mega_shok)', '/emocijos/mega_shok.gif');
s = smile(s, '(mention)', '/emocijos/mention.gif');
s = smile(s, '(moil)', '/emocijos/moil.gif');
s = smile(s, '(mosking)', '/emocijos/mosking.gif');
s = smile(s, '(music)', '/emocijos/music.gif');
s = smile(s, '(music2)', '/emocijos/music2.gif');
s = smile(s, '(nea)', '/emocijos/nea.gif');
s = smile(s, '(negative)', '/emocijos/negative.gif');
s = smile(s, '(new_russian)', '/emocijos/new_russian.gif');
s = smile(s, '(ok)', '/emocijos/ok.gif');
s = smile(s, '(on_the_quiet)', '/emocijos/on_the_quiet.gif');
s = smile(s, '(on_the_quiet2)', '/emocijos/on_the_quiet2.gif');
s = smile(s, '(padonak)', '/emocijos/padonak.gif');
s = smile(s, '(paint2)', '/emocijos/paint2.gif');
s = smile(s, '(paint3)', '/emocijos/paint3.gif');
s = smile(s, '(paratrooper)', '/emocijos/paratrooper.gif');
s = smile(s, '(paratrooper_girl)', '/emocijos/paratrooper_girl.gif');
s = smile(s, '(pardon)', '/emocijos/pardon.gif');
s = smile(s, '(parting)', '/emocijos/parting.gif');
s = smile(s, '(party)', '/emocijos/party.gif');
s = smile(s, '(party2)', '/emocijos/party2.gif');
s = smile(s, '(pilot)', '/emocijos/pilot.gif');
s = smile(s, '(pioneer)', '/emocijos/pioneer.gif');
s = smile(s, '(pioneer_smoke)', '/emocijos/pioneer_smoke.gif');
s = smile(s, '(pleasantry)', '/emocijos/pleasantry.gif');
s = smile(s, '(popcorm1)', '/emocijos/popcorm1.gif');
s = smile(s, '(popcorm2)', '/emocijos/popcorm2.gif');
s = smile(s, '(prankster2)', '/emocijos/prankster2.gif');
s = smile(s, '(preved)', '/emocijos/preved.gif');
s = smile(s, '(punish)', '/emocijos/punish.gif');
s = smile(s, '(rofl)', '/emocijos/rofl.gif');
s = smile(s, '(rtfm)', '/emocijos/rtfm.gif');
s = smile(s, '(russian_ru)', '/emocijos/russian_ru.gif');
s = smile(s, '(sad)', '/emocijos/sad.gif');
s = smile(s, '(sarcastic)', '/emocijos/sarcastic.gif');
s = smile(s, '(sarcastic_hand)', '/emocijos/sarcastic_hand.gif');
s = smile(s, '(sarcasticblum)', '/emocijos/sarcasticblum.gif');
s = smile(s, '(scare)', '/emocijos/scare.gif');
s = smile(s, '(scaut)', '/emocijos/scaut.gif');
s = smile(s, '(scaut_en)', '/emocijos/scaut_en.gif');
s = smile(s, '(scratch_one-s_head)', '/emocijos/scratch_one-s_head.gif');
s = smile(s, '(search)', '/emocijos/search.gif');
s = smile(s, '(secret)', '/emocijos/secret.gif');
s = smile(s, '(sensored)', '/emocijos/sensored.gif');
s = smile(s, '(shok)', '/emocijos/shok.gif');
s = smile(s, '(shout)', '/emocijos/shout.gif');
s = smile(s, '(slow)', '/emocijos/slow.gif');
s = smile(s, '(smile)', '/emocijos/smile.gif');
s = smile(s, '(smoke)', '/emocijos/smoke.gif');
s = smile(s, '(soldier)', '/emocijos/soldier.gif');
s = smile(s, '(soldier_girl)', '/emocijos/soldier_girl.gif');
s = smile(s, '(sorry)', '/emocijos/sorry.gif');
s = smile(s, '(sorry2)', '/emocijos/sorry2.gif');
s = smile(s, '(spiteful)', '/emocijos/spiteful.gif');
s = smile(s, '(spruce_up)', '/emocijos/spruce_up.gif');
s = smile(s, '(stinker)', '/emocijos/stinker.gif');
s = smile(s, '(suicide2)', '/emocijos/suicide2.gif');
s = smile(s, '(sun_bespectacled)', '/emocijos/sun_bespectacled.gif');
s = smile(s, '(superstition)', '/emocijos/superstition.gif');
s = smile(s, '(swoon)', '/emocijos/swoon.gif');
s = smile(s, '(tease)', '/emocijos/tease.gif');
s = smile(s, '(tender)', '/emocijos/tender.gif');
s = smile(s, '(thank_you2)', '/emocijos/thank_you2.gif');
s = smile(s, '(this)', '/emocijos/this.gif');
s = smile(s, '(to_babruysk)', '/emocijos/to_babruysk.gif');
s = smile(s, '(to_become_senile)', '/emocijos/to_become_senile.gif');
s = smile(s, '(to_pick_ones_nose)', '/emocijos/to_pick_ones_nose.gif');
s = smile(s, '(to_pick_ones_nose2)', '/emocijos/to_pick_ones_nose2.gif');
s = smile(s, '(to_take_umbrage)', '/emocijos/to_take_umbrage.gif');
s = smile(s, '(training1)', '/emocijos/training1.gif');
s = smile(s, '(treaten)', '/emocijos/treaten.gif');
s = smile(s, '(umnik2)', '/emocijos/umnik2.gif');
s = smile(s, '(unknw)', '/emocijos/unknw.gif');
s = smile(s, '(vampire)', '/emocijos/vampire.gif');
s = smile(s, '(vava)', '/emocijos/vava.gif');
s = smile(s, '(victory)', '/emocijos/victory.gif');
s = smile(s, '(wacko)', '/emocijos/wacko.gif');
s = smile(s, '(wacko2)', '/emocijos/wacko2.gif');
s = smile(s, '(whistle3)', '/emocijos/whistle3.gif');
s = smile(s, '(wink)', '/emocijos/wink.gif');
s = smile(s, '(wink2)', '/emocijos/wink2.gif');
s = smile(s, '(wink3)', '/emocijos/wink3.gif');
s = smile(s, '(wizard)', '/emocijos/wizard.gif');
s = smile(s, '(yahoo)', '/emocijos/yahoo.gif');
s = smile(s, '(yes)', '/emocijos/yes.gif');
s = smile(s, '(yes3)', '/emocijos/yes3.gif');
s = smile(s, '(yess)', '/emocijos/yess.gif');
s = smile(s, '(yu)', '/emocijos/yu.gif')
 




					//'<img src="' + SmPath + 'smileys/emoticon-0144-nod.gif" onclick="javascript:smiley(\'(nod)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0145-shake.gif" onclick="javascript:smiley(\'(shake)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0142-happy.gif" onclick="javascript:smiley(\'(happy)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0119-puke.gif" onclick="javascript:smiley(\'(puke)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0150-handshake.gif" onclick="javascript:smiley(\'(handshake)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0116-evilgrin.gif" onclick="javascript:smiley(\'(grin)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0128-hi.gif" onclick="javascript:smiley(\'(wave)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0102-bigsmile.gif" onclick="javascript:smiley(\':D\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0103-cool.gif" onclick="javascript:smiley(\'8)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0127-lipssealed.gif" onclick="javascript:smiley(\':x\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0108-speechless.gif" onclick="javascript:smiley(\':|\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0110-tongueout.gif" onclick="javascript:smiley(\':P\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0101-sadsmile.gif" onclick="javascript:smiley(\':(\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0100-smile.gif" onclick="javascript:smiley(\':)\');" style="cursor: pointer;" /> ' +
					//'<img src="' + SmPath + 'smileys/emoticon-0105-wink.gif" onclick="javascript:smiley(\':o\');" style="cursor: pointer;" /> ' +

		return s;
	},

	links: function(s) {
		return s.replace(/((https|http|ftps|ftp|ed2k|irc):\/\/[\S]+)/gi, '<a href="$1" target="_blank">$1</a>');
	},

	truncate: function(clearAll) {
		var truncateTo = clearAll ? 0 : this.prefs.truncate;
		var posts = $('#ys-posts .ys-post').length;
		if (posts <= truncateTo) return;
		//alert(this.initializing);
		if (this.prefs.doTruncate || this.initializing) {
			var diff = posts - truncateTo;
			for (var i = 0; i < diff; i++)
				this.p.shift();
			
			//	$('#ys-posts .ys-post:gt(' + truncateTo + ')').remove();

			if (this.prefs.inverse) 
				$('#ys-posts .ys-post:gt(' + (truncateTo - 1) + ')').remove();
				else 
				$('#ys-posts .ys-post:lt(' + (posts - truncateTo) + ')').remove();
		}
		
		this.markEnds();		
	},
	
	markEnds: function() {
		$('#ys-posts')
			.find('.ys-first').removeClass('ys-first').end()
			.find('.ys-last').removeClass('ys-last');
			
		$('#ys-posts .ys-post:first-child').addClass('ys-first');
		$('#ys-posts .ys-post:last-child').addClass('ys-last');
	},
	
	reload: function(everything) {
		var self = this;
		this.initializing = true;
		
		if (everything) {
			this.ajax(function(json) { 
				$('#yshout').html(''); 
				clearInterval(this.refreshTimer);
				clearInterval(this.floodTimer);
				this.initialLoad(json); 
			}, { 
				reqType: 'init',
				yPath: this.options.yPath,
				log: this.options.log
			});
		} else {
			this.ajax(function(json) { this.truncate(true); this.updates(json); this.initializing = false; }, {
				reqType: 'reload'
			});
		}
	},

	error: function(str) {
		alert(str);
	},

	json: function(parse) {
		this.d('In json: ' + parse);
		var json = eval('(' + parse + ')');
		if (!this.checkError(json)) return json;
	},

	checkError: function(json) {
		if (!json.yError) return false;

		this.d('Error: ' + json.yError);
		return true;
	},

	ajax: function(callback, pars, html) {
		pars = jQuery.extend({
			reqFor: 'shout'
		}, pars);

		var self = this;

		$.post(this.options.yPath + 'yshout.php', pars, function(parse) {
			if (parse)
				if (html)
					callback.apply(self, [parse]);
				else
					callback.apply(self, [self.json(parse)]);
			else
				callback.apply(self);
		});
	},

	d: function(message) {
		$('#debug').css('display', 'block').prepend('<p>' + message + '</p>');
		return message;
	}
};
