// JavaScript Document
//// *********************************** ////
////   Saint Joseph School Main Webpage  ////
////            Version 1.00             ////
////       Last Updated 05/01/2010       ////
////                                     ////
//// *********************************** ////

// The following javascript functions are used to display a horizontal scrolling text box.
//---------------------------------------------------------------------------------------------------------
// Messages
//---------------------------------------------------------------------------------------------------------

var hscrollerEntries = new Array(
  "Welcome to the St. Joseph School website.",
  "Parent Club meetings are at 6PM on the first friday of each month.",
  "FACTS on-line enrollment option is now avaliable for our new families, see the Tution & Fees section of our site for more information."

);

//---------------------------------------------------------------------------------------------------------
// Settings
//---------------------------------------------------------------------------------------------------------

var hscrollerWidth = 435;                               		// width (pixels)
var hscrollerMargin = 2;                                		// margin (pixels)
var hscrollerDelay = 40;                                		// scrolling delay (smaller = faster)
var hscrollerSpacer = "...........";                    		// spacer between hscroller entries

var hscrollerBGColor = "#7788aa";                       		// background color
var hscrollerHLColor = "#cc9900";                       		// hilight (mouse over) color

var hscrollerFont = "Verdana, Arial, Helvetica, sans-serif";	// font family (CSS-spec)
var hscrollerFontSize = 12;                             		// font size (pixels)
var hscrollerFontColor = "white";                       		// font color

var hscrollerBorderWidth = 1;                           		// border width (pixels)
var hscrollerBorderStyle = "solid";                    			// border style (CSS-spec)
var hscrollerBorderColor = "#cc9900";                   		// border color

//---------------------------------------------------------------------------------------------------------
// JavaScript Functions
//---------------------------------------------------------------------------------------------------------

var DOM = document.getElementById;
var IE4 = document.all;

var hscrollerIV, hscrollerID;
var hscrollerItems = new Array();
var hscrollerHeight = hscrollerFontSize + 5;

function hscrollerGetObj(id) {
  if(DOM) return document.getElementById(id);
  else if(IE4) return document.all[id];
  else return false;
}

function hscrollerObject(id) {
  this.elem = hscrollerGetObj(id);
  this.width = this.elem.offsetWidth;
  this.x = hscrollerWidth;
  this.css = this.elem.style;
  this.css.width = this.width + 'px';
  this.css.left = this.x + 'px';
  this.move = false;
  return this;
}

function hscrollerNext() {
  if(!DOM && !IE4) return;
  var obj = hscrollerItems[hscrollerID];
  if(!obj.move) {
    obj.x = hscrollerWidth;
    obj.css.left = hscrollerWidth + 'px';
    obj.move = true;
  }
}

function hscrollerMove() {
  if(!DOM && !IE4) return;
  for(var i = 0; i < hscrollerItems.length; i++) {
    if(hscrollerItems[i].move) {
      if(hscrollerItems[i].x > -hscrollerItems[i].width) {
        hscrollerItems[i].x -= 2;
        hscrollerItems[i].css.left = hscrollerItems[i].x + 'px';
      }
      else hscrollerItems[i].move = false;
    }
  }
  if(hscrollerItems[hscrollerID].x + hscrollerItems[hscrollerID].width <= hscrollerWidth) {
    hscrollerID++;
    if(hscrollerID >= hscrollerItems.length) hscrollerID = 0;
    hscrollerNext();
  }
}

function hscrollerStart(init) {
  if(!DOM && !IE4) return;
  if(hscrollerBGColor) {
    var obj = hscrollerGetObj('divhscroller');
    obj.style.backgroundColor = hscrollerBGColor;
  }
  if(init) {
    hscrollerID = 0;
    hscrollerNext();
  }
  hscrollerIV = setInterval('hscrollerMove()', hscrollerDelay);
}

function hscrollerStop() {
  if(!DOM && !IE4) return;
  clearInterval(hscrollerIV);
  if(hscrollerHLColor) {
    var obj = hscrollerGetObj('divhscroller');
    obj.style.backgroundColor = hscrollerHLColor;
  }
}

function hscrollerInit() {
  if(!DOM && !IE4) return;
  for(var i = 0; i < hscrollerEntries.length; i++) {
    hscrollerItems[i] = new hscrollerObject('divhscrollerEntry' + (i+1));
  }
  var obj = hscrollerGetObj('divhscroller');
  obj.style.width = hscrollerWidth + 'px';
  obj.style.visibility = 'visible';
  hscrollerStart(true);
}

function hscrollerReload() {
  if(!DOM && !IE4) return;
  document.location.reload();
}

window.onresize = hscrollerReload;
window.onload = hscrollerInit;

//---------------------------------------------------------------------------------------------------------
// Construct hscroller
//---------------------------------------------------------------------------------------------------------

document.write('<style> ' +
               '#divhscroller { ' +
               'position: absolute; ' +
               'width: 10000px; ' +
               'height: ' + hscrollerHeight + 'px; ' +
               'cursor: default; ' +
               'overflow: hidden; ' +
               'visibility: hidden; ' +
               (hscrollerBorderWidth ? 'border-width: ' + hscrollerBorderWidth + 'px; ' : '') +
               (hscrollerBorderStyle ? 'border-style: ' + hscrollerBorderStyle + '; ' : '') +
               (hscrollerBorderColor ? 'border-color: ' + hscrollerBorderColor + '; ' : '') +
               '} ' +
               '.csshscrollerContainer { ' +
               'position: relative; ' +
               'height: ' + hscrollerHeight + 'px; ' +
               'margin-top: ' + hscrollerMargin + 'px; ' +
               'margin-bottom: ' + hscrollerMargin + 'px; ' +
               '} ' +
               '.csshscrollerEntry { ' +
               'font-family: ' + hscrollerFont + '; ' +
               'font-size: ' + hscrollerFontSize + 'px; ' +
               'color: ' + hscrollerFontColor + '; ' +
               '} ' +
               '</style>');

document.write('<div class="csshscrollerContainer">' +
               '<div id="divhscroller" onMouseOver="hscrollerStop()" onMouseOut="hscrollerStart()">');

for(var i = 0; i < hscrollerEntries.length; i++) {
  document.write('<div id="divhscrollerEntry' + (i+1) + '" class="csshscrollerEntry" ' +
                 'style="position:absolute; top:2px; white-space:nowrap">' +
                 hscrollerEntries[i] + ((hscrollerEntries.length > 1) ? ' ' + hscrollerSpacer + '&nbsp;' : '') +
                 '</div>');
}
document.write('</div></div>');


