function prepareImages() {
	var links = document.getElementsByTagName('a');

	for (var i = 0; i < links.length; i++){
		if (links[i].className == 'aniImg')
		{
			var img = links[i].getElementsByTagName('img')[0];		
			img.state = 'small';
			img.smallSrc = img.getAttribute('src');
			img.smallWidth = parseInt(img.getAttribute('width'),"10");
			img.smallHeight = parseInt(img.getAttribute('height'),"10");
			img.bigSrc = links[i].getAttribute('href');
			img.bigWidth = parseInt(img.getAttribute('bigwidth'),"10");
			img.bigHeight = parseInt(img.getAttribute('bigheight'),"10");
			img.ratio = img.smallHeight / img.smallWidth;
			links[i].flag = "image";
			links[i].onclick = scale;
		}
	}
}

function prepareMap(){
		var img = document.getElementById('mapImg');		
		var link = document.getElementById('mapLink');		
		img.state = 'small';
		img.smallSrc = img.getAttribute('src');
		img.smallWidth = parseInt(img.getAttribute('width'),"10");
		img.smallHeight = parseInt(img.getAttribute('height'),"10");
		img.bigSrc = link.getAttribute('href');
		img.bigWidth = parseInt(img.getAttribute('bigwidth'),"10");
		img.bigHeight = parseInt(img.getAttribute('bigheight'),"10");
		img.ratio = img.smallHeight / img.smallWidth;
		link.flag = "map";
		link.onmouseover = scale;
		link.onmouseout = scale;
}

function scale()
{
	var img = this.getElementsByTagName('img')[0];		
	img.src = img.smallSrc;

	// if we are scaling up, scale down everything else
	
	if (img.state == 'small')
	{
		var links = document.getElementsByTagName('a');
		
		for (var i = 0; i < links.length; i++)
			if ((links[i].className == 'aniImg') &&
					(links[i].getElementsByTagName('img')[0].state == 'big') && 
				  (links[i] != this))
				links[i].onclick();
	}
	
	if (! img.preloaded)
	{
		img.preloaded = new Image();
		img.preloaded.src = img.bigSrc;
	}

	var interval = window.setInterval(scaleStep, 10);
	return false;
	
	function scaleStep()
	{
		var step = 10;
		var width = parseInt(img.getAttribute('width'));
		var height = parseInt(img.getAttribute('height'));
		
		if (img.state == 'small')
		{
			width += step;
			height += Math.floor(step * img.ratio);
			
			img.setAttribute('width', width);
			img.setAttribute('height', height);
			
			if (width > img.bigWidth - step)
			{
				img.setAttribute('width', img.bigWidth);
				img.setAttribute('height', img.bigHeight);
				img.setAttribute('src', img.bigSrc);
				window.clearInterval(interval);
				img.state = 'big';
			}
		}
		else
		{
			width -= step;
			height -= Math.floor(step * img.ratio);

			img.setAttribute('width', width);
			img.setAttribute('height', height);
			
			if (width < img.smallWidth + step)
			{
				img.setAttribute('width', img.smallWidth);
				img.setAttribute('height', img.smallHeight);
				img.src = img.smallSrc;
				window.clearInterval(interval);
				img.state = 'small';
			}
		}
	}			
}
