//NEWS SCROLLER SCRIPT

var w3c = (document.getElementById) ? 1:0
var ns4 = (document.layers) ? 1:0
var ie4 = (document.all) ? 1:0

var range = "";
var cap = "";
var mutex = 0;
var yplace = 0;
var ymax = 0;
var ymin = 0;
var xplace = 0;
var newsHeight = 0;
var docHeight = 0;
var doAutoScroll = true;


/** The only code you should ever need to change here are the following vars **/
var startPause = 4000 // 1 second = 1000
var endPause = 7000
var speed = 3; 
var autoSpeed = 0.3;                        //speed at which the news scrolls
var newsId = "news";                   //name of the overall news div
var newsClipId = "newsClipping";       //name of the news clipping div
// ----------------------------

function redrawScreen() {
  location.reload();
  return false
}

function shiftTo(obj, x, y) {
  if (w3c) {
    obj.style.left = x + "px";
    obj.style.top = y + "px";
  }
  else if (ns4) {
	 obj.moveTo(x,y);
  } 
  else if (ie4) {
    obj.style.pixelLeft = x;
	obj.style.pixelTop = y;
  }
}

function getObject(obj) {
	var theObj = eval("document." + range + obj + cap);
	return theObj;
} 

function scrollUp() {
if (doAutoScroll==false) {
  if (mutex == 1){
    var theObj = getObject(newsId);
    if (yplace < ymax) {
      yplace = yplace + speed;
      if (yplace > ymax) yplace = ymax;
      shiftTo(theObj, xplace, yplace);
      setTimeout("scrollUp()",25);
    }
  }
}
}
  
function scrollDown() {
if (doAutoScroll==false) {
  if (mutex == 2){
    var theObj = getObject(newsId);
    if (yplace > ymin) {
      yplace = yplace - speed;
      //if (yplace < ymin) yplace = ymin;
	  if (yplace <= (ymin)) {
	  setTimeout("doLoop()",endPause);
	  //yplace = 0; //0; // alert('end') //yplace = -1000; //
	  return;
	  }
	  shiftTo(theObj, xplace, yplace);
      setTimeout("scrollDown()",25);
    }
  }
}
}


function autoScroll() {
if (beginTO) clearTimeout(beginTO);
if (doAutoScroll==true) {
    var theObj = getObject(newsId);
	if (yplace <= (ymin)) {
	 // alert('at end..ready for new loop');
	  setTimeout("doLoop()",endPause);
	  return;
	  }else{
    if (yplace > ymin) {
      yplace = yplace - 0.3; // autoSpeed;
      //if (yplace < ymin) yplace = ymin;
	  
	  }
	  shiftTo(theObj, xplace, yplace);
      TO = setTimeout("autoScroll()",25);
    }
}
}

function killAutoScroll(){
        clearTimeout(TO);
}





function doLoop() {
//alert('Doing Loop');
var theObj = getObject(newsId);
if (doAutoScroll==true){
if (yplace <= (ymin)) {
yplace = 0;
shiftTo(theObj, xplace, yplace);
}
//speed = 1;
setTimeout("restart()",startPause);
}}
function restart(){
doAutoScroll=true;
speed = autoSpeed; // ??
autoScroll();
}

function scrollIt(msg, dir) {
speed = 3;
doAutoScroll = false;
  window.status = msg; 
  mutex = dir;
  if (mutex == 1) scrollUp();
  else if (mutex == 2) scrollDown();
}

function init() {
  if (w3c) {
    range = "getElementById(\"";
    cap = "\")";
    theObj = getObject(newsClipId);
	theObj2 = getObject(newsId);
    newsHeight = parseInt(theObj.offsetHeight);
	docHeight = parseInt(theObj2.offsetHeight);
    theObj = getObject(newsId);
    ymin = (parseInt(theObj.offsetHeight) - newsHeight) * -1 -20// -(docHeight/2);
  }
  else if (ns4) {
    window.captureEvents(Event.RESIZE);
    window.onresize = redrawScreen;
    theObj = getObject(newsClipId);
	theObj2 = getObject(newsId);
    newsHeight = theObj.clip.height;
	docHeight = theObj2.clip.height;
    newsId = newsClipId + ".document." + newsId;
    theObj = getObject(newsId);
    ymin = (theObj.clip.height - newsHeight) * -1 -20// -(docHeight/2);
  }
  else if (ie4) {
    range = "all.";
    theObj = getObject(newsClipId);
	theObj2 = getObject(newsId);
    newsHeight = theObj.offsetHeight;
	docHeight = theObj2.offsetHeight;
    theObj = getObject(newsId);
    ymin = (theObj.offsetHeight - newsHeight) * -1 -20// -(docHeight/2);
  }
  speed = 1;
  beginTO = setTimeout("autoScroll()",startPause);
}
// END OF NEWS SCROLLER SCRIPT  
