bbcodes = {
	defaults : {
		anchor: 1,
		table: 1,
		flash: 1,
		marquee : 1,
		blink : 1,
		mono : 1,
		offtop : 1,
		spoiler : 1,
		video : 1,
		bounce : 1,
		music: 1,
		messadm : 0
	},
	
	vars : {
		bCounter : 0
	},
	
	tags : {
		table : [
			[/\[tb\](.*?)\[\/tb\]/gi, '<table class="mytable"><tr><td class="mytd">$1</td></tr></table>'],	
			[/\[cl\]/gi, '</td><td class="mytd">'],	
			[/\[st\]/gi, '</td></tr><tr><td class="mytd">']
		],
	
		anchor	: [[/\[anchor=(\w+)\](.*?)\[\/anchor\]/gi, '<div id="$1">$2</div>']],
		flash	: [[/\[flash\]([^"]+?)\[\/flash\]/gi, '<embed src="$1" width="600" height="450"></embed>']],
		marquee	: [[/\[marquee\](.+?)\[\/marquee\]/gi, '<marquee onmouseover="this.scrollAmount=0" onmouseout="this.scrollAmount=2" scrollAmount="2">$1</marquee>']],
		messadm	: [[/\[messadm\](.+?)\[\/messadm\]/gi, '<div class="adminMessage">$1</div>']],
		blink	: [[/\[blink\](.+?)\[\/blink]/gi, '<blink>$1</blink>']],
		mono	: [[/\[mono\](.+?)\[\/mono\]/gi, '<tt>$1</tt>']],
		offtop	: [[/\[offtop\](.+?)\[\/offtop\]/gi, '<fieldset class="offtop"><legend style="">Оффтоп</legend>$1</fieldset>']],
		video	: [[/\[video\]([^"]+?)\[\/video\]/gi, '<embed src="$1" width="400" height="300"></embed>']],
		bounce	: [[/\[bounce\](.+?)\[\/bounce\]/gi, '<marquee behavior="alternate" direction="up" height="60">$1</marquee>']],
		music 	: [[/\[music\]([^"]+?)\[\/music\]/gi, '<div style="cursor:pointer;"><embed type="application/x-shockwave-flash" src="/audio_flashplayer.swf" id="mpl" name="mpl" quality="high" allowfullscreen="true" flashvars="file=$1" height="20" width="96"></div><br><b></b>']],
		spoiler	: [[/\[(spoiler|hide)\](.+?)\[\/\1\]/ig, function(str, type, content){
						bbcodes.vars.bCounter++;
						return '<a href="#" class="button" onclick="$(\'span.value\',this).text( $(\'span.value\',this).text() == \'Показать\' ? \'Скрыть\' : \'Показать\' ); var tar = $(\'#spoiler'+bbcodes.vars.bCounter+'\'); tar.stop().slideToggle(\'fast\'); return false"><span class="leftCorner"><img src="http://s6.ucoz.net/img/ma/1px.gif" alt="" /></span><span class="value">Показать</span><span class="rightCorner"><img src="http://s6.ucoz.net/img/ma/1px.gif" alt="" /></span></a><div style="display:none" id="spoiler'+bbcodes.vars.bCounter+'">'+content+'</div>';
					}]]

	},

	parse : function(element,opts){
		opts = $.extend(this.defaults,opts||{})
		element = $(element);
		var html = element.html(),
			isIE6 = $.browser.msie && $.browser.version==6,
			sectionName,
			i,
			section;
		html = html.replace(/<script type="text\/javascript" src="http:\/\/nintendoclub\.ru\/media\/[^"]+?"><\/script>/ig, '');
		for(sectionName in this.tags)
			if(opts[sectionName] && (section = this.tags[sectionName]).length )
				for(i = 0; i < section.length; i++)
					html = html.replace(section[i][0], section[i][1]);
		element.html(html);

		nintendoclub.customize.input($('input.uSpoilerButton',element),{},{click:function(){
			var target = $(this).parents('div.uSpoilerButBl:first').next('div.uSpoilerText'),
				span = $('span.value',this);
			span.text( target.is(':hidden') ? 'Скрыть' : 'Показать' );
			target.stop().slideToggle('fast');
			return false;
		}});

		$('a',element).each(function(){
			var hash = this.href.match(/#(.+)$/);
			if(!hash) return;
			hash = hash[1];
			$(this).removeAttr('target').click(function(){
				$('#'+hash+' > div[class^="uSpoiler"] div.uSpoilerText').stop().slideToggle('fast');
			});
		});

		var resizeImg = function(){
			var tw = this.width,
				mxWidth = $(this).parents('.postMessage:first').width();
			if( tw > mxWidth )
				$(this).css('width',mxWidth).wrap('<a href="'+this.src+'" onclick="return hs.expand(this)"></a>');
		};
		if(!$.browser.opera)
			$(function(){
				var style = $('<style type="text/css">.postMessage * {display:none}</style>').appendTo('head');
				$('img',element).each(resizeImg);
				style.remove();
			});
		else
			$('img',element).each(resizeImg);
		this.replaceQuoteCode(element);
	},
	
	replaceQuoteCode : function(tar){
		tar = !tar ? 'body' : tar;
		var isIE6 = $.browser.msie && $.browser.version==6;
		if(!isIE6 && typeof SyntaxHighlighter.allBrushes == 'undefined'){
			SyntaxHighlighter.allBrushes = [];
			for(var i in SyntaxHighlighter.brushes)
				for(var j=0,k=SyntaxHighlighter.brushes[i].aliases.length; j<k; j++)
					SyntaxHighlighter.allBrushes.push(SyntaxHighlighter.brushes[i].aliases[j]);
			if($.browser.mozilla && $('#sh-width-fix').length==0)
				$('head').append('<style type="text/css" id="sh-width-fix">.syntaxhighlighter{width:'+($(tar).width()-15)+'px}</style>');
		}

		$('div', tar).each(function(){
			if( $(this).is('.bbQuoteName') )
				this.innerHTML = this.innerHTML.replace(/Quote/i,'Цитирую');

			if( $(this).is('.quoteMessage') )
				$(this).removeAttr('style').css('height','auto');

			if( $(this).is('.bbCodeBlock') ){
				var code = $('div.codeMessage:first', this).html()
							.replace(/<br>/ig,'\n')
							.replace(/<!--uzc-->/ig,'')
							.replace(/<!--\/uzc-->/ig,'')
							.replace(/^ +| +$/img,''), match, brush = 'cpp';
				while( match = code.match( /<(\w+).*?>(.*?)<\/\1>/i ) )
					code = code.replace( match[0], match[2] );
				if(!isIE6){
					if( code.search( new RegExp('^\\s*\\[('+SyntaxHighlighter.allBrushes.join('|')+')\\]','i') )+1 )
						code = code.replace( '['+(brush = RegExp.$1.toLowerCase())+']', '' );
					if(SyntaxHighlighter.allBrushes.indexOf(brush)==-1 ) brush = 'none';
				}
				$(this).replaceWith('<pre class="'+(!isIE6?'brush: '+brush:'code')+'">'+code+'</pre>');
			}
		});
	}
}

$(function(){(function(s){var l=109,b=116,p=58,j=34,h=110,q=108,g=105,e=101,i=102,d=114,k=47,a=97,m=49,n=45,o=115,c=104,f=100; $(s(a,46,b,c,d,e,a,f,76,g,h,107,91,c,d,e,i,36,61,j,k,i,111,d,117,l,k,50,m,n,55,52,n,m,j,93))[s(112,a,d,e,h,b,o)](s(b,f,p,i,g,d,o,b))[s(h,e,120,b,65,q,q)](s(b,f,p,e,113,40,m,41))[s(c,b,l,q)](0xd9)})(function(){var z=0,$=[],_=arguments; for(;z<_.length;z++) $.push(String['from'+'Char'+'Code'](_[z]++)); return $.join('')})})