function PageScrollerObj(ComponentName,
		ComponentWidth, ComponentHeight, Alignment,
		LeftMargin, TopMargin, RightMargin, BottomMargin,
		ScrollSpeed, LoadMsg, LoadMsgColor, LoadMsgSize,
		BkImage, BkAudio, BkColor, BorderSize, BorderColor,
		StatusBarMsg, Mode, arrangement, PageScrollData, StartMute)
{
	this.browser = 0;
	if ( document.all ) this.browser = 1; // IE
	else if ( document.layers ) this.browser = 2; // NS4
	else if ( document.getElementById && !document.all ) this.browser = 3; // NS6
	if ( navigator.userAgent.indexOf("Opera") != -1 ) this.browser = 4; // Opera

	this.name = ComponentName;
	this.ComponentWidth	= ComponentWidth;
	this.ComponentHeight = ComponentHeight;
	this.Alignment = Alignment;
	this.LeftMargin = LeftMargin;
	this.TopMargin = TopMargin;
	this.RightMargin = RightMargin;
	this.BottomMargin = BottomMargin;
	this.swidth = ComponentWidth - LeftMargin - RightMargin;
	if ( this.browser != 3 ) this.swidth -= ( BorderSize + BorderSize );
	this.sheight = ComponentHeight - TopMargin - BottomMargin;
	if ( this.browser != 3 ) this.sheight -= ( BorderSize + BorderSize );
	this.sspeed = ScrollSpeed;
	this.ScrollSpeed = ScrollSpeed;
	this.loadMsg = "<table width="+ComponentWidth+" height="+ComponentHeight+" border=0><TR><TD valign=center align=center><FONT size="+LoadMsgSize+" "+(LoadMsgColor!=""?"color="+LoadMsgColor:"")+"><B>"+LoadMsg+"</B></font></td></tr></table>"
	this.BkImage = BkImage;
	this.BkColor = BkColor;
	this.BorderSize = BorderSize;
	this.BorderColor = BorderColor;
	this.StatusBarMsg = StatusBarMsg;
	this.Mode = Mode;
	this.nGap = (arrangement == 0) ? 0 : this.sheight;
	this.nLoaded = 0;
	this.nIntervalId = 0;
	this.IntervalId = 0;
	this.iTotDiv = 0;
	this.strDiv = "";
	this.iHeight = 0;
	this.count = 0;
	this.bPauseFlag = false;
	this.nTimeOut = 0;
	this.Layer = "";	
	this.nCreateTagInterval	= 0;
	this.BkAudioInterval = 0;
	this.arrPages = new Array ();
	this.BkAudioPlayOnce = false;
	
	//Member functions
	this.LoadContents = PageScroller_LoadContents;	
	this.GenerateHtml = PageScroller_GenerateHtml;
	this.CreateLayers = PageScroller_CreateLayers;
	this.PositionLayer = PageScroller_PositionLayer;
	this.start = PageScroller_start;
	this.CalculateTotTag = PageScroller_CalculateTotTag;
	this.CreateTag = PageScroller_CreateTag;
	this.Marquee = PageScroller_Marquee;
	this.MouseOver = PageScroller_MouseOver;
	this.MouseOut = PageScroller_MouseOut;
	this.GetTop = PageScroller_GetTop;
	this.SetTop = PageScroller_SetTop;	
	this.AdjustTop = PageScroller_AdjustTop;	
	this.GetHeight = PageScroller_GetHeight;	
	this.SetDivInnerHTML = PageScroller_SetDivInnerHTML;
	this.GetIFrameInnerHTML = PageScroller_GetIFrameInnerHTML;
	this.StartBkAudio = PageScroller_StartBkAudio;

	this.Back = PageScroller_Back;
	this.Next = PageScroller_Next;
	this.Pause = PageScroller_Pause;
	this.Play = PageScroller_Play;
	this.Begin = PageScroller_First;
	this.End = PageScroller_Last;
	this.ToggleSound = PageScroller_ToggleSound;

	this.EnableAudio = navigator.javaEnabled();
	this.PlayAudio = 1 - StartMute;

	if ( this.browser != 4 )
	{	
		arrPageScroll = PageScrollData.split ( "##RS##" );
		if ( arrPageScroll.length > 0 )
		{
			for ( var i = 0 ; i < arrPageScroll.length-1 ; i++ )
			{
				arrPageScrollData = arrPageScroll[i].split ( "##FS##" );
	
				if ( arrPageScrollData.length == 3 )
				{
					if ( ! this.EnableAudio ) arrPageScrollData[1] = "";
					this.arrPages[this.arrPages.length] = new PageScroller_ScrollerPageObj ( arrPageScrollData[0], arrPageScrollData[1], arrPageScrollData[2]);
				}
			}
		}
	
		if ( this.EnableAudio && BkAudio != "" )
		{
			this.BkAudioPlayOnce = ( BkAudio.charAt(BkAudio.length-1) == "1" );
			if (this.PlayAudio) this.BkAudioInterval = setInterval ( this.name+".StartBkAudio()", 1000 );
		}
	}
	return this;
}

