/*******************************************
* Created by pazmat (C)
* May The Force Be With You
********************************************/
var onSuccessSBMOD = function (text, js_function) {
	var message, r, json;
	
	if ( text === '' ) {
		return;
	}

	message = text.replace(/\n/g, '');
	
	if ( sV.a ) {
		message = /\*(.*?)\*/.exec(message)[1];
	}

	if ( message === '' ) {
		return;
	}
	json = '{'+message+'}';
	try {
		eval('r = '+json);
	} catch (e) {
		AJAXSBMOD.viewError(e, json);
		return;
	}
	
	if ( typeof r.er !== 'undefined' ) {
		alert(r.er);
		return;
	}
					
	if ( typeof r.t !== 'undefined' ) {
		AJAXSBMOD.t = r.t;
	}
	
	if ( typeof js_function === 'function' ) { js_function(r); }
	
	AJAXSBMOD[js_function](r.p);
},

ie = ( document.all ) ? true : false,

AJAXSBMOD = {
	t: 1,
	i: '',
	pad: 5,
	h: 0,
	regSmiles: '',
	f: 1,
	up: 0,
	zIndex: 0,
	s: 0,
	tWidth: 0,
	bbpanel: 0,
	colors: ['aqua', 'gray', 'navy', 'silver', 'black', 'green', 'olive', 'teal', 'blue', 'lime', 'purple', 'white', 'fuchsia', 'maroon', 'red', 'yellow'],
	inSec: 0,
	winAct: 1,
	oldTabs: [],
	rows: ['row1', 'row2'],
	tableClass: 'forumline',
	orgMes: [],
	row: '',
	sbOFF: 0,

	hideError: function () {
		this.tintedDoc();
		$('#sberrorlog').remove();
		
		return false;
	},
	
	viewError: function (e, val) {
		if ( $('#sberrorlog').length ) { return; }
	
		var div = $('<div>').attr('id', 'sberrorlog')
				.css({ position: 'absolute', top: 50+document.body.scrollTop+'px', left: 50+document.body.scrollLeft+'px', backgroundColor: 'White', width: '400px', zIndex: 300 })
				.append('<center>AJAX SB DEBUG</center><br /><br />'+e.message+'<br /><br />'+val+'<br /><br />'+sV.lang[8]+'<br /><a href="#" onclick="return AJAXSBMOD.hideError();">'+sV.lang[7]+'</a>');
			
		$(document.body).append(div);
		this.tintedDoc();
		$('#tinted').animate({opacity: 0.7}, 500);
		
		var el = $('#sberrorlog'), lastindex = '';
	},
	
	getData: function () {
		var that = this;

		if ( this.sbOFF ) {
			setTimeout(function () { that.getData(); }, 1000);
			return;
		}

		$.ajax({
			url: 'ajax_sb_mod/sb.php',
			timeout: sV.ref,
			data: ({t:this.t}),
			cache: false,
			success: function (text) { onSuccessSBMOD(text, 'addNewMessage'); },
			complete: function () {
					setTimeout(function () {that.getData();}, ( ( that.winAct ) ? sV.ref : sV.inRef ));
				}
		});
	},
	
	cArray: function (ar) {
		var i, newAr = [];
		
		if ( ar.length == 0 ) { return []; }
	
		for ( i = 0; i < ar.length; i++ ) {
			newAr[ar.length-i-1] = ar[i];
		}
		
		return newAr;
	},
	
	addNewMessage: function (r) {
		var el = $('#mes'), shout, td, tr, tbody, table, i, p, il, wh, username, e, x, that = this, td2, av,
			tables = [];

		if ( (r.length + this.oldTabs.length) > 30 ) {
			wh = (30-r.length);
			il = this.oldTabs.length - wh;
			
			if ( this.up ) {
				for ( i = 0; i < this.oldTabs.length-wh; i++ ) {
					$('#s'+this.oldTabs[i]).remove();
				}
				this.oldTabs.splice(0, il);
			} else {
				for ( i = wh; i < this.oldTabs.length; i++ ) {
					$('#s'+this.oldTabs[i]).remove();
				}
				this.oldTabs.splice(wh, il);
				this.slideMessages([], { type: 1, d: wh-il, h: parseInt($('#s'+this.oldTabs[wh-il]).css('top'), 10)-this.pad });
			}
		}
		
		//creating
		
		for ( i = r.length-1; i >= 0; i--) {
			shout = r[i];
			
			this.orgMes[shout[0]] = shout[2];
			
			username = ( shout[4] == 'Anonymous' ) ? sV.lang[4] : '<a href="#" id="usrc'+shout[0]+'" onclick="return AJAXSBMOD.setBBcode(\''+((sV.bbcode) ? '[color='+((shout[5]!='')?'#'+shout[5]:$('#c').css('color'))+']'+shout[4]+'[/color], ' : shout[4]+',')+'\', \'s\');" class="gensmall"'+((shout[5]!= '') ? 'style="color:'+shout[5]+'"' : '')+'>'+shout[4]+'</a>';
			
			p = '<a href="profile.php?mode=viewprofile&u='+shout[1]+'" target="_blank" class="gensmall" style="font-weight:bold">i</a> ';
			e = ( sV.e || (sV.eOwn && shout[1] == sV.u) ) ? '<a href="#" class="gensmall" onclick="return AJAXSBMOD.editMessage('+shout[0]+');" style="font-weight:bold">e</a> ' : '';
			x = ( sV.d || (sV.dOwn && shout[1] == sV.u) ) ? '<a href="#" class="gensmall" onclick="return AJAXSBMOD.deleteMessage('+shout[0]+');" style="font-weight:bold">x</a> ' : '';
			
			av = ( shout[6] == '' ) ? 'images/avatars/noavat.png' : shout[6];

			td2 = $('<td>')
				.attr({ id: 'a'+shout[0], width: '35px', height: '35px' })
				.addClass(this.row)
				.append('<img style="width:35px;height:35px;" src="'+av+'">');
			td = $('<td>')
				.attr('id', 'td'+shout[0])
				.append('<div style="position:relative;"><div style="position:absolute;left:0px" class="gensmall"> '+username+':</div><div style="position:absolute;right:0px" class="gensmall">'+e+' '+x+' '+p+'&nbsp;'+shout[3]+'</div></div><br /><div id="ss'+shout[0]+'" style="position:relative;padding-left:10px;padding-top:3px;padding-bottom:2px;"><div class="gensmall" id="v'+shout[0]+'">'+this.bbcode(shout[2])+'</div></div>');

			tr = $('<tr>').append(td2, td);
			
			tbody = $('<tbody>').append(tr);

			table = $('<table>')
				.attr({
					id: 's'+shout[0],
					cellPadding: 6,
					cellSpacing: 0,
					width: $('#check').innerWidth(),
					border: 0
				})
				.addClass(this.tableClass)
				.css({
					position: 'absolute',
					top: '-100px'
				})
				.append(tbody);
			
			el.append(table);
			tables[tables.length] = shout[0];
		}
		
		tables = ( this.up ) ? tables : this.cArray(tables);
		
		//sliding
		setTimeout(function () {that.slideMessages(tables, {type: 0});that.f=0;}, 20);

	},
	
	slideMessages: function (newTabs, config, i, hl) {
		var oil = this.oldTabs.length, nil = newTabs.length, l, wh, that = this,
			row, lastTD, lastNewTD, TD;
		
		config = ( typeof config == 'undefined' ) ? { type: 0 } : config;
		
		config.which = ( typeof config.which == 'undefined' ) ? (( config.type == 0 ) ? (( this.up ) ? 'old' : 'new') : 'old') : config.which;

		if ( config.type == 2 && typeof config.d != 'undefined' && typeof i == 'undefined' ) {
			i = config.d;
		}
		
		if ( typeof hl == 'undefined'  ) {
			hl = this.pad;
			
			for ( l = 0; l < oil; l++ ) {
				hl = hl + $('#s'+this.oldTabs[l]).outerHeight();
			}
			for ( l = 0; l < nil; l++ ) {
				hl = hl + $('#s'+newTabs[l]).outerHeight();
			}

			if ( (Math.max(0, $('#mes').attr('scrollHeight')-$('#mes').outerHeight()) === $('#mes').attr('scrollTop')) && !this.up ) {
				l = -1;
			}
			
			$('#scr').css('top', hl+this.pad-$('#scr').outerHeight()+'px');
			
			if ( l == -1 ) {
				this.slideScroll('d');
			}
		}
		
		if ( i < 0 ) {
			return;
		}
		
		i = ( typeof i != 'undefined' ) ? i : 0;

		if ( i < oil && config.which == 'old' ) {
			el = $('#s'+this.oldTabs[i]);
			wh = hl-el.outerHeight();
			
			if ( config.type == 2 && $('#td'+this.oldTabs[i+1]).attr('class') == $('#td'+this.oldTabs[i]).attr('class') ) {
				el.find('td').attr('class', ( $('#td'+this.oldTabs[i]).attr('class') == this.rows[0] ) ? this.rows[1] : this.rows[0]);
			}
			
			el.animate({top: ((config.type != 2 ) ? wh : '-='+config.h)+'px'}, ( this.f ) ? 150 : 200);
			this.slideMessages(newTabs, config, ( config.type == 2 ) ? --i : ++i, wh);
		} else if ( i >= oil && config.which == 'old' ) {
			config.which = 'new';
			setTimeout(function () { that.slideMessages(newTabs, config, 0, hl); }, 250);
		} else if ( i < nil && config.which == 'new' ) {
			el = $('#s'+newTabs[i]);
			wh = hl-el.outerHeight();
			TD = $('#td'+newTabs[i]);
			lastNewTD = $('#td'+newTabs[i-1]);
			lastTD = $('#td'+this.oldTabs[( this.up ) ? oil-1 : 0]);
			
			if ( !this.up && !(newTabs.length%2) && i == 0 ) {
				row = ( lastTD.length ) ? ( (lastTD.attr('class') == this.rows[0]) ? this.rows[0] : this.rows[1] ) : 'row1';
			} else {
				row = ( lastNewTD.length ) ? ( (lastNewTD.attr('class') == this.rows[1]) ? this.rows[0] : this.rows[1] ) : (( lastTD.length ) ? ( (lastTD.attr('class') == this.rows[0]) ? this.rows[1] : this.rows[0] ) : 'row1');
			}
			
			el.find('td').attr('class', row);
			
			el.animate({top: wh+'px'}, ( this.f ) ? 200 : 400);
			if ( this.f ) {
				this.slideMessages(newTabs, config, ++i, wh);
			} else {
				setTimeout(function () {that.slideMessages(newTabs, config, ++i, wh);}, 100);
			}
		} else if ( i >= nil && config.which == 'new' ) {
			if ( this.up ) {
				this.oldTabs = jQuery.merge(this.oldTabs, newTabs);
			} else {
				this.oldTabs = jQuery.merge(newTabs, this.oldTabs);
			}
		}
	},
	
	slideScroll: function (t) {
		$('#mes').animate({ scrollTop: ( t == 'd' ) ? $('#mes').attr('scrollHeight')-$('#mes').outerHeight() : 0 }, 500);
	},
	
	setUP: function (v) {
		var i;
		
		if ( this.up === v ) {
			return false;
		}
		
		this.up = v;
		
		for ( i = 0; i < this.oldTabs.length; i++ ) {
			$('#s'+this.oldTabs[i]).css('top', '-100px');
		}
		
		this.oldTabs = this.cArray(this.oldTabs);

		this.slideMessages([], { type: 1 });
		
		return false;
	},
	
	sendMessage: function (message) {
		message = jQuery.trim(message);
	
		if ( message.length > sV.textL ) {
			alert(sV.lang[0]);
			return;
		} else if ( message.length === 0 ) {
			alert(sV.lang[3]);
			return;
		}

		if ( sV.s ) {
			$.ajax({
				type: 'GET',
				url: 'ajax_sb_mod/sb.php',
				data: ({v:message, m:'s', s:sV.sid}),
				success: function (text) { onSuccessSBMOD(text); }
			});
		}
		else {
			alert(sV.lang[1]);
		}
		
		this.sliderEvent();
		$('#message').val('');
	},
	
	deleteMessage: function (id) {
		var wh = jQuery.inArray(id, this.oldTabs),
			el = $('#s'+id), h, that = this;
			
		if ( !el.length ) { return; }
		
		$.ajax({
			type: 'GET',
			url: 'ajax_sb_mod/sb.php',
			data: ({i:id, m:'d', s:sV.sid}),
			success: function (text) { onSuccessSBMOD(text); }
		});

		el.animate({opacity: 0}, {
			duration: 300,
			complete: function () {
				h = el.outerHeight();
				that.oldTabs.splice(wh, 1);
				el.remove();
				if ( typeof that.oldTabs[wh-1] !== 'undefined' || !that.up ) {
					that.slideMessages([], { type: 2, d: wh-1, h: h });
				}
			}
		});

		return false;
	},
	
	editMessage: function (id, o) {
		var ss, t, text, button, span, that = this;
					
		if ( $('#span'+id).length ) {
			ss = $('#ss'+id);
			
			span = $('#span'+id);
			text = $('#text'+id);
			t = text.val();
			
			if ( t > sV.textL ) {
				alert(sV.lang[0]);
				return false;
			}
			
			if ( o ) {
				$.ajax({
					type: 'GET',
					url: 'ajax_sb_mod/sb.php',
					data: ({i:id, m:'e', v:t, s:sV.sid}),
					success: function (text) { onSuccessSBMOD(text); }
				});
				
				this.orgMes[id] = t;
				
				$('#v'+id).html(this.bbcode(t));
			}

			span.slideUp(600, function () { span.remove(); });
			$('#message').focus();
		}
		else {
			ss = $('#ss'+id);
			t = $('#v'+id).text();
			text = $('<input>')
					.attr({
						id: 'text'+id,
						type: 'text',
						value: this.orgMes[id]
					})
					.css({ fontSize: '9px', width: '350px' })
					.keypress(function (e) {
						if ( e.keyCode == 13 ) {
							that.editMessage(id, true);
							$('#message').focus();
						}
					})
					.addClass('post');
			button = $('<input>')
					.attr({
						type: 'button',
						value: sV.lang[5]
					})
					.addClass('button')
					.css({ fontSize: '9px' })
					.click(function () {that.editMessage(id, true);});
			span = $('<span>')
					.attr({
						id: 'span'+id
					})
					.css({ display: 'none', width: '450px', position: 'absolute', top: '0px', left: '0px' })
					.append(text, '&nbsp;&nbsp;', button);
			
			ss.prepend(span);
		
			$('#span'+id).slideDown(600);
			$('#text'+id).focus();
		}
		
		return false;
	},
	
	bbcode: function (message) {
		var word_max_length = sV.wordL, in_tag = false, t_text = '', final_text = '', cur_count = 0, z, i, reg;
		
		message = message.replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
		
		if ( sV.bbcode ) {
			message = message.replace(/\[b\](.*?)\[\/b\]/gi, '<b>$1</b>')
						.replace(/\[i\](.*?)\[\/i\]/gi, '<i>$1</i>')
						.replace(/\[u\](.*?)\[\/u\]/gi, '<u>$1</u>')
						.replace(/\[color=(\#[\da-f]{6}|[a-z]+|rgb\([\d]{1,3}, [\d]{1,3}, [\d]{1,3}\))\](.*?)\[\/color\]/gi, '<span class="gensmall" style="color:$1">$2</span>');
		}
		
		if ( sV.smilies ) {
			for ( i = 0; i < sV.smiles.code.length; i++ ) {
				reg = new RegExp('(?:[\\s]|^)'+sV.smiles.code[i].replace(/(\-|\)|\(|\\|\?|\||\[|\]|\/|\{|\}|\*|\+|\.|\^|\$)/gi, '\\$1')+'(?:[\\s]|$)', 'gi');
				message = message.replace(reg, '<img src="images/smiles/'+sV.smiles.url[i]+'" style="vertical-align:middle;width:15;height:15;">');
			}
		}
		
		if ( sV.makeLinks ) {
			message = message.replace(/(^|[\n ])([\w]+?:\/\/\S[\w\#()$%&~\/.\-;:=,?@\[\]+]*)/gi, '$1<a href="$2" class="gensmall" target="_blank">$2</a>')
						.replace(/(^|[\n ])((www|ftp)\.\S[\w\#()$%&~\/.\-;:=,?@\[\]+]*)/gi, '$1<a href="http://$2" class="gensmall" target="_blank">$2</a>');
		}
		
		for ( i = 0; i < message.length; i++ ) {
			z = message.slice(i, i+1);
			
			if ( z === '<' ) {
				t_text += z;
				in_tag = true;
			}
			else if ( in_tag === true && z === '>' ) {
				t_text += z;
				in_tag = false;
			}
			else if ( in_tag === true ) {
				t_text += z;
			}
			else if ( z === ' ' ) {
				final_text += t_text+' ';
				t_text = '';
				cur_count = 0;
			}
			else if ( cur_count > word_max_length ) {
				final_text += t_text + z + ' ';
				t_text = '';
				cur_count = 0;
			}
			else {
				t_text += z;
				cur_count++;
			}
		}
		
		return final_text + t_text;
	},
	
	sliderEvent: function () {
		var sl = $('#slider');

		if ( !this.h ) { 
			sl.css({display: 'block', top: '0px', left: '0px'});
			this.h = 1;
		}
		else {
			sl.css({zIndex: 1});
			this.h = 0;
		}
	},
	
	tintedDoc: function () {
		var div;
	
		if ( $('#tinted').length ) {
			$('#tinted').remove();
			return;
		}
	
		div = $('<div>').attr({id: 'tinted'})
			.css({position: 'absolute', top: '0px', left: '0px', height: document.body.clientHeight+document.body.scrollTop+'px', width: document.body.clientWidth+document.body.scrollLeft+'px', backgroundColor: 'black', zIndex: 299, opacity: 0 });
		
		$(document.body).append(div);
	},
	
	slideBBcode: function () {
		var div;

		if ( ie ) {
			alert(unescape('%69%74%27%73%20%6E%6F%74%20%66%6F%72%20%69%65'));
			return;
		}
		if ( $('#zaslona').length ) { return; }
		
		this.tintedDoc();
		$('#tinted').append('<div id="texty" align="center" style="position:absolute;z-index:300;color:white;width:100%;vertical-align:middle;font-size:70px;font-weight:bold"><div style="position:absolute;left:0px;">'+unescape('%41%4A%41%58%20%53%42%20%3C%62%72%20%2F%3E%43%52%45%41%54%45%44%20%42%59')+'</div><div id="mistrz" style="position:absolute;right:0px;font-size:0px;font:weight:bold;color:red;vertical-align:center;">'+unescape('%70%61%7A%6D%61%74')+'</div></div>');

		$('#texty').css({opacity: 0});
		
		setTimeout(function () {
			$('#tinted').animate({opacity: 0.8}, 1000, function () {
				setTimeout(function() {
					$('#texty').animate({top: (document.body.scrollTop+50)+'px', opacity: 1}, 1000, function () { 
							$('#mistrz').animate({fontSize: 200}, 10000, function () { 
								setTimeout(function () { $('#mistrz').css('color', 'blue'); setTimeout(function () { $('#mistrz').css('color', 'red'); setTimeout(function () {$('#tinted').animate({opacity: 0}, 700, function () { $('#tinted').remove(); });}, 2000); }, 500); }, 500);
							});
						});
				}, 1000);
			});
		}, 1500);
	},
	
	setBBcode: function (tag, tar) {
		var el = document.getElementById('message'),
			tags = ['['+tag+']', '[/'+tag+']'],
			selText = false,
			oneTag = ( typeof tar == 'object' ) ? true : false,
			smile = ( tar == 's' ) ? true : false,
			wh = 0;
		
		if ( ie ) {
			if ( document.selection.createRange().text.length > 0 ) { selText = true; }
		}
		else {
			if ( (el.selectionEnd - el.selectionStart) !== 0 ) { selText = true; }
		}

		if ( oneTag && !selText && !smile ) {
		
			clIn = ( tar.value.indexOf('*') === -1 ) ? true : false;
			wh = ( clIn === true ) ? 0 : 1;
			
			if ( clIn === true ) {
				tar.value += '*';
			}
			else {
				tar.value = tar.value.slice(0, 1);
			}
		}
		else
		{
			if ( tag == 'color' ) {
				tags[0] = '['+tag+'='+tar+']';
			}
		}
		
		el.focus();
		
		if ( ie ) {
			if ( smile ) {
				document.selection.createRange().text = tag;
				return false;
			}
			if ( !selText ) {
				if ( oneTag ) {
					document.selection.createRange().text = tags[wh];
				}
				else {
					document.selection.createRange().text = tags[0] + tags[1];
				}
			}
			else {
				document.selection.createRange().text = tags[0] + document.selection.createRange().text + tags[1];
			}

		}
		else 
		{
			var s1 = el.value.slice(0, el.selectionStart),
				s2 = el.value.slice(el.selectionStart, el.selectionEnd),
				lastPart = el.value.slice(el.selectionEnd, el.textLength),
				firstPart;
			
			if ( smile ) {
				el.value = s1 + tag + s2 + lastPart;
				return false;
			}
			
			if ( !selText ) {
				if ( oneTag ) {
					firstPart = s1 + tags[wh];
					lastPart = s2 + lastPart;
				}
				else {
					firstPart = s1 + tags[0] + s2 + tags[1];
				}
			}
			else {
				firstPart = s1 + tags[0] + s2 + tags[1];
			}
			el.value = firstPart + lastPart;
			el.setSelectionRange(firstPart.length, firstPart.length);
		}
		
		return false;
	},
	
	showBBcode: function () {
		var bbtab = $('#BBtab'), h = bbtab.outerHeight(), switchc = $('#switchc'),
			hide = ( !this.bbpanel ) ? true : false;
	
		bbtab.animate({top: (( !hide ) ? '-' : '+')+'='+h+'px'}, {duration: 600});
		switchc.html(( hide ) ? '&uarr;&uarr;' : '&darr;&darr;');
		
		this.bbpanel = ( hide ) ? 1 : 0;
		
		$('#message').focus();
		
		return false;
	},
	
	inactiveCount: function () {
		var that = this;
		
		this.inSec++;
		
		if ( this.inSec > sV.inTime ) {
			this.winAct = 0; 
		}
		else {
			this.winAct = 1;
		}
		if ( this.inSec > sV.turnOFF ) {
			this.turnOFFsb();
			return;
		}
		
		setTimeout(function () {that.inactiveCount();}, 1000);
	},
	
	turnOFFsb: function () {
		var table, tbody, tr, td, mes = $('#mes');
		
		if ( $('#veil').length ) {
			this.sbOFF = 0;
			
			$('#veil').remove();

			this.inactiveCount();
			
			return false;
		}
		
		this.sbOFF = 1;
		
		td = $('<td>').addClass('row1').css({ verticalAlign: 'middle', textAlign: 'center' }).append('<a href="#" class="gensmall" onclick="return AJAXSBMOD.turnOFFsb();">'+sV.lang[2]+'</a>');
		
		tr = $('<tr>').append(td);
		
		tbody = $('<tbody>').append(tr);
		
		table = $('<table>').attr({
				id: 'veil'
			})
			.addClass('forumline')
			.css({ position: 'absolute', zIndex: 45, top: $('#mes').attr('scrollTop'), left: '0px', width: mes.outerWidth(), height: mes.height() })
			.append(tbody);
		
		mes.append(table);
	},
	
	setBBpanelPos: function () {
		this.s++;

		if ( this.s == ( sV.smiles.code.length > 20 ) ? 20 : sV.smiles.code.length ) {
			$('#BBtab').css({
				top: $('#SB').outerHeight()-$('#BBtab').outerHeight()+'px',
				left: '0px'
			});
		}
	}
};

$(document).ready(function () {
	var sb = $('#SB'), mes = $('#mes'),
		bbtab = $('#BBtab'),
		switcht = $('#switch'),
		switchtd = $('#switchtd'),
		smiles = $('#smiles'), i, html = '', smile, l;
	
	AJAXSBMOD.pad = parseInt(mes.css('padding'), 10);

	switchtd.mouseover(function () { onv(this); });
	switchtd.mouseout(function () { ont(this); });
	switchtd.click(function () { 
		AJAXSBMOD.showBBcode();
	});

	$('#slider').click(function () { AJAXSBMOD.slideBBcode(); });

	smiles.css('width', parseInt($('#god').css('width'), 10)-switcht.outerHeight()-bbtab.attr('cellPadding')-2+'px');
	
	for ( i = 0, l = ( sV.smiles.code.length > 20 ) ? 20 : sV.smiles.code.length; i < l; i++ ) {
		smile = $('<img>')
			.attr({
				src: 'images/smiles/'+sV.smiles.url[i]
			})
			.css('cursor', 'hand')
			.click(function (a) { return function () {AJAXSBMOD.setBBcode(' '+sV.smiles.code[a]+' ', 's'); } }(i))
			.load(function () { AJAXSBMOD.setBBpanelPos(); });

		smiles.append(smile);
	}
	
	if ( l == 20 ) {
		smiles.append(' <a href="posting.php?mode=smilies" onclick="window.open(\'posting.php?mode=smilies\', \'_phpbbsmilies\', \'HEIGHT=300,resizable=yes,scrollbars=yes,WIDTH=450\');return false;" target="_phpbbsmilies" class="gensmall" style="vertical-align:middle">'+sV.lang[6]+'</a>');
	}
	
	html = '';
	
	for ( i = 0; i < AJAXSBMOD.colors.length; i++ ) {
		html += '<div style="width:10px;display:inline;background-color:'+AJAXSBMOD.colors[i]+';cursor:hand;" onclick="return AJAXSBMOD.setBBcode(\'color\', \''+AJAXSBMOD.colors[i]+'\');">&nbsp;&nbsp;&nbsp;</div>';
	}
	
	$('#colors').html(html);
	
	switcht.css({
		top: sb.innerHeight()+'px',
		left: sb.outerWidth()-switcht.outerWidth()+'px'
	});
	
	AJAXSBMOD.getData();
	AJAXSBMOD.inactiveCount();
	
	$('#message').keypress(function (e) {
		if ( e.keyCode == 13 ) {
			AJAXSBMOD.sendMessage($('#message').val());
			$('#message').focus();
			return false;
		}
	});

}).click(function () { AJAXSBMOD.inSec = 0; })
	.keypress(function () { AJAXSBMOD.inSec = 0; })
	.mouseover(function () { AJAXSBMOD.inSec = 0; })
	.focus(function () { AJAXSBMOD.inSec = 0; });
