// © Dow Digital 2001 
// this has been modified to include start stop functionality 
// from the titles in the scrolling news. the function needed 
// to be addressed is 
// startMouseout () starts the scrolling  and 
// stopMouseover () stops the scrolling
// Inclusion 26-9-2000 Michael Fewings

var ns4;
var ie;
var ns6;
var scrollMargin    = 15;
var scrollPos       = 0;        // Current position of scroll
var scrollStep      = 1;        // Size of scrolling step
var scrollSpeedStep = 100;      // Size of jump
var currentScroll   = null;     // Is the panel currently scrolling?
var continueFlag    = false;
var scrollEnable    =true;
var continuous      = false;
var loader = window;
var menuLoc = window;
var isLoaded = false;
var NSresized = false;
var oldDirection;
var oldType;
//var minscroll;
//var maxscroll;
//var boxheight;



// browser identification
var browser = navigator.appName;
var version = parseInt(navigator.appVersion);
     ns4 = (browser=="Netscape" && version == 4) ? true : false;
     ie = (browser.match("Microsoft")) ? true : false;
     ns6 = (browser=="Netscape" && version == 5) ? true : false;
if(ns4){
   origWidth = loader.innerWidth;
   origHeight = loader.innerHeight;
   loader.onresize = reDo;
}

// Initialise all variables / layer positioning etc. A call to this function should be placed
// in the 'onLoad' event of the body tag in the page which contains the scrolling panel.
function init(scrollType,scrollStart,scrollSpeed)
{
   continuous = (scrollType=="continuous");
//   document.onmouseup = toggleScroll;
//   if (ns4) document.captureEvents(Event.MOUSEUP);

   if (ie)
   {
      scrolldiff = ScrollArea.scrollHeight-BoxArea.offsetHeight;
      boxheight  = BoxArea.offsetHeight;
      if (continuous)
      {
         maxscroll = ScrollArea.scrollHeight;
         minscroll = 0 - boxheight;
      }
      else
      {
         maxscroll = ScrollArea.scrollHeight-boxheight+100;
         minscroll = 0;
      }

   }
   if (ns4)
   {
      scrolldiff = document.layers['BoxArea'].document.layers['ScrollArea'].document.height-document.layers['BoxArea'].clip.height;
      boxheight  = document.layers['BoxArea'].clip.height;
      if (continuous)
      {
         maxscroll = document.layers['BoxArea'].document.layers['ScrollArea'].document.height;
         minscroll = 0 - boxheight;
      }
      else
      {
         maxscroll = document.layers['BoxArea'].document.layers['ScrollArea'].document.height-boxheight+100;
         minscroll = 0;
      }
   }
   if (ns6)
   {
	  ElementScroll=document.getElementById("ScrollArea");
	  ElementBox=document.getElementById("BoxArea");
      boxheight  = parseInt(ElementBox.offsetHeight);
      scrolldiff = parseInt(ElementScroll.offsetHeight)-boxheight;
      if (continuous)
      {
		 maxscroll = scrolldiff;
         minscroll = parseInt(0 - boxheight);
      }
      else
      {
         maxscroll = parseInt(ElementBox.style.scrollHeight-boxheight+100);
         minscroll = 0;
      }
   }

   // Work out if we need to display the navigation buttons...
   if (scrolldiff > 0)
   {
      scrollEnable=true;
      // Set the scroller so that it starts scrolling straight away
      if (scrollStart > 0)
         setTimeout("movePanel('down','slide');",scrollStart);
   }
}

function startMouseout ()
{

	if (running==0 && oldType=="slide")
	{
		setTimeout("movePanel('"+oldDirection+"', '"+oldType+"');", scrollSpeedStep +1);
	}
}

function stopMouseover ()
{
   continueFlag=false;
   currentScroll=false;
   running=0;
}

function toggleScroll()
{
   if (!continueFlag) currentScroll=false;
   continueFlag=false;
   currentScroll=false;
   oldDirection=null;
   oldType=null;

}

function movePanel(direction, type)
{
   if (scrollEnable)
   {
      continueFlag=true;
      if ((currentScroll==direction) && (type=="slide"))
      {
         currentScroll=null;
      }
      else
      {
         currentScroll=direction;
         scrollExec(direction, type);
      }
   }
}

function scrollExec(direction, type)
{
   if (currentScroll==direction)
   {
	  if (type=="slide")
	  {
		oldDirection=direction;
		oldType=type;
	  }
	  else {
		oldDirection=null;
		oldType=null;
	  }
	  if ((type=="slide") && (currentScroll))
      {
         setTimeout("scrollExec('"+direction+"', '"+type+"');", scrollSpeedStep);
		 running=1;
      }
      else currentScroll=null;

      if (type=="jump") delta=boxheight-scrollMargin;
      else delta=scrollStep;
      if (direction=="up") delta=-delta;
      scrollPos+=delta;
      //if (scrollPos < 0) scrollPos=0;
      if (scrollPos < minscroll)
      {
         if (continuous)
            scrollPos=maxscroll;
         else
            scrollPos=minscroll;
      }


      if (scrollPos > maxscroll)
      {
         if (continuous)
            scrollPos = minscroll;
         else
            scrollPos = maxscroll;
      }
      if (ie) { ScrollArea.style.top=-scrollPos };
      if (ns4) { document.layers['BoxArea'].document.layers['ScrollArea'].top=-scrollPos };
      if (ns6) {
          ElementScroll=document.getElementById("ScrollArea");
          ElementScroll.style.top=-scrollPos;
	  }
   }
}

function reDo(){
   if (loader.innerWidth==origWidth && loader.innerHeight==origHeight) return;
   menuLoc.location.reload();
}

window.onerror = handleErr;

function handleErr(){
   arAccessErrors = ["permission","access"];
   mess = arguments[0].toLowerCase();
   found = false;
   for (i=0;i<arAccessErrors.length;i++) {
      errStr = arAccessErrors[i];
      if (mess.indexOf(errStr)!=-1) found = true;
   }
   return found;
}