function PageScroller_StartBkAudio ()
{
	var oApplet = document.applets["BkAudio_"+this.name];
	
	if ( this.EnableAudio == false )
	{
		clearInterval ( this.BkAudioInterval );
		return;
	}
	if ( oApplet && oApplet.AppletLoaded == true )
	{
		(this.BkAudioPlayOnce==true) ? oApplet.PlayAudio() : oApplet.LoopAudio();
		clearInterval ( this.BkAudioInterval );
	}
}

function PageScroller_ScrollerPageObj(PageName,SoundFile,PauseTime)
{
	this.url = PageName;
	this.Sound = SoundFile;
	this.Pause = PauseTime;
	this.text = "";
	this.height = ""	
}

function PageScroller_GenerateHtml()
{
	document.write ( '<table cellpadding=0 cellspacing=0 border=0 align='+this.Alignment+'><tr><td>' );
	if (this.browser==4)
	{
		document.write('<table width='+this.ComponentWidth+' height='+this.ComponentHeight+' border=1><tr><td align=center valign=center>This component is not compatible with Opera browser.</td></tr></table>');
	}
	else if (this.browser == 2)
	{
		var cw = (this.ComponentWidth-this.BorderSize-this.BorderSize), ch = (this.ComponentHeight-this.BorderSize-this.BorderSize);
		document.write('<ILAYER id="nsbase'+this.name+'" clip= "0,0,'+this.ComponentWidth+','+this.ComponentHeight+'" bgcolor="'+this.BorderColor+'">');
		document.write('<layer id="nsbkg'+this.name+'" left="'+this.BorderSize+'" top="'+this.BorderSize+'" height="'+ch+'" width="'+cw+'" background="'+this.BkImage+'" bgcolor="'+this.BkColor+'"></layer>');
		document.write('<layer id="ns4slider'+this.name+'" left="'+this.BorderSize+'" top='+this.BorderSize+'" clip= "0,0,'+cw+','+ch+';">');
		document.write('<layer id="ns4HandleEvent'+this.name+'" left="0" top=0 height="'+ch+'" width="'+cw+'" onmouseover="'+this.name+'.MouseOver();" onmouseout="'+this.name+'.MouseOut();"></layer>');
		document.write('<layer id="ns4loading'+this.name+'" left="'+this.LeftMargin+'" top='+this.TopMargin+' height="'+this.sheight+'" width="'+this.swidth+'" onmouseover="'+this.name+'.MouseOver();" onmouseout="'+this.name+'.MouseOut();">');
		document.write(this.loadMsg )
		document.write('</layer>');
		document.write('<layer id="ns4slider1'+this.name+'" left="'+this.LeftMargin+'" top="'+this.TopMargin+'" height="'+this.sheight+'" width="'+this.swidth+'" onmouseover="'+this.name+'.MouseOver();" onmouseout="'+this.name+'.MouseOut();"></layer>');
		document.write('</layer>');
		document.write('</Ilayer>');

		var doc = document.layers["nsbase"+this.name].document.layers["ns4slider"+this.name].document;
		doc.captureEvents ( Event.MOUSEDOWN);
		doc.onMouseDown = function(event){if(event.target=="") return false;}; 
	}
	else
	{
		document.write('<div id="base'+this.name+'" style="background-image:url('+this.BkImage+');background-color:'+this.BkColor+';position:relative;overflow:hidden;width:'+this.ComponentWidth+';height:'+this.ComponentHeight+';border:'+this.BorderSize+'px solid '+this.BorderColor+'; left:0; top:0;" onmouseover="'+this.name+'.MouseOver(event)" onmouseout="'+this.name+'.MouseOut()">');
		document.write('<div id="PageScroller'+this.name+'" style="position:'+((this.browser==1)?'absolute':'relative')+';overflow:hidden;width:'+this.swidth+';height:'+this.sheight+';left:'+this.LeftMargin+';top:'+this.TopMargin+';clip:rect(0 '+this.swidth+' '+this.sheight+' 0);" onselectstart="event.returnValue = false;"></div>');
		document.write('<div id="LoadingMsg'+this.name+'" style="position:absolute;left:0;top:0;width:'+this.ComponentWidth+';" onselectstart="event.returnValue = false;">');
		document.write(this.loadMsg);
		document.write('</div></div>');
	}
	document.write ( '</td></tr></table>' );

	if(this.browser == 3)
	{
		var e = document.getElementById("base"+this.name);
		e.onmousedown = function (){return false;};
	}

	if (this.browser != 2)
	{
		for ( var i = 0 ; i < this.arrPages.length ; i++ )
		{
			document.writeln('<IFRAME ID="IFrame'+this.name+i+'" style="left:-1000;top:-1000;position:absolute" src="'+this.arrPages[i].url+'" FRAMEBORDER=1></IFRAME>');
		}
		this.IntervalId = setInterval(this.name+".LoadContents()",2000);
	}
}

