var secs
var timerID = null
var timerRunning = false
var delay = 1000


// kies getal binnen 45 seconden
function get_random()
		{
			var ranNum= Math.round(Math.random()*45);
			return ranNum;
		}

function InitializeTimer2()
{
    // hoeveel seconden moet ie wachten voor de functie
    secs = get_random()
    StopTheClock()
    StartTheTimer()
	secs2 = 9
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        self.status = ""
        // DOE ACTIE!
		//alert(document.body.clientWidth);
		//alert(document.body.clientHeight);
		popup();
		moveIt(document.getElementById('popup'),randomHeight(),randomWidth());
        showLayer("popup");
		hideTimer();
		background();
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

function hideTimer()
{
    if (secs2==0)
    {
        StopTheClock()
        self.status = ""
        // DOE ACTIE!
        hideLayer("popup");
		InitializeTimer2();
    }
    else
    {
        self.status = secs2
        secs2 = secs2 - 1
        timerRunning = true
        timerID = self.setTimeout("hideTimer()", delay)
    }
}

function randomWidth(){
	if(document.all)
		{
			w = document.body.clientWidth - 350;
		}
	else
		{
			w = innerWidth - 350;
		}
		var ranNum= Math.round(Math.random()*w);
		return ranNum;
}

function randomHeight(){
	if(document.all)
	{
		 h = document.body.clientHeight - 350;
	}
	else
	{
		 h = innerHeight - 350;
	}
		var ranNum= Math.round(Math.random()*h);
		return ranNum;
}

function moveIt(obj, mvTop, mvLeft) {
	obj.style.position = "absolute";
	obj.style.top = mvTop;
	obj.style.left = mvLeft;
}