function swap(id,img) {
	document.getElementById(id).src = img;
	return true;
}

var loop = false;

function startLoop(id, direction) {
	loop = true;
	loopMe(id, direction);
}

function endLoop() {
	loop = false;
}

function loopMe(id, direction) {
	if (!loop) { return; }

	scroll(id, direction);

	setTimeout("loopMe('"+id+"', '"+direction+"')", 50);
}

function scroll(id, direction) {
	var content = document.getElementById(id);
	var height = document.getElementById(id).offsetHeight - content.parentNode.offsetHeight + 10;
	var width = document.getElementById(id).offsetWidth - content.parentNode.offsetWidth;

	// Horizontal scrolling
	if (direction == 'up' || direction == 'down') {
		var top_string = content.style.top;
		var top_broken = top_string.split("px");

		// Up
		if (direction == 'up') {
			// the division by 1 is necessary to force numerical evaluation (stupid javascript)
			var top_new = ((top_broken[0] / 1) + 30);
			if (top_new > 0) {
				top_new = 0;
			}

		// Down
		} else {
			var top_new = ((top_broken[0] / 1) - 30);
			if (top_new < (0 - height)) {
				top_new = (0 - height);
			}
		}

		top_new = top_new + "px";

		content.style.top = top_new;

	// Vertical scrolling
	} else {
		var left_string = content.style.left;
		var left_broken = left_string.split("px");

		// Left
		if (direction == 'left') {
			// the division by 1 is necessary to force numerical evaluation (stupid javascript)
			var left_new = ((left_broken[0] / 1) + 5);
			if (left_new > 0) {
				left_new = 0;
			}

		// Right
		} else {
			var left_new = ((left_broken[0] / 1) - 5);
			if (left_new < (0 - width)) {
				left_new = (0 - width);
			}
		}
		left_new = left_new + "px";

		content.style.left = left_new;
	}
}