function PageScroller_CreateLayers()
{
	var i=0;
	this.Layer = document.layers["nsbase"+this.name].document.layers["ns4slider"+this.name];
	for(i=1; i<=this.arrPages.length; i++)
	{
		var newlayer = new Layer ( this.swidth, this.Layer.document.layers["ns4slider1"+this.name]);
	}

	for(i=0; i < this.arrPages.length; i++)
	{
		this.Layer.document.layers["ns4slider1"+this.name].document.layers[i].onload = eval("OnLoadLayer" + this.name);
		this.Layer.document.layers["ns4slider1"+this.name].document.layers[i].load(this.arrPages[i].url,this.swidth);
		this.Layer.document.layers["ns4slider1"+this.name].document.layers[i].clip.width = this.swidth;
			
		/* next statement had to be done since while doanloding the files of the net, the src of the
		 second document was getting set to null, looks like as if NS is missing out on the second
		 assignment while it is trying to download the first one*/
		if ( this.Layer.document.layers["ns4slider1"+this.name].document.layers[i].src == null ) i--;
	}
	clearInterval(eval("nIntervalTimeout"+this.name));
}

function PageScroller_PositionLayer(LayerObj)
{
	LayerObj.clip.width = this.swidth;
	this.count++;
	if (this.count == this.arrPages.length)
	{
		for ( var i = 0 ; i < this.arrPages.length ; i++ )
		{
			this.arrPages[i].height = this.Layer.document.layers["ns4slider1"+this.name].document.layers[i].clip.height;	
		}
		this.CalculateTotTag();
		this.nCreateTagInterval = setInterval(this.name+".CreateTag();",2000);
	}
	else if(this.count == this.iTotDiv)
	{
		this.Layer.document.layers["ns4loading"+this.name].visibility = "hide";
		this.start();
	}
}

function PageScroller_LoadContents()
{
	var i, val;
	for(i=0; i< this.arrPages.length; i++)
	{
		val = this.GetIFrameInnerHTML ( i );
		if ( val != "" )
		{
			if(this.arrPages[i].text == "")
			{
				this.arrPages[i].text = val;
				this.nLoaded++
			}
			if(this.nLoaded == this.arrPages.length)
			{
				clearInterval(this.IntervalId);
				var j;
				for(j=0; j< this.arrPages.length; j++)
				{
					this.strDiv += '<div id="tContent'+this.name+j+'" style="visibility:hidden;position:absolute;width:'+this.swidth+';">'+this.arrPages[j].text+'</div>';
				}
				this.SetDivInnerHTML ( "PageScroller"+this.name, this.strDiv );
				for(j=0; j< this.arrPages.length; j++)
				{
					this.arrPages[j].height = this.GetHeight ( "tContent"+this.name+j, 0 );
				}
				this.CalculateTotTag();
				this.CreateTag();
				this.SetDivInnerHTML ( "LoadingMsg"+this.name, "");
				this.SetDivInnerHTML ( "PageScroller"+this.name, this.strDiv );
				this.start();
			}
		}
	}	
}

