// Initializer
  function init() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;
    iRotate.init();
    if (hasClass(document.getElementsByTagName("body")[0], 'section-admin')) doFocus(0);
    else doFocus(1);
  }
  if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
  }
  if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
          clearInterval(_timer);
          init();
        }
    }, 10);
  }
  /*@cc_on @*/
  /*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      init(); // call the onload handler
    }
  };
  /*@end @*/
  window.onload = init;

// Push Rotation
  var iRotate = function() {
    var pushes = new Array();
    var pushesCreated = 0;
    var lastPush = -1;
    var currentPush = -1;
    var nextPush = 0;
    var rotation;
    return {
      init: function() {
        try {
          if (document.getElementById("rotation")) {
            if (pushes.length>0) iRotate.go();
            if (pushes.length>1) rotation = window.setInterval('iRotate.go()', 10000);
          }
        } catch(e) {}
      },
      startOn: function(iPush) {
        lastPush = iPush-1;
        currentPush = iPush-1;
        nextPush = iPush;
      },
      addPush: function(imageURL, destinationURL, altText) {
        next = pushes.length;
        pushes[next] = { 'image': imageURL, 'link': destinationURL, 'text': altText };
      },
      go: function() {
        pushElement = document.getElementById("rotation");
        pushCount = pushes.length;
        if (pushesCreated!=1) {
          for (iPush=0; iPush<pushCount; iPush++) {
            var pushAnchor = document.createElement("a");
                pushAnchor.setAttribute("id", "push-"+iPush);
                pushAnchor.setAttribute("href", pushes[iPush]['link']);
                pushAnchor.style.display = 'none';
                pushAnchor.style.opacity = '0';
            var pushImg = document.createElement("img");
                pushImg.setAttribute("src", pushes[iPush]['image']);
                pushImg.setAttribute("alt", pushes[iPush]['text']);
                pushImg.style.display = 'block';
                pushImg.style.marginLeft = 'auto';
                pushImg.style.marginRight = 'auto';
                pushImg.style.width = '950px';
                pushImg.style.height = '230px';
                pushAnchor.appendChild(pushImg);
                pushElement.appendChild(pushAnchor);
            var controller = document.getElementById("rotate-to-"+iPush).getElementsByTagName("a")[0];
            controller.setAttribute("onclick", "iRotate.goTo("+iPush+"); return false;");
          }
          pushesCreated = 1;
          var pushMainAnchor = document.createElement("a");
              pushMainAnchor.setAttribute("id", "push-clicker");
              pushElement.appendChild(pushMainAnchor);
        }
        useOld = 0;
        if (pushCount>1 && currentPush!=-1) useOld = 1;
        if (nextPush>pushCount-1) nextPush = 0;
        try {
          document.getElementById("push-"+nextPush).style.zIndex = 2;
        } catch(e) {
          var pushAnchor = document.createElement("a");
              pushAnchor.setAttribute("id", "push-"+nextPush);
              pushAnchor.setAttribute("href", pushes[nextPush]['link']);
              pushAnchor.style.display = 'block';
              pushAnchor.style.visibility = 'hidden';
              pushAnchor.style.opacity = '0';
              pushAnchor.style.position = 'absolute';
              pushAnchor.style.top = '0';
          var pushImg = document.createElement("img");
              pushImg.setAttribute("src", pushes[nextPush]['image']);
              pushImg.setAttribute("alt", pushes[nextPush]['text']);
              pushImg.style.display = 'block';
              pushImg.style.marginLeft = 'auto';
              pushImg.style.marginRight = 'auto';
              pushImg.style.width = '951px';
              pushImg.style.height = '464px';
              pushAnchor.appendChild(pushImg);
              pushElement.appendChild(pushAnchor);
        }
        try {
          deadPush = document.getElementById("push-"+lastPush);
          deadPush.style.display = 'none';
        } catch(e) {}
        if (useOld) {
          oldPush = document.getElementById("push-"+currentPush);
          oldPush.style.zIndex = 1;
        }
        newPush = document.getElementById("push-"+nextPush);
        newPush.style.zIndex = 2;
        setOpacity(newPush, 0);
        newPush.style.display = 'block';
        newPush.style.visibility = 'visible';
        fadeIn("push-"+nextPush, 0, 100, 10);
        pushClicker = document.getElementById("push-clicker");
        pushClicker.setAttribute("href",  newPush.getAttribute("href"));
        lastPush = currentPush;
        currentPush = nextPush;
        nextPush = currentPush+1;
        try {
          removeClass(document.getElementById("rotate-to-"+lastPush), "selected");
        } catch(e) {}
        try {
          addClass(document.getElementById("rotate-to-"+currentPush), "selected");
        } catch(e) {}
      },
      goTo: function(iPush) {
        if (iPush!=currentPush) {
          clearInterval(rotation);
          nextPush = iPush;
          iRotate.go();
          var controllers = document.getElementById("rotation-controls").getElementsByTagName("li");
          for (iControl=0; iControl<controllers.length; iControl++) {
            if (hasClass(controllers[iControl], "selected")) removeClass(controllers[iControl], "selected");
            if (iControl==iPush) addClass(controllers[iControl], "selected");
          }
          if (pushes.length>1) rotation = window.setInterval('iRotate.go()', 10000);
        }
      }
    }
  }();

