﻿function SetupDynamicPromoBox(box, desc, shadow, text, speed, maxHeight) {
	if (typeof (box) == typeof ("")) { box = document.getElementById(box); }
	if (typeof (desc) == typeof ("")) { desc = document.getElementById(desc); }
	if (typeof (shadow) == typeof ("")) { shadow = document.getElementById(shadow); }
	if (typeof (text) == typeof ("")) { text = document.getElementById(text); }
	if (speed == null) { speed = 1; }
	if (maxHeight == null) { maxHeight = 134; }
	speed = ((1 / 1000) / speed) * maxHeight;

	shadow.style.height = text.offsetHeight + "px";
	shadow.style.marginBottom = -text.offsetHeight + "px";
	desc.Speed = speed;
	desc.Offset = 0.00;
	desc.MaxOffset = text.offsetHeight * -1;
	desc.OldTime = new Date();
	box.desc = desc;
	box.Timer = null;
	box.Direction = 0;
	box.desc.ApplyOffset = function() {
		this.style.top = this.Offset + "px";
	}
	box.desc.Move = function() {
		var gapTime = (new Date() - this.OldTime) * 1;
		var end = false;
		this.Offset += ((this.Direction * this.Speed) * gapTime);
		if (this.Offset > 0) { this.Offset = 0; end = true; }
		if (this.Offset < this.MaxOffset) { this.Offset = this.MaxOffset; end = false; }
		this.ApplyOffset();
		this.OldTime = new Date();
		if (!end) { this.Timer = setTimeout("document.getElementById('" + this.id + "').Move();", 20); }
	}
	box.onmouseover = function() {
		this.desc.Direction = -1;
		if (this.Timer == null) {
			box.desc.OldTime = new Date();
			setTimeout("document.getElementById('" + this.desc.id + "').Move();", 20);
		}
	}
	box.onmouseout = function() {
		this.desc.Direction = 1;
		if (this.Timer == null) {
			box.desc.OldTime = new Date();
			setTimeout("document.getElementById('" + this.desc.id + "').Move();", 20);
		}
	}
}
