var rot_DEF_count_msg = 4;
var rot_DEF_timeout = 300;
var rot_msg = 1;
var rot_timeout = rot_DEF_timeout;
var rot_phase = 0;
var rot_direction = +1;
var rot_stop = 0;

function rotate() {
	if (rot_stop) return;

	if (rot_timeout > 0) {
		rot_timeout--;
	} else {
		rot_phase += (Math.ceil(rot_phase / 10)+1) * rot_direction;
		if (rot_direction > 0 && rot_phase > 3000) {
			rot_msg++;
			if (rot_msg > rot_DEF_count_msg) rot_msg -= rot_DEF_count_msg;
			document.getElementById("rot").innerHTML = document.getElementById("rot-"+ rot_msg).innerHTML;
			rot_direction = -1;
		}
		if (rot_direction < 0 && rot_phase < 1) {
			rot_direction = +1;
			rot_phase = 0;
			rot_timeout = rot_DEF_timeout;
		}
		document.getElementById("rot-me").style.left = rot_phase +"px";
	}

//	self.status = rot_timeout +" - "+ rot_phase +" * "+ rot_direction;	
	if (rot_phase > 0) window.setTimeout("rotate()", 10);
	else window.setTimeout("rotate()", 100);
}

onload = rotate;