/* $Id: bounce.js,v 1.1 2002/10/02 18:49:42 shaggy Exp $ */

/*
Copyright (c) 2001, 2002 by Martin Tsachev. All rights reserved.
http://www.mt-dev.com

This script uses JavaScript library functions by Peter-Paul Koch
http://www.xs4all.nl/~ppk/

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the conditions available at
http://www.opensource.org/licenses/bsd-license.html
are met.
*/


// getObj function by Peter-Paul Koch
function getObj(name, parLyr) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else
	if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else
	if (document.layers) {
		if ( !parLyr ) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		} else {
			this.obj = document.layers[parLyr].document.layers[name];
			this.style = document.layers[parLyr].document.layers[name];
		}
	}
}


var posTop = 200;
var posLeft = 250;
var chV = 3;
var chH = 3;
var maxTop = 500;
var minTop = 200;
var maxLeft = 550;
var minLeft = 250;


function calculateChange() {
	now = new Date()
	if ( posTop > maxTop ) {
		chV = -( Math.floor( Math.random() * 10 ) );
	} else {
	if ( posTop < minTop ) {
		chV = +( Math.floor( Math.random() * 10 ) );
	} else {
		chV +=  Math.floor( Math.random() * 5 ) -2;
	}
	}

	if ( posLeft > maxLeft ) {
		chH = -( Math.floor( Math.random() * 10 ) );
	} else {
	if ( posLeft < minLeft ) {
		chH = +( Math.floor( Math.random() * 10 ) );
	} else {
		chH +=  Math.floor( Math.random() * 5 ) - 2;
	}
	}
}


function startBounce() {
	if ( document.all || document.getElementById || document.layers ) {
		bounceText = new getObj('bouncer');
		posTop += chV;
		posLeft += chH;
		calculateChange();
		bounceText.style.left = posLeft;
		bounceText.style.top = posTop;
		setTimeout("startBounce()", 30);
	}
}
