/**
 * Labels to input captions
 *
 * @author Geoff Oliver <geoff@plan8studios.com> for Fourthdoor Creative
 * @version 1.0
 */

caps = [];

function labels_to_captions(){
	// setup some vars
	var TO_CAPTION_CLASSNAME = 'as_caption';
	
	// first we need to grab all the label elements
	var labels = $ES('label');
	
	// now let's figure out which ones to move into a caption
	for(var l = 0; l < labels.length; l++){
		var lbl = labels[l];
		if(lbl.className == TO_CAPTION_CLASSNAME){
			var el = $(lbl.htmlFor);
			caps[lbl.htmlFor] = lbl.innerHTML;
			el.addEvent('focus',function(){
				if(this.value == caps[this.id] && this.className == 'field_blur'){
					this.value = ''; 
					this.className = 'field_focus'; 
				}
			});
			el.addEvent('blur',function(){
				if(this.value.replace(/^[\s]*/,'').replace(/[\s]*$/,'') == ''){
					this.value = caps[this.id];
					this.className = 'field_blur';
				}
			});
			el.className = 'field_blur';
			el.value = lbl.innerHTML;
			lbl.parentNode.removeChild(lbl);
		}
	}
}