/**
* Version1.2:	Added functionality for netscape 6.
*/

/**
* suggest at:	yogeshsarang@indiatimes.com
*/

/**
* object impementation for showing Marquee.
*
* Name		:	XMarquee.
* Date		:	Wednesday,July 24,2001.
* Author	:	Yogesh Sarang.
* Company	:	Infoseek India Pvt. Ltd.
*
* Method Summary
*	Parameterized Constructor	: no return.
*		Parameter summary
*			name					: type string.
*				Its name of instance which holds the object of XMarquee.
*			x						: type int.
*				Its left position of marquee.
*			y						: type int.
*				Its top position of marquee.
*			width					: type int.
*				Its width of marquee area.
*			height					: type int.
*				Its height of marquee area.
*			text					: type string.
*				Its content of marquee.
*		Asigns default values to member veriables & writes DHTML code for Marquee.
*	scrollit					: no return.
*		It is currently used for Netscape4.X only to scroll layer for marquee.
*	setX						: no return.
*		It sets the left position of marquee area.
*	setY						: no return.
*		It sets the top position of marquee area.
*	setHeight					: no return.
*		It sets the height of marquee area.
*	setWidth					: no return.
*		It sets the width of marquee area.
*	setText						: no return.
*		It sets the text to be scrolled in marquee.
* Variable Summary
*	name				: type string.
*		Its name of the object used for multiple instances of XMarquee.
*		Should be different for every instance.
*	scrollFlag			: type boolean.
*		Its indicator if marquee should be scrolled or not.
*/
function XMarquee(name,x,y,width,height,text)
{
	this.name=name;
	this.scrollAmount=2;
	this.scrollDelay=50;
	this.scrollFlag=true;
	this.scrollit=scrollit;
	this.setText=settext;
	this.setWidth=setwidth;
	this.setHeight=setheight;
	this.setX=setx;
	this.setY=sety;
	
	if(document.layers)
		document.write("<layer clip=0,0,"+width+","+height+" z-index=0 left="+x+" top="+y+" name=XMarquee_"+name+"_frame  onmouseover='"+name+".scrollFlag=false'  onmouseout='"+name+".scrollFlag=true;'><layer name=XMarquee_"+name+"_doc width=3000>"+text+"</layer></layer>");
	else if(document.all)
		document.write("<div id='XMarquee_"+name+"_frame' name='XMarquee_"+name+"_frame' style='position:absolute;visibility:show;left:"+x+";top:"+y+";width:"+width+";height:"+height+"'><marquee name='XMarquee_"+name+"_doc' id='XMarquee_"+name+"_doc' onmouseover='this.stop()' onmouseout='this.start()' scrollamount="+this.scrollAmount+" scrolldelay="+this.scrollDelay+">"+text+"</marquee></div>");
	else if(document.getElementById)
		document.write("<div id='XMarquee_"+name+"_frame' name='XMarquee_"+name+"_frame' style='position:absolute;visibility:show;left:"+x+";top:"+y+";clip:rect(0 "+width+" "+height+" 0)'><div name='XMarquee_"+name+"_doc' id='XMarquee_"+name+"_doc' style='position:absolute;visibility:show;left:0;top:0'>"+text+"</div></div>");
}

/**
* implementation of scrollit for XMarquee object.
*/
function scrollit()
{
	if(document.layers || (document.getElementById && !document.all))
	{
		if(this.scrollFlag)
		// if layer should be scrolled.
		{
			// scroll the document layer by scrollAmount.
			if(document.layers)
			{
				divobj=document.layers["XMarquee_"+this.name+"_frame"].document.layers["XMarquee_"+this.name+"_doc"];
				if(divobj.left>=divobj.document.width*(-1))
					divobj.left-=this.scrollAmount;
				else
				{
					frameobj=document.layers["XMarquee_"+this.name+"_frame"];
					divobj.left=frameobj.clip.width;
				}
			}
			else if(document.getElementById)
			{
				divobj=document.getElementById("XMarquee_"+this.name+"_doc");

				if(parseInt(divobj.style.left)>=parseInt(divobj.offsetWidth)*(-1))
					divobj.style.left=(parseInt(divobj.style.left)-this.scrollAmount)+"pt";
				else
				{
					frameobj=document.getElementById("XMarquee_"+this.name+"_frame");
					divobj.style.left=parseInt(frameobj.style.clip.substring(frameobj.style.clip.indexOf(" ")+1,frameobj.style.clip.length))+"pt";
				}
			}
		}

		// iterate through scrollit after every 100ms.
		setTimeout(this.name+".scrollit()",this.scrollDelay);
	}
}

