var postImg_MaxWidth = screen.width - 202;
var postImgAligned_MaxWidth = Math.round(screen.width/3);
var attachImg_MaxWidth = screen.width - 280;
var ExternalLinks_InNewWindow = '1';

function initPostBBCode(context)
{
	initSpoilers(context);
	imgFit_Onload(context);
	initExternalLinks(context);
	keep4u_ReplaceImages(context);
}
function initSpoilers(context)
{
	var context = context || 'body';
	$('div.sp-head-wrap', $(context)).click(function(){
		$(this).find('div.sp-head').toggleClass('unfolded');
		$(this).next('div.sp-body').slideToggle('fast');
	});
}
function initExternalLinks(context)
{
	var context = context || 'body';
	if (ExternalLinks_InNewWindow) {
		$("a.postLink:not([@href*='"+ window.location.hostname +"/'])", $(context))
			.bind("click", function(){ return !window.open(this.href); })
		;
	}
}
function keep4u_ReplaceImages(context)
{
	var context = context || 'body';
	$("img.postImg[@src*='keep4u']", $(context)).each(function(){
		var new_src = this.src.replace(/http:\/\/keep4u.ru\/imgs\/\w\/(.*)\/(.*)\.(.*)/, "http://keep4u.ru/torrents/$1/$2.$3");
		var new_url = this.src.replace(/http:\/\/keep4u.ru\/imgs\/\w\/(.*)\/(.*)\.(.*)/, "http://keep4u.ru/full/$1/$2/$3");
		this.src = new_src;
		$(this).wrap('<a href="'+new_url+'" target="_blank"></a>');
	});
}
$(document).ready(function(){
	initSpoilers('body');
	initExternalLinks();
	keep4u_ReplaceImages();
});
$(window).load(function(){ imgFit_Onload('body'); });
