function ScrollContinuousObj ( ComponentName,
	ComponentWidth, ComponentHeight, Alignment,
	LeftMargin, TopMargin, RightMargin, BottomMargin,
	ScrollSpeed, LoadMsg, LoadMsgColor, LoadMsgSize,
	BkImage, BkAudio, BkColor, BorderSize, BorderColor,
	StatusBarMsg, Mode, 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
	
	if ( this.browser == 1 )
	{
		this.IE4 = false;
		var i = navigator.userAgent.indexOf("MSIE");
		if ( i > -1 ) if ( navigator.userAgent.substr(i+5,2) == "4." ) this.IE4 = true;
	}

	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.BkAudioPlayOnce = false;

	this.nLoaded = 0;
	this.nIntervalId = 0;
	this.iTotDiv = 0;
	this.strDiv = "";
	this.iHeight = 1;	
	this.oldY = 0;
	this.OrgPageY = 0;
	this.ContentDragging = false;
	this.count = 0;
	this.bPauseFlag = false;
	this.nCreateTagInverval	= 0;
	this.BkAudioInterval = 0;
	this.Layer = "";
	this.arrPages = new Array ();
	
	//Member functions
	this.GenerateHtml = ContScroller_GenerateHtml;
	this.CreateLayers = ContScroller_CreateLayers;
	this.PositionLayer = ContScroller_PositionLayer;
	this.start = ContScroller_start;
	this.GetTop = ContScroller_GetTop;
	this.GetHeight = ContScroller_GetHeight;
	this.SetTop = ContScroller_SetTop;
	this.Marquee = ContScroller_Marquee;
	this.GetIFrameInnerHTML	= ContScroller_GetIFrameInnerHTML;
	this.SetDivInnerHTML = ContScroller_SetDivInnerHTML;
	this.LoadContents = ContScroller_LoadContents;
	this.StartBkAudio = ContScroller_StartBkAudio;
	
	this.MouseOver = ContScroller_MouseOver;
	this.MouseOut = ContScroller_MouseOut;
	this.MouseDown = ContScroller_MouseDown;
	this.MouseUp = ContScroller_MouseUp;
	this.MouseMove = ContScroller_MouseMove;
		
	this.DragPages = ContScroller_DragPages;
	this.CalculateTotTag = ContScroller_CalculateTotTag;		
	this.CreateTag = ContScroller_CreateTag;
	
	this.Back = ContScroller_Back;
	this.Next = ContScroller_Next;
	this.Play = ContScroller_Play;
	this.Pause = ContScroller_Pause;
	this.Begin = ContScroller_First;
	this.End = ContScroller_Last;
	this.ToggleSound = ContScroller_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 == 2 )
				{
					if ( ! this.EnableAudio ) arrPageScrollData[1] = "";
					this.arrPages[this.arrPages.length] = new ContScroller_ScrollerPageObj ( arrPageScrollData[0], arrPageScrollData[1] );
				}
			}
		}
		
		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 ContScroller_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 ContScroller_ScrollerPageObj ( PageName, SoundFile )
{
	this.url = PageName;
	this.Sound = SoundFile;
	this.text = "";
	this.height = ""	
}

function ContScroller_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();">');
		document.write('</layer>');
		document.write('</layer>');
		document.write('</ilayer>');
		
		var doc = document.layers["nsbase" +this.name].document.layers["ns4slider"+this.name].document;
		doc.captureEvents ( Event.MOUSEUP|Event.MOUSEDOWN|Event.MOUSEDRAG|Event.MOUSEMOVE );
		doc.onMouseUp = eval("NS4MouseUp"+this.name);
		doc.onMouseMove = eval("NS4MouseMove"+this.name);
		doc.onMouseDown = eval("NS4MouseDown"+this.name);
	}
	else 
	{
		document.writeln('<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()" onmousemove="'+this.name+'.MouseMove(event);" onmousedown="'+this.name+'.MouseDown(event);" onmouseup="'+this.name+'.MouseUp(event);">');
		document.writeln('<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; return false;"></div>');
		document.writeln('<div id="LoadingMsg'+this.name+'" style="position:absolute;left:0;top:0;width:'+this.ComponentWidth+';" onselectstart="event.returnValue = false;">');
		document.write ( this.loadMsg );
		document.writeln('</div></div>');
	}
	document.write ( '</td></tr></table>' );
	
	if (!document.layers)
	{
		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 ContScroller_CreateLayers()
{
	var i = 0;

	this.Layer = document.layers["nsbase"+this.name].document.layers["ns4slider"+this.name];
	var l = this.Layer.document.layers["ns4slider1"+this.name];
	for(i=0; i<this.arrPages.length; i++)
	{
		var newlayer = new Layer ( this.swidth, l );
	}
	for(i=0; i < this.arrPages.length; i++)
	{
		l.document.layers[i].onload = eval("OnLoadLayer" + this.name);
		l.document.layers[i].src = this.arrPages[i].url;
		l.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 ( l.document.layers[i].src == null ) i--;
	}
	clearInterval(eval("nIntervalTimeout"+this.name));
}

function ContScroller_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.nCreateTagInverval = setInterval(this.name+".CreateTag();",2000);
	}
	else if ( this.count == this.iTotDiv )
	{
		this.Layer.document.layers["ns4loading"+this.name].visibility = "hide";
		this.start();
	}
}

