var Marquee = function(obj, direction, ScrollAmount){//up,left
	var base = this;
	this.obj = typeof(obj)=="string" ? d(obj) : obj;
	this.direction = direction;
	this.amount = NotIsNull(ScrollAmount) ? ScrollAmount : 1;
	this.timer = null;
	this.w = this.getWidth(this.obj) - this.amount;
	this.h = this.getHeight(this.obj) - this.amount;
	if(this.direction == "left"){
		if(this.obj.offsetWidth < (2 * this.w)){
			var s = "<td style='word-break:keep-all;white-space:nowrap;'>" + this.obj.innerHTML + "</td>";
			this.obj.innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr>" + s + s + s + s + s + "</tr></table>";
		}
	}
	else{
		if(this.obj.offsetHeight < (2 * this.h)){
			var s = "<tr><td>" + this.obj.innerHTML + "</tr></td>";
			this.obj.innerHTML = "<table border='0' cellpadding='0' cellspacing='0'>" + s + s + s + s + s + "</table>";
		}
	}
	this.obj.onmouseover = function(){base.stop(base)};
	this.obj.onmouseout =  function(){base.start(base)};
	this.start(base);
}
Marquee.prototype.start = function(base){
	base.timer = setInterval(function(){base.scrolling();},50);
}
Marquee.prototype.stop = function(base){
	clearInterval(base.timer);
}
Marquee.prototype.scrolling = function(){
	if(this.direction == "left"){
		if (this.obj.scrollLeft >= this.w){
			this.obj.scrollLeft = 0;
		}
		else if(this.obj.scrollLeft >= 0){
			this.obj.scrollLeft += this.amount;
		}
	}
	else{
		if (this.obj.scrollTop >= this.h){
			this.obj.scrollTop = 0;
		}
		else if(this.obj.scrollTop >= 0){
			this.obj.scrollTop += this.amount;
		}
	}
}
Marquee.prototype.getHeight = function(obj){
	var d = document.createElement("div");
	d.style.height = "0px";
	d.style.overflow = "hidden";
	d.innerHTML = obj.innerHTML;
	obj.parentNode.appendChild(d);
	var h = d.scrollHeight;
	obj.parentNode.removeChild(d);
	return h;
	//return obj.scrollHeight;
}
Marquee.prototype.getWidth = function(obj){
	var d = document.createElement("div");
	d.style.width = "0px";
	d.style.wordBreak = "keep-all";
	d.style.whiteSpace = "nowrap";
	d.style.overflow = "hidden";
	d.innerHTML = obj.innerHTML;
	obj.parentNode.appendChild(d);
	var w = d.scrollWidth;
	obj.parentNode.removeChild(d);
	return w;
	//return obj.scrollWidth;
}
