function richtextImagePositioning()
	{
	// Richtext content images - wrap text around narrower images (no changes made if images already floated)
	// Last modified: 26 August 2009 (TS)
	// ----------------------------------
	var divs, imgs, i, j, widthThreshold, contentDiv, imageMargins;

	/*
	 * 	GET THE ELEMENT THAT CONTAINS THE CONTENT
	 */
	contentDiv = document.getElementById('content');
	if (!contentDiv) return; // !! Early Return !!
	/*
	 * 	THIS LINE SETS THE THRESHOLD BELOW WHICH WORDS ARE WRAPPED AROUND A LEFT FLOATED IMAGE
	 */
	widthThreshold = contentDiv.offsetWidth * 0.7;
	/* 
	 *	THIS LINE SETS IMAGE MARGINS
	 */
	imageMargins = '15px';

	divs = contentDiv.getElementsByTagName('div');
	for (i=0; i< divs.length; ++i)
		{
		if(divs[i].className == 'richtext-container')
			{
			// Remove empty text nodes between images (IE workaround)
			if (ieversion) divs[i].innerHTML = divs[i].innerHTML.replace(/(<(img|IMG)[^>]+>)(\&nbsp;|\s)+\<(IMG|img)/, '$1<img');

			imgs = divs[i].getElementsByTagName('img');
			for (j=0; j<imgs.length; ++j)
				{
				if (!imgs[j].style.cssFloat && !imgs[j].style.styleFloat) // If not already floated
					{
					if (imgs[j].offsetWidth + imgs[j].offsetLeft < widthThreshold)
						{
						imgs[j].style.cssFloat = 'left';
						imgs[j].style.styleFloat = 'left';
						imgs[j].style.marginRight = imageMargins;
						}
					else
						{
						if (imgs[j].getAttribute('style')) imgs[j].removeAttribute('style');
						}

					// Remove empty text nodes after images (non-IE)
					if (!ieversion)
						{
						if (imgs[j].nextSibling && imgs[j].nextSibling.nodeType == 3 && imgs[j].nextSibling.nodeValue.match(/^(\&nbsp;|\s)+$/)) imgs[j].parentNode.removeChild(imgs[j].nextSibling);
						}

					// Add margin-right if image comes next 
					if (imgs[j].nextSibling && imgs[j].nextSibling.tagName && imgs[j].nextSibling.tagName.toLowerCase() == 'img') imgs[j].style.marginRight = imageMargins;
					}
				}
			}
		}
	}

var ieversion; // !! GLOBAL !!

function layout()
	{
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) //test for MSIE x.x;
		ieversion=new Number(RegExp.$1);
	else
		ieversion = null;

	richtextImagePositioning();
	}

if (window.addEventListener) // DOM Level 2 API
	{
	window.addEventListener("load", layout, 0);
	window.addEventListener("resize", richtextImagePositioning, 0);
	}
else if (window.attachEvent) // IE workaround
	{
	window.attachEvent("onload", layout);
	window.attachEvent("onresize", richtextImagePositioning);
	}
