//Add Load Events to the onload property

function addLoadEvent(func) {

  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
	
    window.onload = func;
    
  } else {
	
    window.onload = function() {
  	  oldonload();
  	  func();
  	}
  	
  }
}

//Toggle dummy text for searches
function search() {
    
    if($('search_field')) {

        $('search_field').onfocus = function() {
  			
  			// if already cleared, do nothing
			if (this._cleared) return
			
			  // when this code is executed, "this" keyword will in fact be the field itself
			  this.clear()
			  this._cleared = true
		}
		
	}

}

//attach events on mouseover/mouseout
sfHover = function() {
 
    if($("nav")) { 
    
        var sfEls = $("nav").getElementsByTagName("li");
        nodes = $A(sfEls);   
        
        nodes.each(function(node){
            node.onmouseover = function() { this.className+= " sfhover"; };
            node.onmouseout = function() { this.className = this.className.replace(new RegExp("sfhover+"), ""); };
	    });  
    
    }
    
}

/*
*
*   The ucwords function is a JS replication of the PHP fucntion
*   Edward Lynn
*/
function ucwords( str ) {
    return str.replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase ( ); } );
}

/*
*
*   The ucfirst function is a JS replication of the PHP fucntion 
*
*/
function ucfirst( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: ucfirst('kevin van zonneveld');
    // *     returns 1: 'Kevin van zonneveld'
 
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1, str.length-1);
}

/*
*
*   Count and trim user entered copy within a
*   textarea form field.
*/
function textCounter(elm, countfield, maxlimit) {
    if (elm.value.length > maxlimit) 
        // trim excess chars.
        elm.value = elm.value.substring(0, maxlimit);
    else 
        countfield.value = maxlimit - elm.value.length;
}

FastInit.addOnLoad(search,sfHover);
//addLoadEvent(sfHover);  




