/*
 * Autopopulate search fields with labels
 *
 * Copy the value of an input field's title attribute to its value attribute.
 * Clear the input field on focus if its value is the same as its title.
 * Repopulate the input field on blur if it is empty.
 * Hide the input field's associated label if it has one.
 */
var autoPopulate = {
	sInputClass:'populate', // Class name for input elements to autopopulate
	sHiddenClass:'structural', // Class name that gets assigned to hidden label elements
	bHideLabels:true, // If true, labels are hidden
	/**
	 * Main function
	 */
	init:function() {
		// Check for DOM support
		if (!document.getElementById || !document.createTextNode) {return;}
		// Find all input elements with the given className
		var arrInputs = $$('input.' + autoPopulate.sInputClass + "[type=text]");
		var iInputs = arrInputs.length;
		var oInput;
		arrInputs.each(function(oInput) {
			if (autoPopulate.bHideLabels) { autoPopulate.hideLabel(oInput.id); } // Hide the input's label
			
			// If value is empty and title is not, assign title to value
			if ((oInput.value == '') && (oInput.title != '')) { oInput.value = oInput.title; }
			// Add event handlers for focus and blur
			Event.observe(oInput, 'focus', function() {
				// If value and title are equal on focus, clear value
				if (this.value == this.title) {
					this.value = '';
					this.select(); // Make input caret visible in IE
				}
			});
			Event.observe(oInput, 'blur', function() {
				// If the field is empty on blur, assign title to value
				if (!this.value.length) { this.value = this.title; }
			});
		});
	},
	hideLabel:function(sId) {
		var arrLabels = document.getElementsByTagName('label');
		var iLabels = arrLabels.length;
		var oLabel;
		for (var i=0; i<iLabels; i++) {
			oLabel = arrLabels[i];
			if (oLabel.htmlFor == sId) {
				oLabel.className = oLabel.className + ' ' + autoPopulate.sHiddenClass;
			}
		}
	}

};

document.observe("dom:loaded", autoPopulate.init);

// Requires Prototype 1.6+
document.observe("dom:loaded", function() {
  $$('.shock_block').each(function(elm) {
  	if(elm.shocked) return;
  	var cover 	= elm.down(0);
  	var content = elm.down(1);
  	elm.observe('mouseover', function(){  cover.hide(); content.setStyle({ visibility: 'visible' }); });
  	elm.observe('mouseout',  function(){ cover.show(); content.setStyle({ visibility: 'hidden' }); });
  	elm.shocked = true;
  });
});