// 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();
    }
  }
}

/**
 * Populate the search field
 * ---------------------------------------------------------------------------
 */
function populateSearchFieldText (field_id, label) {
    if (!document.getElementById) return false;
    
    // On startup copy label text to field
    var field = document.getElementById(field_id);
    field.value = label;
    
    // On focus blank out field if label text is value
    field.onfocus = function () {
        if (this.value == label) {
			this.value = '';
        }
    }
    
    // On blur copy label text if value is blank
    field.onblur = function () {
        if (this.value == '') {
			this.value = label;
        }
    }
}

// Load functions at startup
addLoadEvent(function(){
    populateSearchFieldText('search', 'Search');
});


/**
 * Javascript drop down menu (for IE6)
 * Taken from: http://www.htmldog.com/articles/suckerfish/dropdowns/
 * ---------------------------------------------------------------------------
 */
sfHover = function() {
        var sfEls = document.getElementById("nav-primary").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);
}
