if (document.getElementById) { // modern check


/*
	CONFIGS =================================
*/

	// config:  pop-up defaults
	var popClass = "popup";
	var popName	= "popWin";
	var popPrefix = "pup-";
	var popW	= 400;
	var popH	= 300;
	
	// config:  magic labels
	var magicLabelClass 	= 'dynLabel';

/*
	END config ----------------------
*/



/*
	UTILITIES =================================
*/
	
	/**
	 * addEvent
	 * Non-destructively attach a function to any event.
	 * @example	addEvent(window, 'load', functionName);
	*/
	if (typeof addEvent == 'undefined') {
		function addEvent(obj, evType, fn) {
			if (obj.addEventListener){
				obj.addEventListener(evType, fn, true);
				return true;
			} else if (obj.attachEvent){
				var r = obj.attachEvent("on"+evType, fn);
				return r;
			} else {
				return false;
			}
		}
	}
	
	
/*
	END Utilities -----------
*/



/*
	FUNCTIONS ============================
*/


	/**
	 * popupHandler();
	 * Pop-up window launch handler. Keys off of specified CSS class.
	*/
	function popupHandler() { 
		var cl=popClass.length;
		var a=document.getElementsByTagName("a");
		for(var i=0; i<a.length; i++) { 
			var ca=document.getAttribute?a[i].getAttribute("class").split(" "):a[i].className.split(" ");
			if(ca[0]===popClass) { 
				a[i].onclick=function () { 
					var w = popW;  var h = popH; var s='';
					var ca2=document.getAttribute ? this.getAttribute("class").split(" ") : this.className.split(" ");
					for (var i=0; i<ca2.length; i++) {
						if (ca2[i].substring(0,popPrefix.length) === popPrefix) {
							var aaa = ca2[i].substring(popPrefix.length,ca2[1].length);
							c = aaa.split("_");
							for (var z=0; z<c.length; z++) {
								if (c[z].substring(0,1)=='w') { w = c[z].substring(1,c[z].length); }
								else if (c[z].substring(0,1)=='h') { h = c[z].substring(1,c[z].length); }
								else { s += c[z] +"=1,"; }
							}					
						}
					}
					var t=this.getAttribute("target")?this.getAttribute("target"):popName;
					popUp(this.getAttribute("href"),t,w,h,s);
					return false;
				}
			}
		}
	}
	
	/**
	* popUp();
	* Pop-up window launcher.
	*/
	function popUp(winURL,t,w,h,s){
		var specs="width="+w+",height="+h+",";
		if (s && s!='') { specs += s; }
		var scrX=Math.round((screen.width/2)-(w/2));
		var scrY=Math.round((screen.height/2)-(h/2));
		if(scrY>100){ scrY=scrY-40; }
		specs+='top='+scrY+',left='+scrX;
		var win=window.open(winURL,t,specs);
		win.focus();
	}



	
	function initOverlabels() {
		setTimeout(overLabels, 50);
	}
	
	function overLabels () {
		// source:  http://alistapart.com/articles/makingcompactformsmoreaccessible
	
	  var labels, id, field;

	  // Set focus and blur handlers to hide and show 
	  // LABELs with 'overlabel' class names.
	  labels = document.getElementsByTagName('label');
	  for (var i = 0; i < labels.length; i++) {
		
	    if (labels[i].className == 'overlabel') {
	
	      // Skip labels that do not have a named association
	      // with another field.
	      id = labels[i].htmlFor || labels[i].getAttribute('for');
	      if (!id || !(field = document.getElementById(id))) {
	        continue;
	      }
	
	      // Change the applied class to hover the label 
	      // over the form field.
	      labels[i].className = 'overlabel-apply';
	
	      // Hide any fields having an initial value.
	      if (field.value !== '') {
	        hideLabel(field.getAttribute('id'), true);
	      }
	
	      // Set handlers to show and hide labels.
	      field.onfocus = function () {
	        hideLabel(this.getAttribute('id'), true);
	      };
	      field.onblur = function () {
	        if (this.value === '') {
	          hideLabel(this.getAttribute('id'), false);
	        }
	      };
	
	      // Handle clicks to LABEL elements (for Safari).
	      labels[i].onclick = function () {
	        var id, field;
	        id = this.getAttribute('for');
	        if (id && (field = document.getElementById(id))) {
	          field.focus();
	        }
	      };
	
	    }
	  }
	};
	
	function hideLabel (field_id, hide) {
	  var field_for;
	  var labels = document.getElementsByTagName('label');
	  for (var i = 0; i < labels.length; i++) {
	    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
	    if (field_for == field_id) {
	      labels[i].style.display = (hide) ? 'none' : 'block';
	      return true;
	    }
	  }
	  return false;
	}
	


		
	

	// for nav menus
	sfHover = function() {
		var navSiteElement = $$( '#nav ul' )[ 0 ];
		if ( !( navSiteElement ) ) {
			return;
		}
		var sfEls = navSiteElement.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover = function() {
				if (this.getAttribute && this.getAttribute( "class" ) ) {
					this.setAttribute( "class", this.getAttribute("class") + " sfhover" );
				}
				else {
					this.className += " sfhover";
				}
			}
			sfEls[i].onmouseout=function() {
				if (this.getAttribute('class')) {
					this.setAttribute( 'class', this.getAttribute('class').replace( new RegExp(" sfhover\\b"), "" ) );
				} else {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		}
	}

	


//	ONLOAD INITS ==================================

	addEvent(window,'load',initOverlabels);
	addEvent(window,'load',popupHandler);

// -------------------------------
} // close modern check