REM Edgar V. Poirier
REM moomoo@nbnet.nb.ca
REM Revised August, 2000
Dim w, wW, wH, wx, baseFont, myTimer, layers, mH, bW, Res
Dim x(), y(), xD(), yD(), bT(), bL(), pW(), pH(), bP()
Dim picX(), picY(), bxW(), bxH()
Dim numPics(), chkPics(), scrollDirection()

Set w=document.body

REM *** Set Font Size ***
baseFont=11

REM *** Set number of scrolling layers ***
layers=3

reDim x(layers), y(layers), xD(layers), yD(layers), bT(layers), bL(layers)
reDim pW(layers), pH(layers), bP(layers), picX(layers), picY(layers)
reDim bxW(layers), bxH(layers), numPics(layers), chkPics(layers), scrollDirection(layers)

REM *** Set scroll Direction
REM     xD(image_number)=-1 means move left
REM     xD(image_number)=1 means move right
REM     yD(image_number)=-1 means move up
REM     yD(image_number)=1 means move down
REM *** Larger numbers give faster movement
xD(1)=1
yD(1)=0
xD(2)=1
yD(2)=1
xD(3)=0
yD(3)=0


REM *** Set the border Height here ***
bH=280

REM Initialize
sub setUp()
	on error resume next
	REM Top Margin is set here
	w.style.marginTop=bH+5
	REM Get window dimensions
	wW=w.clientWidth
	wH=w.clientHeight
	sH=w.scrollHeight
	mH=wH
	if sH>wH then mH=sH
	for i=1 to layers
		bL(i)=0
		bT(i)=0
		REM Initial position
		x(i)=0
		y(i)=0
	next
	REM Set the visible limits
	frm.style.height=bH
	frm.style.width=wW
	frm.style.left=0
	frm.style.top=0
	REM Start the scroll.
	SF
end sub

REM universal scrolling routine.
sub SF()
	ClearTimeOut(myTimer)
	for i=1 to layers
		x(i)=x(i)+xD(i)
		if xD(i)>0 and x(i)>=0 then x(i)=-pW(i)
		if xD(i)<0 and x(i)<-pW(i) then x(i)=0
		y(i)=y(i)+yD(i)
	 	if yD(i)>0 and y(i)>=0 then y(i)=-pH(i)
		if yD(i)<0 and y(i)<-pH(i) then y(i)=0
		REM Position the background image.
		document.all("b"&i).style.left = x(i)
		document.all("b"&i).style.top = y(i)
	next
	REM repeat (larger numbers give slower scroll below)
	myTimer=SetTimeOut("SF",10)
end sub

REM Everything starts here
sub Window_OnLoad()
	REM Get window dimensions
	wW=w.clientWidth
	wH=w.clientHeight
	sH=w.scrollHeight
	REM Get users screen resolution
	wx=window.screen.width
	REM and adjust font size to match. This will have the same size font
	REM appear no matter what the viewer's screen resolution is
	Res=INT(SQR(wx))-25
	REM Set the font size
	w.style.fontSize = baseFont+Res
	<!-- This is the container for the layers No changes required here -->
	data="<DIV id=frm style='position:absolute;top:0;left:-1800;width:800;height:600;z-index:-1;filter:BlendTrans(Duration=0)'>"
	for i=1 to layers
		REM Get dimensions of background image.
		pW(i)=document.all("bkg"&i).style.posWidth
		pH(i)=document.all("bkg"&i).style.posHeight
		REM Calculate the size of the background
		REM Number of images
		picX(i)=INT((wx)/pW(i))+4
		if picX(i)<2 then picX(i)=4
		picY(i)=4
		REM Width of background
		bxW(i)=picX(i)*pW(i)
		REM Height of background
		bxH(i)=picY(i)*pH(i)
		REM Calculate required number of images
		numPics(i)=picX(i)*picY(i)
		REM Create a SPAN to hold the layer
		data=data&"<SPAN id='b"&i&"' style="
		data=data&"'position:absolute;top:0;left:0;width:"&bxW(i)&";height:"&bxH(i)&"'>"
		REM "Tile" the background (NOTE: Image is not positioned.)
		for j=1 to numPics(i)
			data=data&"<IMG src='" & document.all("bkg"&i).src & "'>"
		next
		data=data&"</SPAN>"
	next
	data=data&"</DIV>"
	w.insertAdjacentHTML "afterBegin", data
	REM Lets get started.
	setUp
end sub

REM This runs if the window size is changed.
sub Window_OnResize()
	setUp
end sub

