var scrollingPanes = new Array();
var panePositions = new Array();
var dupeCount = 0; //Current number of created duplicates
var paneHeight = 0; //Current height of container pane
var itemHeight = 0; //Height of item to be duplicated
var paneOffset = 2; //Spacing distance between panes
var updateSpeed = 60; //Update frequency in milliseconds, lower is faster
var allowScroll = true;
 
function DuplicateDIV(srcDivName,insertDivName)
{
try
{
dupeCount++;
var srcDiv = document.getElementById(srcDivName);
var targetDiv = document.getElementById(insertDivName);
var newDivId = srcDivName + dupeCount;
if(srcDiv && targetDiv)
{
 
itemHeight = srcDiv.offsetHeight;
 
var duplicateDiv = document.createElement('div');
duplicateDiv.innerHTML = srcDiv.innerHTML;
duplicateDiv.className = srcDiv.className;
duplicateDiv.setAttribute('id',newDivId);
targetDiv.appendChild(duplicateDiv);
panePositions.push(dupeCount * (itemHeight + paneOffset));
return duplicateDiv;
}
}
catch(err)
{
//Handle error here
alert(err.message);
return null;
}
 
}
 
function StartScrolling()
{
 
var containerPane = document.getElementById("scrollingWindow");
containerPane.onmouseover = PauseScrolling;
containerPane.onmouseout = ResumeScrolling;
 
scrollingPanes.push(document.getElementById("scrollingDiv0"));
panePositions.push(0);
 
var requiredHeight = containerPane.offsetHeight;
var currentHeight = 0;
while(currentHeight < requiredHeight)
{
var newPane = DuplicateDIV("scrollingDiv0","scrollingWindow");
if(newPane != null)
{
currentHeight += newPane.offsetHeight;
scrollingPanes.push(newPane);
}
else
{
break;
}
}
 
setInterval("UpdateDivPanes()",updateSpeed);
}
 
function PauseScrolling()
{
allowScroll = false;
}
 
function ResumeScrolling()
{
allowScroll = true;
}
 
/*
//Update the current positions of all the duplicated divs
*/
function UpdateDivPanes()
{
if(allowScroll == true)
{
for(var i = 0; i < scrollingPanes.length; i++)
{
var thisPane = scrollingPanes[i];
thisPane.style.top = panePositions[i] + "px";
panePositions[i]--;
if(panePositions[i] <= 0 - (itemHeight + paneOffset))
{
panePositions[i] = EndPosition();
}
}
}
}
 
/*
//This function calculates what the current bottom-most div is
//and returns the value of that plus the pane offset value.
*/
function EndPosition()
{
var maxPosition = 0;
for(var i = 0; i < scrollingPanes.length; i++)
{
if(panePositions[i] > maxPosition)
{
maxPosition = panePositions[i];
}
}
 
return maxPosition + itemHeight + paneOffset - 1; //The -1 compensates for the face that everything else is moving by 1 pixel this cycle
 
}
 
