

initialize = function() {
  slideshowCheck();
  exitPage();
  openNewPage();
}

/*
dropdown menus based on son of suckerfish.

Beefed up a little by Grae to allow for multiple suckerfish drop downs within the one page, from one linked javascript.
Checks to ensure presence of element by id before attaching function.
*/
sfHover = function() {
  var sfEls = document.getElementById("utilityNav").getElementsByTagName("LI");
  for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
      this.className+=" sfhover";
    }
    sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
  }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function showElement(el) {
  var elem = document.getElementById(el);
  elem.style.display = 'block';
}

function hideElement(el) {
  var elem = document.getElementById(el);
  elem.style.display = 'none';
}

function getElement(i) {
  return document.getElementById(i);
}
function toggle(id) {
    document.getElementById(id).style.display = 
      (document.getElementById(id).style.display == 'block') ? 'none' : 'block';
  }
// Shows the element to the right of the cursor.
function showCalendarDetail(el, event) {
  var elem = document.getElementById(el);
  cursor = getPosition(event);
  elem.style.display = 'block'; 
  elem.style.left = (cursor.x + 10) + 'px';
  elem.style.top = cursor.y + 'px';

}

function getPosition(e) {
     e = e || window.event;
     var cursor = {x:0, y:0};
     if (e.pageX || e.pageY) {
         cursor.x = e.pageX;
         cursor.y = e.pageY;
     }
     else {
         cursor.x = e.clientX +
             (document.documentElement.scrollLeft ||
             document.body.scrollLeft) -
             document.documentElement.clientLeft;
         cursor.y = e.clientY +
             (document.documentElement.scrollTop ||
             document.body.scrollTop) -
             document.documentElement.clientTop;
     }
     return cursor;
}

// Checks to see if there is a div id="slideShow", if so loads the necessary 
// JavaScript, gets the category and calls the initialize function.
function slideshowCheck() {
  var category = '';
  if (document.getElementById('slideshow')) {
    var div = document.getElementById('slideshow');
    if (div.attributes['category']) {
      scriptCall(div);
      //category = div.attributes['category'].value;
      //callBack(category);
    }
  }
  function scriptCall (div) {
    var scriptArray = new Array;
    scriptArray.push("/scripts/Ajax.js");
    scriptArray.push("/scripts/AjaxUpdater.js");
    scriptArray.push("/scripts/Slideshow.js");
    for (i = 0; i < scriptArray.length; i ++) {
      script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = scriptArray[i];
      document.body.insertBefore(script, document.body.firstChild);
    }
  }
}

exitPage = function(){
// Modified by Mike Clark (July 7, 2004) to make script server independent
// 30 Aug 07, S. Clason: revisions to accomodate moving between
// two TofE domains.
//var domain = "gandolf";
//var exit = "http://gandolf:8083/index.cfm?objectID=9077AEE6-D612-00A6-A25269FA67BEEC34";
// S. Clason, 22 Jan 09: removed ci.erie.co.us from var erieDomains.

var domain = location.hostname;
var exit = "http://" + domain + "/index.cfm?objectID=5DF69634-65BD-D40A-FB3ADA29929F5E72";
var lynx = document.links;
var erieDomains = "erieco.gov, www.erieco.gov";

//alert("domain=" + domain + ", exit=" + exit);
//alert (location.href.substring(0,(exit.length)) + " =? " + exit);

if (location.href.substring(0,(exit.length)) != exit){
  for (var i = 0; i < lynx.length; i++) {
    // Only check if target is not on an TofE domain.
    if (erieDomains.indexOf(lynx[i].hostname) != -1) {
    return true;
    }
// 12-10-04 added && to condition to check if link is an email link. If email link, then we
// don't want it to use the external page creator. -- mclark
    if ((lynx[i].hostname != domain) && (lynx[i].href.indexOf("@") == -1)) {
      lynx[i].href = exit + "&target=" + lynx[i].href;
      lynx[i].target = "new";
    }
  }
 }
}

openNewPage = function() {
// Scans the page for links to other domains, attaches an onClick event handler 
// to open those links in a new browser page.

// Steve Clason, steve@steveclason.com
// 9 Jan 09  

  var links = document.getElementsByTagName("a");
  var erieDomains = 'erieco.gov, www.erieco.gov';
  for (var i = 0; i < links.length; i++) {
    if (erieDomains.indexOf(links[i].hostname) == -1) {
      //console.log("url: " + links[i].href);
      links[i].onclick = function() {
        window.open(this.href, "newWin");
        return false;
      } 
    }
  }
}
