// variable for timer
var timer;
var clkset;

function speed(setting)
{
	clkset = setting;
	return clkset;
}	


function left()
{
	var obj = document.getElementById("lyr");

	obj.style.left = (parseInt(obj.style.left)-1)+"px";

	timer = window.setTimeout("left()", clkset);

	if(parseInt(obj.style.left) < 0) {stop()};
}

function right()
{
	var obj = document.getElementById("lyr");

	obj.style.left = (parseInt(obj.style.left)+1)+"px";
	
	timer =	window.setTimeout("right()",clkset);     

	if(parseInt(obj.style.left) > 550) {stop()};
}

function up()
{
	var obj = document.getElementById("lyr");

	obj.style.top = (parseInt(obj.style.top)-1)+"px";

	timer = window.setTimeout("up()", clkset);

	if(parseInt(obj.style.top) < 0) {stop()};
}

function down()
{
	var obj = document.getElementById("lyr");

	obj.style.top = (parseInt(obj.style.top)+1)+"px";

	timer = window.setTimeout("down()", clkset);

	if(parseInt(obj.style.top) > 175) {stop()};
}

function dupright()
{
	var obj = document.getElementById("lyr");

	obj.style.top = (parseInt(obj.style.top)-1)+"px";
	obj.style.left = (parseInt(obj.style.left)+1)+"px";

	timer = window.setTimeout("dupright()", clkset);

	if(parseInt(obj.style.top) < 0) {stop()};
	if(parseInt(obj.style.left) > 550) {stop()};
}

function dupleft()
{
	var obj = document.getElementById("lyr");

	obj.style.top = (parseInt(obj.style.top)-1)+"px";
	obj.style.left = (parseInt(obj.style.left)-1)+"px";

	timer = window.setTimeout("dupleft()", clkset);

	if(parseInt(obj.style.top) < 0) {stop()};
	if(parseInt(obj.style.left) < 0) {stop()};
}

function ddownleft()
{
	var obj = document.getElementById("lyr");

	obj.style.top = (parseInt(obj.style.top)+1)+"px";
	obj.style.left = (parseInt(obj.style.left)-1)+"px";

	timer = window.setTimeout("ddownleft()", clkset);

	if(parseInt(obj.style.top) > 175) {stop()};
	if(parseInt(obj.style.left) < 0) {stop()};
}

function ddownright()
{
	var obj = document.getElementById("lyr");

	obj.style.top = (parseInt(obj.style.top)+1)+"px";
	obj.style.left = (parseInt(obj.style.left)+1)+"px";

	timer = window.setTimeout("ddownright()", clkset);

	if(parseInt(obj.style.top) > 175) {stop()};
	if(parseInt(obj.style.left) > 550) {stop()};
}

function square()
{
	var obj = document.getElementById("lyr");

	obj.style.left = (parseInt(obj.style.left)+1)+"px";
	if(parseInt(obj.style.left) > 300) {sd()};
	timer = window.setTimeout("square()", clkset);
	end;
}

function sd()
{
	var obj = document.getElementById("lyr");

	obj.style.top = (parseInt(obj.style.top)+1)+"px";
	if(parseInt(obj.style.top) > 175) {sl()};
	timer = window.setTimeout("sd()", clkset);
	end;
}
function sl()
{
	var obj = document.getElementById("lyr");

	obj.style.left = (parseInt(obj.style.left)-1)+"px";
	if(parseInt(obj.style.left) < 0) {su()};
	timer = window.setTimeout("sl()", clkset);
	end;
}
function su()
{
	var obj = document.getElementById("lyr");

	obj.style.top = (parseInt(obj.style.top)-1)+"px";
	if(parseInt(obj.style.top) < 0) {square()};
	timer = window.setTimeout("su()", clkset);
	end;
}

function stop()
{
	clearTimeout(timer)
}