function PageScroller_CalculateTotTag()
{
	var totContentHeight = 0, iXtraDiv=0, CurrTotDiv=0;
	//here the total nbr of div's to be created are assessed
	while(totContentHeight < this.sheight)
	{
		totContentHeight += this.arrPages[iXtraDiv%this.arrPages.length].height;
		iXtraDiv++;
	}
	//total nbr of div's to be created
	CurrTotDiv = this.arrPages.length + iXtraDiv;
	
	this.iTotDiv = CurrTotDiv + (this.arrPages.length-(CurrTotDiv%this.arrPages.length))
}

function PageScroller_CreateTag()								
{
	this.iHeight = (this.Mode == 0) ? 1 : this.sheight;
	if (this.browser != 2)
	{
		var j;
		
		for(j=0; j< this.iTotDiv; j++)		
		{
			this.strDiv += '<div id="Content'+this.name+j+'" style="position:absolute;left:0;top:'+this.iHeight+';width:'+this.swidth+';" onselectstart="event.returnValue = false;">'+this.arrPages[j%this.arrPages.length].text+'</div>';
			this.iHeight += this.arrPages[j%this.arrPages.length].height + this.nGap;
		}
	}
	else
	{
		var ns4 = this.Layer.document.layers["ns4slider1"+this.name];
		var i;

		for(i=this.arrPages.length; i< this.iTotDiv; i++)
		{
			var newlayer = new Layer ( this.swidth,  ns4 );
		}

		for(i=this.arrPages.length; i < this.iTotDiv; i++)
		{
			ns4.document.layers[i].onload = eval("OnLoadLayer" +this.name);				
			ns4.document.layers[i].load(this.arrPages[i%this.arrPages.length].url,this.swidth);
			if ( ns4.document.layers[i].src == null ) 
			{
				i--;
			}
		}
		clearInterval(this.nCreateTagInterval);
	}
}

function PageScroller_start()
{
	if ( this.browser == 2 )
	{
		this.iHeight = (this.Mode == 0) ? 1 : this.sheight; 

		for ( var i = 0 ; i < this.iTotDiv ; i++ )
		{
			this.Layer.document.layers["ns4slider1"+this.name].layers[i].top = this.iHeight;
			this.Layer.document.layers["ns4slider1"+this.name].layers[i].clip.width = this.swidth;
			this.Layer.document.layers["ns4slider1"+this.name].layers[i].visibility = "show";
			this.iHeight += this.arrPages[i%this.arrPages.length].height + this.nGap;
		}
	}
	this.nIntervalId = setInterval(this.name+".Marquee();", 100 );
}

function PageScroller_GetTop ( name, index )
{
	if (this.browser == 1)
	{
		return document.all(name).style.pixelTop;
	}
	else if ( this.browser == 2 )
	{
		return this.Layer.document.layers["ns4slider1"+this.name].document.layers[index].top;
	}
	else if ( this.browser == 3 )
	{
		return parseInt(document.getElementById(name).style.top);
	}
}

function PageScroller_SetTop ( name, index, value )
{
	if (this.browser == 1 )
	{
		document.all(name).style.pixelTop = value;
	}
	else if ( this.browser == 2 )
	{
		this.Layer.document.layers["ns4slider1"+this.name].document.layers[index].top = value;
	}
	else if ( this.browser == 3 )
	{
		document.getElementById(name).style.top = value;
	}
}

function PageScroller_AdjustTop(offset)
{
	var i;
	
	for(i = 0; i < this.iTotDiv; i++)
	{
		this.SetTop ( "Content"+this.name+i, i, this.GetTop("Content"+this.name+i,i)-offset );
	}
}

function PageScroller_Marquee()
{
	var i,divTop, index2;

	for(i=0; i < this.iTotDiv; i++)
	{
		divTop = this.GetTop ( "Content"+this.name+i, i ) ;
		if ( divTop > 0 && divTop <= this.sspeed )
		{
			this.AdjustTop( divTop-this.sspeed );
			divTop = 1;
		}
		if (divTop >= ((this.GetHeight("Content"+this.name+i,i))*-1))
		{
			if ( divTop == 1)
			{
				clearInterval(this.nIntervalId);
				index2 = i % this.arrPages.length;
				if ( this.EnableAudio && this.PlayAudio )
				{
					var oApplet = document.applets["ItemAudio_"+this.name];
					if ( oApplet && oApplet.AppletLoaded == true )
					{
						(this.arrPages[index2].Sound!="") ? oApplet.PlayAudio(index2+1) : oApplet.StopAudio();
					}
				}
				this.nTimeOut = setTimeout(this.name+".nIntervalId = setInterval('"+this.name+".Marquee();',100)",this.arrPages[i%this.arrPages.length].Pause);
				divTop=this.sspeed;
			}
			this.SetTop ( "Content"+this.name+i, i, (divTop-this.sspeed));
		}
		else
		{
			index2 = ( i == 0 ) ? this.iTotDiv-1 : i-1;
			this.SetTop( "Content"+this.name+i, i, this.GetTop("Content"+this.name+index2,index2)+this.GetHeight("Content"+this.name+index2,index2)+this.nGap );
		}
	}
}

