/***********************************************************************
Image-resize script
(c) Copyright GoT (Gathering.tweakers.net) & Crisp.
Code mag dan ook alleen op uitdrukkelijke toestemming van 
Crisp en/of GoT gebruikt worden.
***********************************************************************/
var incompetent_browser = document.all && navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('Opera') == -1;

function user_images()
{
	var im = document.images, i = im.length;
	while (i--)
	{
		if (im[i].className == 'rml' || im[i].className == 'rmlleft' || im[i].className == 'rmlright')
		{
			if (im[i].naturalWidth || im[i].complete)
				scaleImage(0,im[i]);
			else if (typeof im[i].onreadystatechange != 'undefined')
				im[i].onreadystatechange = scaleImage;
			else
				im[i].onload = scaleImage;
			im[i].onerror = scaleImage;
			im[i].onabort = scaleImage;
		}
	}
	if (incompetent_browser && window.attachEvent) window.attachEvent('onload', user_images_ie); 
}

function user_images_ie()
{
	var im = document.images, i = im.length;
	while (i--)
	{
		if (im[i].className == 'rml' || im[i].className == 'rmlleft' || im[i].className == 'rmlright')
			scaleImage(0,im[i]);
	}
}

function scaleImage(e,img)
{
	if (!img) var img = this;
	var width = height = 0;

	if (img.width || img.complete)
	{
		if (img.naturalWidth)
		{
			width = img.naturalWidth;
			height = img.naturalHeight;
		}
		else if (img.complete)
		{
			var dum = new Image(); dum.src = img.src;
			width = dum.width;
			height = dum.height;
		}
		if (width && img.onreadystatechange) img.onreadystatechange = null;

		var contentDiv = img.parentNode;
		while (contentDiv.className != 'content' && contentDiv.className != 'message-quote-div') contentDiv = contentDiv.parentNode;

		var maxWidth = contentDiv.offsetWidth - (contentDiv.className == 'content' ? 14 : 6);

		if (width > maxWidth)
		{
			if (img.parentNode.tagName.toLowerCase() != 'a')
			{
				if (!img.naturalWidth) img.naturalWidth = width;
				if (!img.naturalHeight) img.naturalHeight = height;
				img.className = 'resized hand';
				img.onclick = openImage;
			}
		}
		if (img.width > maxWidth) img.width = maxWidth;
	}
}

function openImage()
{
	var popup = window.open('showimage.html?'+escape(this.src),'','toolbar=no,location=no,menubar=no,scrollbars=no,width='+this.naturalWidth+',height='+this.naturalHeight+',resizable=yes,status=no');
	try { popup.focus(); } catch(e) {}
}