// Object Cache
  var objects = new Array();

// Opacity
  function setOpacity(obj, opacity) {
    obj.style.filter = 'alpha(opacity:'+opacity+')';
    obj.style.KHTMLOpacity = opacity/100;
    obj.style.MozOpacity = opacity/100;
    obj.style.opacity = opacity/100;
  }
  function fadeIn(objId, start, end, speed) {
    if (!objects[objId]) objects[objId] = document.getElementById(objId);
    obj = objects[objId];
    if (start>end) {
      setOpacity(obj, end);
    } else {
      setOpacity(obj, start);
      start+= speed;
      window.setTimeout("fadeIn('"+objId+"', "+start+", "+end+", "+speed+")", 50);
    }
  }

// Classes
  function hasClass(obj, className) {
    return obj.className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'));
  }
  function addClass(obj, className) {
    if (!this.hasClass(obj, className)) obj.className += " "+className;
  }
  function removeClass(obj, className) {
    if (hasClass(obj, className)) {
      var reg = new RegExp('(\\s|^)'+className+'(\\s|$)');
      obj.className=obj.className.replace(reg, ' ');
    }
  }

// Form Focus
  function doFocus(form) {
    try {
      var formNodes = document.getElementsByTagName("form")[form].getElementsByTagName("fieldset")[0].getElementsByTagName("*");
      for (var i=0; i<formNodes.length; i++) {
        if ((formNodes[i].tagName=='input' && formNodes[i].getAttribute("type")!='hidden') || formNodes[i].tagName=='textarea' || formNodes[i].tagName=='select') {
          formNodes[i].focus();
          i = formNodes.length;
        }
      }
    } catch(e) {}
  }

// Form Input
  function caseThis(element) {
    var required = '1';
    if (arguments.length>1) required = arguments[1];
    var inputParts = element.value.split(' ');
    var output = '';
    for (var i=0; i<inputParts.length; i++) {
      if (i!=0) output+= ' ';
      output+= inputParts[i].substring(0, 1).toUpperCase();
      var noCapsLock = inputParts[i].substring(1);
      if (noCapsLock.length>1) {
        if (noCapsLock==noCapsLock.toUpperCase()) noCapsLock = noCapsLock.toLowerCase();
      }
      output+= noCapsLock;
    }
    if (required=='0' || (required=='1' && output.length!=0)) removeClass(element.parentNode, 'flag');
    else addClass(element.parentNode, 'flag');
    element.value = output;
  }
  function upperThis(element) {
    var valueLength = '0';
    if (arguments.length>1) valueLength = arguments[1];
    var output = element.value.toUpperCase();
    if (valueLength=='0' || (valueLength!='0' && output.length==valueLength)) removeClass(element.parentNode, 'flag');
    else addClass(element.parentNode, 'flag');
    element.value = output;
  }
  function postalThis(element) {
    var postal = element.value.replace(/[^0-9]/g, '');
    var output = '';
    if (postal.length==5 || postal.length==9) {
      if (postal.length==5) output = postal;
      if (postal.length==9) output = postal.substring(0, 5)+'-'+postal.substring(5, 9);
      removeClass(element.parentNode, 'flag');
    }
    else {
      output = postal;
      addClass(element.parentNode, 'flag');
    }
    element.value = output;
  }
  function phoneThis(element) {
    var phone = element.value.replace(/[^0-9]/g, '');
    var output = '';
    if (phone.length==10) {
      output = phone.substring(0, 3)+'-'+phone.substring(3, 6)+'-'+phone.substring(6, 10);
      removeClass(element.parentNode, 'flag');
    }
    else {
      output = phone;
      addClass(element.parentNode, 'flag');
    }
    element.value = output;
  }
  function emailThis(element) {
    var email = element.value;
    var valid = 1;
    var at_parts = email.split('@');
    if (at_parts.length!=2 || at_parts[0]=='' || at_parts[1]=='') valid = 0;
    else {
      var domain_parts = at_parts[1].split('.');
      if (domain_parts.length<2 || domain_parts[0]=='' || domain_parts[1]=='') valid = 0;
    }
    if (valid==1) removeClass(element.parentNode, 'flag');
    else addClass(element.parentNode, 'flag');
    var output = email.toLowerCase();
    element.value = output;
  }
  function requireThis(element) {
    if (element.value!='') removeClass(element.parentNode, 'flag');
    else addClass(element.parentNode, 'flag');
  }
