$(document).ready(function() {

	var int, left, left_target, fullstop, nstop;
	var stopstr = "sorry no time to rest ..";

	init_on_move();

	function init_on_move() {
		left = $(document).width() + 10;
		left_target = ($(document).width() - $('#msg').innerWidth()) / 2;
		fullstop = "";
		nstop = 0;
		$('#msg').css({left:left});
		$('p').text(fullstop).fadeIn(10);
		$('p').css({left:left_target});
		int = setInterval(bring_text_in, 10);
	}

	function bring_text_in() {
		left -= 4;
		$('#msg').css({left:left});
		if (left <= left_target) {
			clearInterval(int);
			int = setInterval(cant_stop, 100);
		}
	}

	function cant_stop() {
		fullstop += stopstr[nstop];
		$('p').text(fullstop);
		if (++nstop >= stopstr.length) {
			clearInterval(int);
			int = setInterval(start_take_text_out, 1600);
			$('p').fadeOut(1600);
		}
	}

	function start_take_text_out() {
		clearInterval(int);
		int = setInterval(take_text_out, 10);
	}

	function take_text_out() {
		left -= 4;
		$('#msg').css({left:left});
		if (left <= -1000) {
			clearInterval(int);
			setTimeout(init_on_move, 4000);
		}
	}
});

