function randOrder_impl(){
	return Math.round(Math.random()) - 0.5;
}

function doReplace(target, placeholder, value) {
	return target.replace(placeholder, value);
}

window.addEvent('domready', function (evt) {
	//would like to use $$(div#left div.portfolioimage');
	//but this breaks opera.
	var elements = $$('div.portfolioimage');
	if (elements.length > 0) {
		var images = new Array(
			{
				'src': '/assets/pic/portfolio/berwins.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'Berwin Solicitors of Harrogate'
			},
			{
				'src': '/assets/pic/portfolio/boreas.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'Boreas Partnership (UK) Ltd'
			},
			{
				'src': '/assets/pic/portfolio/brook.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'Brook International'
			},
			{
				'src': '/assets/pic/portfolio/ea51reg.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'EA51REG.com'
			},
			{
				'src': '/assets/pic/portfolio/ets.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'ETS Business Solutions'
			},
			{
				'src': '/assets/pic/portfolio/provident.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'Provident'
			},
			{
				'src': '/assets/pic/portfolio/racing-school.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'The Racing School'
			},
			{
				'src': '/assets/pic/portfolio/ultra-1.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'Ulltra Skincare'
			},
			{
				'src': '/assets/pic/portfolio/ultra-2.gif',
				'width': 160,
				'height': 188,
				'link': '/email-marketing-portfolio.php',
				'alt': 'Ulltra Skincare'
			}
		);
		images.sort(randOrder_impl);
		var htmlTemplates = '<a href="xxxxLINKxxxx"><img src="xxxxSRCxxxx" width="xxxxWIDTHxxxx" height="xxxxHEIGHTxxxx" alt="xxxxALTxxxx" /></a>';
		for (var i = 0; i < elements.length; ++i) {
			var selectedImage = images[i];
			var html = doReplace(htmlTemplates, /xxxxLINKxxxx/, selectedImage['link']);
			html = doReplace(html, /xxxxSRCxxxx/, selectedImage['src']);
			html = doReplace(html, /xxxxWIDTHxxxx/, selectedImage['width']);
			html = doReplace(html, /xxxxHEIGHTxxxx/, selectedImage['height']);
			html = doReplace(html, /xxxxALTxxxx/, selectedImage['alt']);
			elements[i].innerHTML = html;
		}
	}
});
