function pageLoad() {
	// start rotator
	rotatorPreLoadImages();
}

var _rotatorMaxWidth = 265;
var _rotatorMaxHeight = 178;
var _rotatorLastImage = -1;
var _rotatorImageCount = 8;
var _rotatorBasePath = "/Portals/9/rotator/";
var _rotatorMode = 'static';
var _rotatorCache = [];

function rotatorPreLoadImages() {
	$bgImg = $("#container_rotator img");
	
	switch (_rotatorMode) {
		case 'static':
			if (window.location.pathname == '/') {				
				$bgImg.css('background-image', 'url(/Portals/9/Skins/Saemor.Saemor/images/image_1.jpg)');
			}
			break;
	}
	
	for (x = 1; x <= _rotatorImageCount; x++) {
		var img = document.createElement('img');
		img.src = _rotatorBasePath + (x < 10 ? '0' : '') + x + '.JPG';
		var ratio = 0;
		if (img.width == 0) {
			img.width = _rotatorMaxWidth;
		}
		
		if (img.width > _rotatorMaxWidth) {
			// resize width
			ratio = _rotatorMaxWidth / img.width;
			img.width = _rotatorMaxWidth;
			img.height = img.height * ratio;
		}
		if (img.height >  _rotatorMaxHeight) {
			// resize height
			ratio = _rotatorMaxHeight / img.height;
			img.height = _rotatorMaxHeight;
			img.width = img.width * ratio;
		}
		
		var $img = $(img);
		$img.hide();
		$("#container_rotator").append($img);
		
		_rotatorCache.push($img);
	}
	
	// start rotator
	switch (_rotatorMode) {
		case 'static':
			if (window.location.pathname != '/') {				
				var randomImg = Math.round(Math.random() * (_rotatorImageCount - 1));
				_rotatorCache[randomImg].show();
			} 
			break;
		default:
			window.setTimeout("rotateImage()", 1000);
			$bgImg.fadeOut('slow');
		break;
	}
}

function rotateImage() {
	var x = _rotatorLastImage + 1;
	if (x >= _rotatorImageCount) x = 0;
	
	if (_rotatorLastImage != -1) {
		_rotatorCache[_rotatorLastImage].fadeOut('slow');
	}
	
	_rotatorCache[x].fadeIn('slow');
	
	window.setTimeout("rotateImage()", 5000);
	_rotatorLastImage = x;
}
