// Load multiple functions on window onload and onresize
// Source: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent (func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// Javascript for drop down menu, only needed for IE. Taken from: http://www.htmldog.com/articles/suckerfish/dropdowns/
sfHover = function() {
	var sfEls = document.getElementById("primary-navigation").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"), "");
		}
	}
}

// Attach event for IE only
if (window.attachEvent) {
	addLoadEvent(sfHover);
}


// Select box navigation
function selectNavigation () {
    if (!document.getElementById) return false; 
    
    // Loop through all select tags
    var selectTags = document.getElementsByTagName('select');
    for (i = 0; i < selectTags.length; i++) {
        selectTag = selectTags[i];
        if (selectTag.className == 'selectNav') {
            
            // Add select nav functionality
            selectTag.onchange = function() {
                // Ensure we have a URL, and redirect to it
                var destination = selectTag[selectTag.selectedIndex].value;
                if (destination.indexOf('http://') == 0) {
                    location.href = destination;
                }
            }
        }
    }
    
    // Hide submit button
    var submitTag = document.getElementById('selectNavSubmit');
    submitTag.style.display = 'none';
}

addLoadEvent(selectNavigation);