var myMarquee = function(){}

myMarquee.prototype = {
	parentElm	: null,
	childElm	: null,
	intId		: null,
	doScroll	: 1,
	
	marqueeType	: 1,	// 1 = horizontal, 2 = vertical
	
	moveOffset	: 1,	// in pixels
	
	Create	: function(parentElm, marq)		// parent elemnt & a marque text (or a marquee element)
	{
		if (typeof(parentElm) == 'undefined') return false;
		this.parentElm = parentElm;
		parentElm.style.position = 'relative';
		var w = parseInt(parentElm.style.width)?parseInt(parentElm.style.width):parentElm.offsetWidth;
		var h = parseInt(parentElm.style.height)?parseInt(parentElm.style.height):parentElm.offsetHeight;
		
		parentElm.style.overflow = 'hidden';
		
		if (typeof(marq) == 'string') // Create a node
		{			
			var tmp = document.createElement('div');
			tmp.style.position	= 'absolute';
			this.childElm = tmp;
			parentElm.appendChild(tmp);
			tmp.innerHTML		= marq;
			if (this.marqueeType == 1) { 
				tmp.innerHTML = '<nobr>' + tmp.innerHTML + '</nobr>';
				tmp.style.width = parseInt(tmp.offsetWidth)+'px';
				tmp.style.left = w+'px';
				tmp.style.top  = 3+'px';
			}
			if (this.marqueeType == 2) { 
				tmp.style.width = (w-4)+'px'; 
				tmp.style.height = parseInt(tmp.offsetHeight)+'px'; 
				tmp.style.top  = h+'px'; 
				tmp.style.left = '0px';
			}		
		}
		else			// Marquee div already exists
		{
			marq.style.position	= 'absolute';
			if (this.marqueeType == 1) { 
				marq.innerHTML = '<nobr>' + marq.innerHTML + '</nobr>';
				marq.style.width = parseInt(marq.offsetWidth)+'px';
				tmp.style.left = w+'px';
				tmp.style.top  = 3+'px';
			}
			if (this.marqueeType == 2) { 
				marq.style.width = (w-4)+'px'; 
				marq.style.height = parseInt(marq.offsetHeight)+'px'; 
				marq.style.top  = h+'px'; 
				marq.style.left = '0px';
			}
			this.childElm	= marq;
		}
		return true;
	},
	
	Move	: function(cls)
	{
		
		if (!cls.doScroll) return true;
		var xPos = parseInt(cls.childElm.style.left);
		var yPos = parseInt(cls.childElm.style.top);
		
		var w	= parseInt(cls.childElm.style.width);
		var h	= parseInt(cls.childElm.style.height);
		
		var w1 = parseInt(cls.parentElm.style.width)?parseInt(cls.parentElm.style.width):cls.parentElm.offsetWidth;
		var h1 = parseInt(cls.parentElm.style.height)?parseInt(cls.parentElm.style.height):cls.parentElm.offsetHeight;
		
		if (cls.marqueeType == 1)
		{
			if ((xPos+w) <= 0) cls.childElm.style.left = w1+'px';
			else
			{
				xPos -= cls.moveOffset;
				cls.childElm.style.left = xPos + 'px';
			}
		}
		
		if (cls.marqueeType == 2)
		{
			if ((yPos+h) <= 0) cls.childElm.style.top = h1+'px';
			else
			{
				yPos -= cls.moveOffset; 
				cls.childElm.style.top = yPos + 'px';
			}
		}
		//alert(cls.Create);	
	}

}

var Marq = new myMarquee();

