var navigatorObject=self.navigator;
var disect=/\w[a-z|.|0-9]{1,20}/
var BrowserName=(""+navigatorObject.appName.match(disect)).toLowerCase();
var BrowserVersion=parseInt(navigatorObject.appVersion.match(disect));
var IE4=false;
var NS4=false;
var NS6=false;
if (BrowserName=="microsoft") IE4=true;
if (BrowserName=="netscape"&&BrowserVersion<5) NS4=true;
if (BrowserName=="netscape"&&BrowserVersion>=5) NS6=true;
var BoxStack=new Object();
var BoxCount=0;
var BoxesInitialized=0;

// Main object
// Instance is created with 2 options
// image name, background color   or
// x,y,width,height, backgroundcolor
// isClip draws the layer for scrolling
// the object contains the following methods:
// show()
// hide()
// setText(sText)
// divMove() after you change x or y
// divResize() after you change width or height
// the properties are Read/Write

function dynamicText(xPos,yPos,TextWidth,TextHeight,BackgroundColor)
{
	if (""+typeof(xPos)!="number")
	{
		this.x=1;
		this.y=1;
		this.width=1;
		this.height=1;
		this.bgColor=yPos;
		this.Boxname="TextBox"+xPos;
		this.RelativePos = xPos;
	} else {
		this.x=xPos;
		this.y=yPos;
		this.width=TextWidth;
		this.height=TextHeight;
		this.bgColor=BackgroundColor;
		this.Boxname="TextBox"+this.x+this.y

	}
    this.setText=setText;
	this.divPlace=divPlace;
    this.divMove=divMove;
    this.divResize=divResize;
	this.text="";
    this.Hide=Hide;
    this.Show=Show;
    this.visibility=true;
    this.readyState=false;
	this.wraper = ""
	this.isClip=false;
	this.Clip = "";
	this.ClipHeight = 0;
	this.ClipWidth = 0;
	BoxStack[BoxCount++]=this;

	// function to create layers
	if (IE4||NS6)
	{
		divPreText="<div style='position:relative' id='"
		divPostText="</div>"
document.write("<div id='"+this.Boxname+"' style='position:absolute;left:"+this.x+";top:"+this.y+";height:"+this.height+";width:"+this.width+";background-color:"+this.bgColor+";overflow : hidden;'></DIV>")
		if (IE4)
		{
			this.wraper = document.all[this.Boxname];
		} else
		{
			this.wraper = document.getElementById(this.Boxname);
		}
	}
	if (NS4)
	{
		divPreText="<layer id='";
		divPostText="</layer>";
		window.document.write("<layer id='"+this.Boxname+"' left="+this.x+" top="+this.y+" clip='0,0,"+this.width+","+this.height+"' visibility=show bgcolor="+this.bgColor+"></layer>");
		this.wraper = document.layers[this.Boxname];
	}

}

// Change text after onload
function setText(TextToWrite)
{
	if (this.isClip)
	{
		TextToWrite = divPreText+
				this.Boxname+"_clip' name='"+this.Boxname+"_clip'>"+
				TextToWrite+
				divPostText;
	}
	this.text=TextToWrite
	if (IE4)
	{
		document.all[this.Boxname].innerHTML=this.text;
		if (this.isClip)
		{
			this.Clip = document.all[this.Boxname+"_clip"].style;
			this.ClipHeight = document.all[this.Boxname+"_clip"].offsetHeight;
			this.ClipWidth = document.all[this.Boxname+"_clip"].offsetWidth;
		}
	}
	if (NS4)
	{
		document[this.Boxname].document.open();
		document[this.Boxname].document.write(this.text);
		document[this.Boxname].document.close();
		if (this.isClip)
		{
			this.wraper = this.Clip = document.layers[this.Boxname].layers[this.Boxname+"_clip"];
			this.ClipHeight = this.wraper.document.height;
			this.ClipWidth = this.wraper.document.width;
		}
	}
	if (NS6)
	{
		document.getElementById(this.Boxname).innerHTML=this.text;
		if (this.isClip)
		{
			this.Clip = document.getElementById(this.Boxname+"_clip").style;
			this.ClipHeight = document.getElementById(this.Boxname+"_clip").offsetHeight;
			this.ClipWidth = document.getElementById(this.Boxname+"_clip").offsetWidth;
		}
	}
	if (this.isClip) {
		this.Clip.top=0;
		this.Clip.left=0;
	}
}
// Internal method
function divPlace()
{
	imageToRelate=""+this.Boxname.substring(7,this.Boxname.length)
	if (IE4||NS6)
	{
		imageX=document.images[imageToRelate].offsetLeft;
		imageY=document.images[imageToRelate].offsetTop;
	} else
	{
		imageX=document.images[imageToRelate].x;
		imageY=document.images[imageToRelate].y;
	}
	imageWidth=document.images[imageToRelate].width;
	imageHeight=document.images[imageToRelate].height;

	this.x=imageX;
	this.y=imageY;
	this.width = imageWidth;
	this.height = imageHeight;
	this.divMove();
	this.divResize();
}
// Move layer after onload
function divMove()
{
	if (NS4)
	{
		document[this.Boxname].x=this.x;
		document[this.Boxname].y=this.y;
	}
	if (IE4)
	{
		document.all[this.Boxname].style.left=this.x;
		document.all[this.Boxname].style.top=this.y;
	}
	if (NS6)
	{
		document.getElementById(this.Boxname).style.left=this.x;
		document.getElementById(this.Boxname).style.top=this.y;
	}
}
// Resize layer after onload
function divResize()
{
	if (NS4)
	{
		document[this.Boxname].clip.width=this.width;
		document[this.Boxname].clip.height=this.height;
	}
	if (IE4)
	{
		document.all[this.Boxname].style.width=this.width;
		document.all[this.Boxname].style.height=this.height;
	}
	if (NS6)
	{
		document.getElementById(this.Boxname).style.width=this.width;
		document.getElementById(this.Boxname).style.height=this.height;
	}
}

function Show(){
    if (NS4)
	{
	document[this.Boxname].visibility="show";
	}
	if (IE4)
	{
	document.all[this.Boxname].style.visibility="visible";
	}
	if (NS6)
	{
	document.getElementById(this.Boxname).style.visibility="visible";
	}
    this.visibility=true;
}
function Hide(){
    if (NS4)
	{
	document[this.Boxname].visibility="hide";
	}
	if (IE4)
	{
	document.all[this.Boxname].style.visibility="hidden";
	}
	if (NS6)
	{
	document.getElementById(this.Boxname).style.visibility="hidden";
	}
    this.visibility=false;
}

//if (""+window.onload=="undefined"||""+window.onload=="null")
//window.onload=drawTextBoxes;
// ******************************************************* //
// ** This method MUST!! be implemented in the using code  //
// ******************************************************* //
function drawTextBoxes()
{
	 for (i=BoxesInitialized;i<BoxCount;i++)
	 {
	 	BoxStack[i].setText(BoxStack[i].text);
		if (BoxStack[i].x==BoxStack[i].width)
		{
			BoxStack[i].divPlace(BoxStack[i].text);
		}

	}
	BoxesInitialized = i;
}