function ScrollContinuousObj ( ComponentName,
	ComponentWidth, ComponentHeight, Alignment,
	LeftMargin, TopMargin, RightMargin, BottomMargin,
	ScrollSpeed, LoadMsg, LoadMsgColor, LoadMsgSize,
	BkImage, BkAudio, BkColor, BorderSize, BorderColor,
	StatusBarMsg, Mode, PageScrollData, StartMute, MouseOverPause )
{
	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.MouseOverPause = MouseOverPause;

	this.Started = 0;
	this.nLoading = 0;
	this.nIntervalId = 0;
	this.iTotDiv = 0;
	this.strDiv = "";
	this.oldY = 0;
	this.OrgPageY = 0;
	this.ContentDragging = false;
	this.bPauseFlag = false;
	this.BkAudioInterval = 0;
	this.Layers = "";
	this.arrPages = new Array ();
	
	//Member functions
	this.GenerateHtml = ContScroller_GenerateHtml;
	this.CreateLayers = ContScroller_CreateLayers;
	this.CreateLayerTag = ContScroller_CreateLayerTag;
	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.GetIFrame = ContScroller_GetIFrame;

	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 )
	{	
		var arrPageScroll = PageScrollData.split ( "##RS##" );
		if ( arrPageScroll.length > 0 )
		{
			for ( var i = 0 ; i < arrPageScroll.length-1 ; i++ )
			{	
				var 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+'" clip="0,0,'+this.swidth+','+this.sheight+'" onmouseover="'+this.name+'.MouseOver();" onmouseout="'+this.name+'.MouseOut();">');
		for ( var i = 0 ; i <= this.arrPages.length ; i++ )
			document.write ( '<layer width="'+this.swidth+'" visibility="hidden"></layer>' );
		document.write('</layer>');
		document.write('</layer>');
		document.write('</ilayer>');
		
		this.Layers = document.layers["nsbase"+this.name].document.layers["ns4slider"+this.name].document.layers["ns4slider1"+this.name].document.layers;
		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 (this.browser==4) return;
	if (this.browser != 2)
	{
		this.nLoading = 0;
		for ( i = 0 ; i < this.arrPages.length ; i++ )
			document.writeln('<IFRAME ID="IFrame'+this.name+i+'" style="left:-1000;top:-1000;position:absolute" FRAMEBORDER=1></IFRAME>');
		this.GetIFrame(this.nLoading).src = this.arrPages[this.nLoading].url;
		this.IntervalId = setInterval(this.name+".LoadContents()",800);
	}
	else
	{ this.nLoading = -1; this.iTotDiv = this.arrPages.length + 1; }
}

function ContScroller_CreateLayerTag(index)
{
	var doc;
	if ( index < this.arrPages.length )
		doc = this.Layers[index+1].document;
	else
		doc = this.Layers[0].document.layers[index-this.arrPages.length].document;
	doc.open ();
	doc.write ( '<layer src="'+this.arrPages[index%this.arrPages.length].url+'" width="'+this.swidth+'" visibility=hidden onload="'+this.name+'.CreateLayers();"></layer>' );
	doc.close ();
}

function ContScroller_CreateLayers()
{
	this.nLoading++;
	if ( this.nLoading == this.arrPages.length )
	{
		for ( var i = 0 ; i < this.arrPages.length ; i++ )
		{
			this.Layers[i+1].clip.width = this.swidth;
			this.arrPages[i].height = this.Layers[i+1].clip.height;
		}
		this.CalculateTotTag();
		with ( this.Layers[0].document )
		{
			open ();
			for ( i = this.arrPages.length ; i < this.iTotDiv ; i++ )
				write ( '<layer width="'+this.swidth+'" visibility="hidden"></layer>' );
			close ();
		}
	}
	else if ( this.nLoading == this.iTotDiv )
	{
		document.layers["nsbase"+this.name].document.layers["ns4slider"+this.name].document.layers["ns4loading"+this.name].visibility = "hide";
		this.start();
		return;
	}
	setTimeout ( this.name+'.CreateLayerTag('+this.nLoading+');', 500 );
}

function ContScroller_start()
{
	if (this.browser == 2 )
	{
		var l, i, iHeight = (this.Mode == 0) ? 1 : this.sheight;
		l = this.Layers[0];
		for ( i = l.document.layers.length-1 ; i >= 0 ; i-- )
			l.document.layers[i].moveAbove ( l );
		for ( i = 0 ; i < this.iTotDiv ; i++ )
		{
			l = this.Layers[i+1];
			l.top = iHeight; l.width = this.swidth; l.visibility = "show";
			l = l.document.layers[0]; l.width = this.swidth; l.visibility = "show";
			iHeight += this.arrPages[i%this.arrPages.length].height ;
		}
	}
	if (!this.bPauseFlag) this.nIntervalId = setInterval(this.name+".Marquee();", 100 );
	this.Started = 1;
}

function ContScroller_GetIFrame ( index )
{
	if (this.browser==1) return document.all("IFrame"+this.name+index);
	else if (this.browser==2) return null;
	else if (this.browser==3) return document.getElementById("IFrame"+this.name+index);
}

function ContScroller_GetTop ( name, index )
{
	if (this.browser==1) return document.all(name).style.pixelTop;
	else if (this.browser==2) return this.Layers[index+1].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.Layers[index+1].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.Layers[index+1].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 val = this.GetIFrameInnerHTML ( this.nLoading );
	if ( val != "" )
	{
		this.arrPages[this.nLoading].text = val;
		this.nLoading++;
		if(this.nLoading == 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();
		}
		else
		{
			this.GetIFrame(this.nLoading).src = this.arrPages[this.nLoading].url;
		}
	}
}

function ContScroller_MouseOver(event)
{ 
	if ( this.MouseOverPause ) 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()								
{
	var 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:'+iHeight+';width:'+this.swidth+';" onselectstart="event.returnValue = false;">' + this.arrPages[j%this.arrPages.length].text+ '</div>';
			iHeight += this.arrPages[j%this.arrPages.length].height;
		}
	}
}

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;
		if (!this.Started) return;
		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 || ! this.PlayAudio )
		{
			oBkApplet = document.applets["BkAudio_"+this.name];
			if ( oBkApplet && oBkApplet.AppletLoaded == true ) (this.PlayAudio==0) ? oBkApplet.StopAudio() : ( (this.BkAudioPlayOnce==true) ? oBkApplet.PlayAudio() : oBkApplet.LoopAudio() );
		}
	}
}
