function get_object(name) {

	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else if (document.layers) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

function get_top_position(object) {

	var current_top = 0;

	if (document.getElementById || document.all) {
		while (object.offsetParent) {
			current_top += object.offsetTop;
			object = object.offsetParent;
		}
	} else if (document.layers) current_top += object.y;

	return current_top;
}

function get_left_position(object) {

	var current_left = 0;

	if (document.getElementById || document.all) {
		while (object.offsetParent) {
			current_left += object.offsetLeft;
			object = object.offsetParent;
		}
	} else if (document.layers) current_left += object.x;

	return current_left;
}


function init_layers() {

	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;

	window_dimensions();
	width = window_width; 

	for (i = 0; i < n; ++i) {
		scroll_layers[i] = new get_object("scroll_" + (i + 1));

		scroll_left[i] = get_left_position(scroll_layers[i].obj);
		scroll_top[i] = get_top_position(scroll_layers[i].obj);

		if (document.layers) {
			scroll_layers[i].style.clip.left = 0;
			scroll_layers[i].style.clip.right = width;
			scroll_layers[i].style.clip.top = 0;
			scroll_layers[i].style.clip.bottom = height;
		} else {
			scroll_layers[i].style.clip = "rect(0 " + width + " " + height + " 0)";
		}

		scroll_height[i] -= height;
		scroll_width[i] -= width;
	}
	position_layers(0, 0);

	if (document.layers) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = mouse_xy;
}

function position_layers(mouse_x, mouse_y) {

	for (i = 0; i < n; ++i) {
		x = mouse_x * scroll_width[i] / window_width;
		y = mouse_y * scroll_height[i] / window_height;

//		scroll_layers[i].style.left = -x;
//		scroll_layers[i].style.top = -y;
		scroll_layers[i].style.left = scroll_left[i] - x;
		scroll_layers[i].style.top = scroll_top[i] - y;

		if (document.layers) {
			scroll_layers[i].style.clip.left = x;
			scroll_layers[i].style.clip.right = x + width;
			scroll_layers[i].style.clip.top = y;
			scroll_layers[i].style.clip.bottom = y + height;
		} else {
			scroll_layers[i].style.clip = "rect(" + (y + 1) + " " + (x + width) + " " + (y + height + 1) + " " + x + ")";
		}
	}
}


function mouse_xy(e) {

	if (!e) var e = window.event;

	if (e.clientX || e.clientY) {
		mouse_x = e.clientX;
		mouse_y = e.clientY;
	} else if (e.pageX || e.pageY) {
		mouse_x = e.pageX;
		mouse_y = e.pageY;
	}
	position_layers(mouse_x, mouse_y);
}


function window_dimensions() {

	if (window.innerWidth) {
		window_width = window.innerWidth;
		window_height = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		window_width = document.documentElement.clientWidth;
		window_height = document.documentElement.clientHeight;
	} else if (document.body) {
		window_width = document.body.clientWidth;
		window_height = document.body.clientHeight;
	}
}
