var tictacWidth = 55;
var tictacHeight = 55;
var TictacSpeed = 1;
var stopafter=0;

var xMax;
var yMax;
var xPos = 0;
var yPos = 0;
var xDir = 'right';
var yDir = 'down';
var supertictacRunning = true;
var tempTictacSpeed;
var currentTictacSrc;
var newXDir;
var newYDir;

function stopit(){
    clearTimeout(doit)
    if (document.getElementById)
	document.getElementById("supertictac").style.visibility="hidden"
    else if (document.all)
	document.all("supertictac").style.visibility = "hidden";
    else
    document.layers["supertictac"].visibility = "hide";
}

function initializeTictac() {
	xMax = document.body.clientWidth;
	yMax = document.body.clientHeight-4;

	// php nastavi vychozi pozici
        if (document.all) {
	    xPos = parseInt( document.all("supertictac").style.left )
	    yPos = parseInt( document.all("supertictac").style.top )
        }
	else if (document.layers) {
	    xPos = parseInt( document.layers["supertictac"].left )
	    yPos = parseInt( document.layers["supertictac"].top )
        }
	else if (document.getElementById) {
	    xPos = parseInt( document.getElementById("supertictac").style.left )
	    yPos = parseInt( document.getElementById("supertictac").style.top )
        }

    setTimeout('moveTictac()',400);
    if (stopafter>0)
	setTimeout("stopit()",stopafter*1000)
}


function moveTictac() {
    if (supertictacRunning == true) {
	calculatePosition();
	//alert(xPos,yPos);
        if (document.all) {
	    document.all("supertictac").style.left = xPos + document.body.scrollLeft;
	    document.all("supertictac").style.top = yPos + document.body.scrollTop;
        }
	else if (document.layers) {
	    document.layers["supertictac"].left = xPos + pageXOffset;
	    document.layers["supertictac"].top = yPos + pageYOffset;
        }
	else if (document.getElementById) {
	    document.getElementById("supertictac").style.left = xPos + pageXOffset;
	    document.getElementById("supertictac").style.top = yPos + pageYOffset;
        }
	doit=setTimeout('moveTictac()',30);
    }
}

function calculatePosition() {
    if (xDir == "right") {
	if (xPos > (xMax - tictacWidth - TictacSpeed)) {
	    xDir = "left";
	}
    }
    else if (xDir == "left") {
	if (xPos < (0 + TictacSpeed)) {
	    xDir = "right";
	}
    }

    if (yDir == "down") {
	if (yPos > (yMax - tictacHeight - TictacSpeed)) {
	    yDir = "up";
	}
    }
    else if (yDir == "up") {
	if (yPos < (0 + TictacSpeed)) {
	    yDir = "down";
	}
    }

    if (xDir == "right") {
	xPos = xPos + TictacSpeed;
    }
    else if (xDir == "left") {
	xPos = xPos - TictacSpeed;
    }
    else {
	xPos = xPos;
    }

    if (yDir == "down") {
	yPos = yPos + TictacSpeed;
    }
    else if (yDir == "up") {
	yPos = yPos - TictacSpeed;
    }
    else {
	yPos = yPos;
    }
}

if (document.all||document.layers||document.getElementById){
    window.onload = initializeTictac;
    window.onresize = new Function("window.location.reload()");
}