/**
* implementation of setText for XMarquee object.
* Parameter summary
*	text			: type int.
*		Its text to be displayed in marquee area.
*/
function settext(text)
{
	if(document.layers)
	{
		obj=document.layers["document.XMarquee_"+this.name+"_frame"].document.layers["XMarquee_"+this.name+"_doc.document"];
		obj.write(text);
		obj.close();
	}
	else if(document.all)
	{
		obj=document.all["XMarquee_"+this.name+"_doc"];
		obj.innerHTML=text;
	}
	else if(document.getElementById)
	{
		obj=document.getElementById("XMarquee_"+this.name+"_doc");
		obj.innerHTML=text;
	}
}

/**
* implementation of setWidth for XMarquee object.
* Parameter summary
*	width				: type int.
*		Its width of marquee area.
*/
function setwidth(width)
{
	if(document.layers)
	{
		obj=eval("document.XMarquee_"+this.name+"_frame");
		obj.clip.width=width;
	}
	else if(document.all)
	{
		obj=eval("XMarquee_"+this.name+"_frame");
		obj.style.width=width;
	}
	else if(document.getElementById)
	{
		obj=document.getElementById("XMarquee_"+this.name+"_frame");
		obj.style.width=width;
		obj.style.clip="rect(0 "+width+" "+parseInt(obj.style.clip.substring(obj.style.clip.indexOf(" ",obj.style.clip.indexOf(" ")+1)+1,obj.style.clip.length))+" 0)";
	}
}

/**
* implementation of setHeight for XMarquee object.
* Parameter summary
*	height				: type int.
*		Its height of marquee area.
*/
function setheight(height)
{
	if(document.layers)
	{
		obj=document.layers["document.XMarquee_"+this.name+"_frame"];
		obj.clip.height=height;
	}
	else if(document.all)
	{
		obj=document.all["XMarquee_"+this.name+"_frame"];
		obj.style.height=height;
	}
	else if(document.getElementById)
	{
		obj=document.getElementById("XMarquee_"+this.name+"_frame");
		obj.style.height=height;
		obj.style.clip="rect(0 "+parseInt(obj.style.clip.substring(obj.style.clip.indexOf(" ")+1,obj.style.clip.length))+" "+height+" 0)";
	}
}

/**
* implementation of setX for XMarquee object.
* Parameter summary
*	x					: type int.
*		Its left position of marquee.
*/
function setx(x)
{
	if(document.layers)
	{
		obj=document.layers["XMarquee_"+this.name+"_frame"];
		obj.left=x;
	}
	else if(document.all)
	{
		obj=document.all["XMarquee_"+this.name+"_frame"];
		obj.style.left=x;
	}
	else if(document.getElementById)
	{
		obj=document.getElementById("XMarquee_"+this.name+"_frame");
		obj.style.left=x;
	}
}

/**
* implementation of setY for XMarquee object.
* Parameter summary
*	y					: type int.
*		Its top position of marquee.
*/
function sety(y)
{
	if(document.layers)
	{
		obj=document.layers["document.XMarquee_"+this.name+"_frame"];
		obj.top=y;
	}
	else if(document.all)
	{
		obj=document.all["XMarquee_"+this.name+"_frame"];
		obj.style.top=y;
	}
	else if(document.getElementById)
	{
		obj=document.getElementById("XMarquee_"+this.name+"_frame");
		obj.style.top=y;
	}
}
