
// The structure of this marque script was inspired by 
// Deluxe Scroller by Howard Covitz.
//
// Deluxe Scroller was far too limited for what we
// needed however, and couldn't really be extended.
//
// This one has been rebuilt using a similar markup
// structure, but a much better script.
function beginMarquee(div_id,direction, speed, rate, distance, pause)
{
 var hull=document.getElementById(div_id);
 if(!hull){return;}
 
 // default values
 if (!direction)
 {
  direction = 'up';
 }
 if (!speed)
 {
  speed = 30;
 }
 
 // The two ULs are used to scroll the content. We will call them block
 // a, and block b. Block a is ALWAYS ahead of block b.
 var a=hull.getElementsByTagName('ul')[0];
 var b=hull.getElementsByTagName('ul')[1];
 
 // Clone the data to the other div
 a.innerHTML = b.innerHTML;
 
 if (direction == 'left' || direction == 'right')
 {
   // d should have the same vertical placement as c but this is
   // hard to get right in the markup, so we just correct it here.
   delta = 0 - (b.offsetTop - a.offsetTop);
   b.style.top=delta+'px';
   b.style.marginBottom=(0 - b.offsetHeight)+'px'; // NOTE: This assumes that the bottom margin WAS 0
 }
 
 a.traveled = 0;
 a.myposition = 0;
 a.myinterval = setTimeout('domarquescroll("' + div_id + '", "' + direction + '", ' + speed + ', ' + rate + ', ' + distance + ', ' + pause + ')',speed);

 a.onmouseover=function(){clearTimeout(a.myinterval);}
 a.onmouseout=function(){a.myinterval =setTimeout('domarquescroll("' + div_id + '", "' + direction + '", ' + speed + ', ' + rate + ', ' + distance + ', ' + pause + ')',speed);}
 b.onmouseover=function(){clearTimeout(a.myinterval);}
 b.onmouseout=function(){a.myinterval =setTimeout('domarquescroll("' + div_id + '", "' + direction + '", ' + speed + ', ' + rate + ', ' + distance + ', ' + pause + ')',speed);}
}

function unpause(div_id, direction, speed, rate, distance, pause)
{
 var hull=document.getElementById(div_id);
 var a= hull.getElementsByTagName('ul')[0];
 a.myinterval = setTimeout('domarquescroll("' + div_id + '", "' + direction + '", ' + speed + ', ' + rate + ', ' + distance + ', ' + pause + ')',speed);
}

function domarquescroll(div_id, direction, speed, rate, distance, pause)
{
 var hull=document.getElementById(div_id);
 var a= hull.getElementsByTagName('ul')[0];
 var b= hull.getElementsByTagName('ul')[1];
 
// // calculate the client rect of the hull in page coordinates
// var top = hull.offsetTop + hull.clientTop;
// var bottom = hull.offsetTop + hull.clientTop + hull.clientHeight;
// var left = hull.offsetLeft + hull.clientLeft;
// var right = hull.offsetLeft + hull.clientLeft + hull.clientWidth;

 // The basic idea behind how we scroll here is that relatively
 // positioned elements STILL take up their space. We shift both
 // blocks by the same amount, and when the first one is no longer
 // visible, we reset the position. There is no visible change to
 // the user, but internally both blocks move a long way on the
 // reset. This means the first block is always first.
 // do the scroll
 if (direction == 'up')
 {
   a.myposition -= rate;
   a.style.top=a.myposition+'px';
   b.style.top=a.myposition+'px';
   if (a.myposition + a.offsetHeight <= 0)
   {
     a.style.top = '0px';
     b.style.top = '0px';
     a.myposition = 0;
   }
 }
 else if (direction == 'down')
 {
   a.myposition += rate;
   a.style.top=a.myposition+'px';
   b.style.top=(a.myposition-(a.offsetHeight * 2))+'px'; // wierd placement is to get d ABOVE c (visually)
   if (a.myposition > a.offsetHeight)
   {
     a.style.top = '0px';
     b.style.top = '0px';
     a.myposition = 0;
   }
 }
 else if (direction == 'left')
 {
   a.myposition -= rate;
   a.style.left=a.myposition+'px';
   b.style.left=(a.myposition+a.offsetWidth)+'px';
   if (a.myposition + a.offsetWidth < 0)
   {
     a.style.left = '0px';
     b.style.left = '0px';
     a.myposition = 0;
   }
 }
 else // right
 {
   a.myposition += rate;
   a.style.left=a.myposition+'px';
   b.style.left=(a.myposition-a.offsetWidth)+'px';
   if (a.myposition > a.offsetWidth)
   {
     a.style.left = '0px';
     b.style.left = '0px';
     a.myposition = 0;
   }
 }
 
 timeout = speed;
 if (distance && pause)
 {
  a.traveled += rate;
  if (a.traveled >= distance)
  {
   a.traveled = 0;
   timeout = pause;
  }
 }
 
 a.myinterval = setTimeout('domarquescroll("' + div_id + '", "' + direction + '", ' + speed + ', ' + rate + ', ' + distance + ', ' + pause + ')',timeout);
}