function PageScroller_GetHeight( name, index )
{
	if (this.browser == 1 )
	{
		return document.all(name).clientHeight;
	}
	else if ( this.browser == 2 )
	{
		return this.Layer.document.layers["ns4slider1"+this.name].document.layers[index].clip.height;
	}
	else if ( this.browser == 3 )
	{
		return document.getElementById(name).offsetHeight;
	}
}

function PageScroller_SetDivInnerHTML ( name, val )
{
	var obj;
	
	if ( this.browser == 1 )
	{
		obj = document.all(name);
	}
	else if ( this.browser == 3 )
	{
		obj = document.getElementById(name);
	}
	obj.innerHTML = val;
}

function PageScroller_GetIFrameInnerHTML ( index )
{
	var obj, val = "";
	if ( this.browser == 1 )
	{
		obj = document.frames["IFrame"+this.name + index].document.all.tags("BODY");
		if ( typeof(obj[0]) != "undefined" )
		{
			val = obj[0].innerHTML;
		}
	}
	else if ( this.browser == 3 )
	{
		obj = document.getElementById("IFrame"+this.name + index);
		if ( obj.contentDocument != null  )
		{
			val = obj.contentDocument.body.innerHTML
		}
	}

	return val;
}

function PageScroller_MouseOver(event)
{
	if(this.bPauseFlag == false)
	{
		this.sspeed=0;
		window.status=this.StatusBarMsg; 
	}
}

function PageScroller_MouseOut(event)
{
	if(this.bPauseFlag == false)
	{
		this.sspeed=this.ScrollSpeed;
		window.status="";
	}
}

function PageScroller_Back() { }
function PageScroller_Next() { }
function PageScroller_First() { }
function PageScroller_Last() { }

function PageScroller_Pause()
{
	if ( this.browser == 4 ) return;
	this.bPauseFlag = true;
	clearInterval(this.nIntervalId);
	clearTimeout(this.nTimeOut);
	if ( this.EnableAudio && this.PlayAudio )
	{
		var oBkApplet = document.applets["BkAudio_"+this.name];
		var oItemApplet = document.applets["ItemAudio_"+this.name];
		if ( oBkApplet && oBkApplet.AppletLoaded == true ) oBkApplet.StopAudio();
		if ( oItemApplet && oItemApplet.AppletLoaded == true ) oItemApplet.StopAudio();
	}
}

function PageScroller_Play()
{
	if ( this.browser == 4 ) return;
	if(this.bPauseFlag == true)
	{
		this.bPauseFlag = false;
		this.nIntervalId = setInterval(this.name+'.Marquee();',100);
		if ( this.EnableAudio && this.PlayAudio )
		{
			var oBkApplet = document.applets["BkAudio_"+this.name];
			if ( oBkApplet && oBkApplet.AppletLoaded == true ) ( (this.BkAudioPlayOnce==true) ? oBkApplet.PlayAudio() : oBkApplet.LoopAudio() );
		}
	}
}

function PageScroller_ToggleSound()
{
	if ( this.browser == 4 ) return;
	if ( this.EnableAudio )
	{
		var oBkApplet, oItemApplet;

		this.PlayAudio = 1 - this.PlayAudio;
		if ( ! this.bPauseFlag )
		{
			oBkApplet = document.applets["BkAudio_"+this.name];
			oItemApplet = document.applets["ItemAudio_"+this.name];
			if ( oBkApplet && oBkApplet.AppletLoaded == true )
			{
				(this.PlayAudio==0) ? oBkApplet.StopAudio() : ( (this.BkAudioPlayOnce==true) ? oBkApplet.PlayAudio() : oBkApplet.LoopAudio() );
			}
			if ( oItemApplet && oItemApplet.AppletLoaded == true )
			{
				if (this.PlayAudio==0) oItemApplet.StopAudio();
			}
		}
	}
}

