/*
lots of utility functions for EnergyRace
*/

//DROP SHADOWS
createDropShadows = function(){
//get the elements with the classname highContrast
var highContrast = $$('.highContrast');
	for(i = 0; i < highContrast.length; i++){
		var currentElement = highContrast[i];
		var hcContent = currentElement.firstChild.data;
		var contentSpan = document.createElement('span');
		var contentSpanText = document.createTextNode(hcContent);
		contentSpan.appendChild(contentSpanText);
		var shadowSpan = document.createElement('span');
		var shadowSpanText = document.createTextNode(hcContent);
		shadowSpan.appendChild(shadowSpanText);
		shadowSpan.className = "shadow";
		currentElement.firstChild.data = '';
		currentElement.appendChild(shadowSpan);
		currentElement.appendChild(contentSpan);
	}
}

//form focus classes
function liveLabels(){
  var inputs = $$('input');
  for(i=0; i<inputs.length; i++){
    var thisinput = inputs[i];
    thisinput.addEvent('focus', function(){
        var thisLabel = this.getPrevious();
        thisLabel.addClass('current');
        this.addClass('focus');
    });
    thisinput.addEvent('blur', function(){
         var thisLabel = this.getPrevious();
         thisLabel.removeClass('current');
         this.removeClass('focus');
    });
}
  var selects = $$('select');
  for(i=0; i<selects.length; i++){
    var thisselect = selects[i];
    thisselect.addEvent('focus', function(){
        var thisLabel = this.getPrevious();
        thisLabel.addClass('current');
        this.addClass('focus');
    });
    thisselect.addEvent('blur', function(){
         var thisLabel = this.getPrevious();
         thisLabel.removeClass('current');
         this.removeClass('focus');
    });
}

  var textareas = $$('textarea');
  for(i=0; i<textareas.length; i++){
    var thistextarea = textareas[i];
    thistextarea.addEvent('focus', function(){
        var thisLabel = this.getPrevious();
        thisLabel.addClass('current');
        this.addClass('focus');
    });
    thistextarea.addEvent('blur', function(){
         var thisLabel = this.getPrevious();
         thisLabel.removeClass('current');
         this.removeClass('focus');
    });
}
}


Window.onDomReady(function(){
	createDropShadows();
liveLabels();
});

