Event.observe(document, 'dom:loaded', function() {
	
	// Bail on IE 6
	if (Prototype.Browser.IE) {
		var m = navigator.appVersion.match(/^.*MSIE\s*(\d+).*$/);
      		if (!m || parseInt(m[1], 10) < 7) {
        		return;
      	}
    }
	
	var imageGroups=$H({
		
		'home' : [
			{'folder':'', 'filename':'NICOffice_Norway.png', 'weight':3},
			{'folder':'', 'filename':'NIC Office.png', 'weight':3},
			{'folder':'', 'filename':'NICOffice_CornerTree.png', 'weight':3},
		]
	});

	var imagePools = $H();

	imageGroups.each(function(imageGroup){
		var imagePool = [];
		imageGroup.value.each(function(image){
			image.weight.times(function(){ imagePool.push(image); });
		});
		imagePools[imageGroup.key] = imagePool;
	});

	$$('.randomimage').each(function(el){
		var imageType = el.classNames().find(function(cls){return imagePools[cls];});	
		var imagePool = imagePools[imageType];
		var image = imagePool[Math.floor(Math.random() * imagePool.length)];
		var thumbnail = el.down('img');
		
		thumbnail.src = 'http://www.nearinfinity.com/home/images/#{folder}/#{filename}'.interpolate(image);
		
		imagePools[imageType] = imagePool.without(image);
	});
		
	// Clean up... we're done
	imagePools = null;
	imageGroups = null;
});