var img = new Array();
var speed_ms = 10;
var speed_px;
var table_num = 0;
var table_change_interval;
var table_hover = 0;

function getAbsolutePos(el)
{
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent)
	{
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

var image_change = function(image_i) 
{
	var image = img[image_i];
	var width = parseInt(image.style.width) + image.speed;
	
	if (width <= width_min) 
	{
		width = width_min;
		image.style.position = 'static';
		image.style.zIndex = 1;
	} 
	else if (width > width_max) 
	{
		width = width_max;
	} 
	else 
	{
		image.style.position = 'absolute';
	}
	
	image.style.width = width + 'px';
	image.style.height = width + 'px';

	var block = document.getElementById('visitweb_block' + table_num);
	var newpos_x = image.center_x - Math.round(width/2);
	var newpos_y = image.center_y - Math.round(width/2);
	
	if (block.clientWidth < newpos_x + width)
		newpos_x = block.clientWidth - width;
	if (block.clientHeight < newpos_y + width)
		newpos_y = block.clientHeight - width;		
	if (newpos_x < block.clientLeft) 
		newpos_x = block.clientLeft;
	if (newpos_y < block.clientTop) 
		newpos_y = block.clientTop;
		
	image.style.left = newpos_x + 'px';
	image.style.top = newpos_y + 'px';			

	if (width == width_min || width == width_max)
		clearInterval(image.interval);
}

var table_change = function() 
{
	if (table_hover == 0)
	{
		table_num++;
		table_num %= tables;
		
		for (i = 0; i < tables; i++) 
		{
			table = document.getElementById('visitweb_block' + i);
			if (i == table_num)
			{
				table.style.display = '';
			}
			else
			{
				table.style.display = 'none';
			}
		}
	}
}

window.onload = function()
{
	if (tables > 1)
		table_change_interval = setInterval("table_change()", rotate_delay);
	
	if (zoom_enable)
	{
		var i; 
		img = document.getElementsByTagName('img');
		for (i = 0; i < img.length; i++) 
		{
			img[i].xi = i;		
			
			width_min = img[i%colsrows].clientWidth;
			img[i].center_x = getAbsolutePos(img[i%colsrows]).x + Math.round(width_min/2);
			img[i].center_y = getAbsolutePos(img[i%colsrows]).y + Math.round(width_min/2);
			img[i].style.width = width_min + 'px';
			img[i].style.height = width_min + 'px';
			
			img[i].onmouseover = function() 
			{
				this.style.zIndex = 100;	
				this.speed = speed_px;			
				if (this.interval) clearInterval(this.interval);
				this.interval = setInterval("image_change("+this.xi+")", speed_ms);
			};
			img[i].onmouseout = function() 
			{
				this.speed = -speed_px;
				if (this.interval) clearInterval(this.interval);
				this.interval = setInterval("image_change("+this.xi+")", speed_ms);
			};
		}			
		speed_px = Math.round((width_max-width_min)/5);
	}
}

