function scrolling(id)
{
	this.name = id + "Var";
  eval(this.name + " = this");

	this.el = null;
	this.elWidth = 0;
	this.elHeight = 0;
	this.view = null;
	this.viewWidth = 0;
	this.viewHeight = 0;

	this.dx = 0;
	this.dy = 0;

	this.timer = null;

	this.count = 0;

	this.start = start;
	this.stop = stop;
	this.go = go;

	var el = document.getElementById(id);

	if (el != null) {
		this.el = el;
		this.elWidth = Number(this.el.style.width.substr(0, this.el.style.width.length - 2));
		this.elHeight = Number(this.el.style.height.substr(0, this.el.style.height.length - 2));
		this.view = this.el.parentNode;
//		alert(this.view);
		this.viewWidth = Number(this.view.style.width.substr(0, this.view.style.width.length - 2));
		this.viewHeight = Number(this.view.style.height.substr(0, this.view.style.height.length - 2));

//		alert(this.elWidth + ', ' + this.elHeight + '\n' + this.viewWidth + ', ' + this.viewHeight + '\n');

		return this;
	} else {
		return null;
	}
}

function start(dx, dy, interval)
{
	this.dx = dx;
	this.dy = dy;

	this.timer = window.setInterval(this.name + ".go()", interval);
}

function stop()
{
	clearInterval(this.timer);
}

function go()
{
	// HORIZONTAL
	var left = Number(this.el.style.left.substr(0, this.el.style.left.length - 2));
//    var left = 5;
	if ( (this.dx > 0) && (left > this.viewWidth) ) {
		// text vyjel vpravo
		left = -this.elWidth;
	}

	if ( (this.dx < 0) && ((left+this.elWidth) < 0) ) {
		// text vyjel vlevo
		left = this.viewWidth;
		left = 800;
	}

	left += this.dx;
	this.el.style.left = left + 'px';

	// VERTICAL
	var top = Number(this.el.style.top.substr(0, this.el.style.top.length - 2));

	if ( (this.dy > 0) && (top > this.viewHeight) ) {
		// text vyjel dole
		top = -this.elHeight;
	}

	if ( (this.dy < 0) && ((top+this.elHeight) < 0) ) {
		// text vyjel nahore
		top = this.elHeight;
	}

	top += this.dy;
	this.el.style.top = top + 'px';
}