function ContScroller_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.nIntervalId = setInterval(this.name+".Marquee();", 100 );
}

function ContScroller_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 ContScroller_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 ContScroller_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 ContScroller_Marquee()
{
	var i, divTop, index2;

	if ( this.ContentDragging == true ) return;
	if ( this.sspeed == 0 ) return;

	for ( i = 0; i < this.iTotDiv ; i++ )
	{
		divTop = this.GetTop ( "Content"+this.name+i, i );
		if (divTop >= ((this.GetHeight("Content"+this.name+i,i))*-1))
		{
			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) );
		}
	}
}

function ContScroller_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 ContScroller_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 ContScroller_LoadContents()
{
	var i=0, 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 ContScroller_MouseOver(event)
{
	this.sspeed=0;
	window.status=this.StatusBarMsg 
}

function ContScroller_MouseOut(event)
{
	this.sspeed=this.ScrollSpeed;
	window.status="";
}

function ContScroller_MouseDown(e)
{
	if ( this.browser == 1 )
	{
		this.oldY = e.clientY;
		if(navigator.platform.indexOf("Win") != -1 && this.IE4 == false )
		{
			document.all("PageScroller"+this.name).setCapture();
		}
	}
	else if ( this.browser == 2 )
	{
		this.OrgPageY = e.pageY;
		this.oldY = 0;
	}
	else if (this.browser == 3)
	{
		this.oldY = e.pageY;
		e.stopPropagation ();
	}
	this.ContentDragging = true;
	return true;
}

function ContScroller_MouseUp ( e )
{
	if ( this.browser == 1 )
	{
		// mouse up event outside the div tag has mouse and client coordinates same
		if ( e.x == e.clientX && e.y == e.clientY )
		{
			this.MouseOut ( e );
		}
		if(navigator.platform.indexOf("Win") != -1 && this.IE4 == false )
		{
			document.all("PageScroller"+this.name).releaseCapture();
		}
	}
	this.ContentDragging = false;
	return true;
}

function ContScroller_MouseMove ( e )
{
	if ( this.ContentDragging == true )
	{
		var OffsetValue=0;	

		if ( this.browser == 1 )
		{
			 OffsetValue = ( e.clientY - this.oldY );
			 this.oldY = e.clientY;
		}
		else if ( this.browser == 2 )
		{
			OffsetValue = (e.pageY - this.OrgPageY) - this.oldY;
			this.oldY = e.pageY - this.OrgPageY;
		}
		else if (this.browser == 3)
		{
			OffsetValue = ( e.pageY - this.oldY );
			this.oldY = e.pageY;
		}
		this.DragPages(OffsetValue);
	}
	return true;
}

function ContScroller_DragPages(val)
{
	var index2, i;

	for ( i = 0 ; i < this.iTotDiv; i++ )
	{
		var divTop = this.GetTop ( "Content"+this.name+i, i );
		this.SetTop ( "Content"+this.name+i, i, divTop+val );
		divTop += val;
	}
	for ( i = 0 ; i < this.iTotDiv; i++ )
	{
		var divTop = this.GetTop ( "Content"+this.name+i, i );
		if (divTop < ((this.GetHeight("Content"+this.name+i,i))*-1))
		{
			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) );
		}	
		else if ( divTop > this.sheight )
		{
			index2 = ( i == this.iTotDiv-1 ) ? 0 : i+1;
			this.SetTop ( "Content"+this.name+i, i, this.GetTop("Content"+this.name+index2,index2)-this.GetHeight("Content"+this.name+index2,index2) );
		}
	}
}

function ContScroller_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 ContScroller_CreateTag()								
{
	this.iHeight = (this.Mode == 0) ? 1 : this.sheight; 

	if (this.browser != 2)
	{
		var j;
		this.strDiv = "";
		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;
		}
	}
	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.nCreateTagInverval);
	}
}

function ContScroller_Back() { }
function ContScroller_Next() { }
function ContScroller_First() { }
function ContScroller_Last() { }

function ContScroller_Pause()
{
	if ( this.browser == 4 ) return;
	this.bPauseFlag = true;
	clearInterval(this.nIntervalId);
	if ( this.EnableAudio && this.PlayAudio )
	{
		var oBkApplet = document.applets["BkAudio_"+this.name];
		if ( oBkApplet && oBkApplet.AppletLoaded == true ) oBkApplet.StopAudio();
	}
}

function ContScroller_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 ContScroller_ToggleSound()
{
	if ( this.browser == 4 ) return;
	if ( this.EnableAudio )
	{
		var oBkApplet;

		this.PlayAudio = 1 - this.PlayAudio;
		if ( ! this.bPauseFlag )
		{
			oBkApplet = document.applets["BkAudio_"+this.name];
			if ( oBkApplet && oBkApplet.AppletLoaded == true )
			{
				(this.PlayAudio==0) ? oBkApplet.StopAudio() : ( (this.BkAudioPlayOnce==true) ? oBkApplet.PlayAudio() : oBkApplet.LoopAudio() );
			}
		}
	}
}

