// JavaScript Document
<!--
// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
/* switching to util.js addOnLoadHandler()
window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  sfMenu(); //init the menu handling functions
}
*/
addOnLoadHandler(function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
/* commenting out to troubleshoot IE7 menu errors
   6/11/2009 -Eric Miller
  sfMenu(); //init the menu handling functions
*/  
});
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

/* apply the hover states to menu items in all browsers but safari */
function menuHoverStyles() {
  if(navigator.userAgent.indexOf('Safari') == -1) {
    var links = new Array();
    var uls = document.getElementById('navlist').getElementsByTagName('ul')
    for(var i=0; i<uls.length; i++) {
        a = uls[i].getElementsByTagName('a')
        for(var j=0; j<a.length; j++) links.push(a[j])
    }
    for(var i=0; i<links.length; i++) {
        links[i].onmouseover = function() { this.style.color='#fff'; this.style.background = '#000099 url(/structural_images/1st-nav-arrow.gif) no-repeat 5px 50%'}
        links[i].onfocus = function() { this.style.color='#fff'; this.style.background = '#000099 url(/structural_images/1st-nav-arrow.gif) no-repeat 5px 50%'}
        links[i].onmouseout = function() { this.style.color='#333'; this.style.background = '#CED5DF'}
        links[i].onblur = function() { this.style.color='#333'; this.style.background = '#CED5DF'}
    }
    
  }
}