// wait until the document is ready, then load stuff
$(document).ready(function(){
	
	$('#Nav > li').each(function(i){						 
		$(this).hover(function(){  
			$(this).find('ul.subnav').show();
		},function(){
			$(this).find('ul.subnav').hide();
		});		
	});
	
	$('#NavI > li').each(function(i){						 
		$(this).hover(function(){  
			$(this).find('ul.subnav').show();
		},function(){
			$(this).find('ul.subnav').hide();
		});		
	});
	
	$('.subnav > li').each(function(i){						 
		$(this).hover(function(){  
			$(this).find('ul.subnav2').show();
		},function(){
			$(this).find('ul.subnav2').hide();
		});	
		$(this).hover(function(){  
			$(this).find('ul.subnav2b').show();
		},function(){
			$(this).find('ul.subnav2b').hide();
		});	
	});
	
		
	$('#fade').cycle({fx: 'fade', speed: 1000, timeout: 150});
	$('#fade2').cycle({fx: 'fade', speed: 2000, timeout: 2150});
	

});

/* TEXT OVERLAY TEXT BOX */

function initOverLabels () {
  if (!document.getElementById) return;      

  var labels, id, field;

  // Set focus and blur handlers to hide and show 
  // labels with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  for (var j = 0; j < labels.length; j++) {

    if (labels[j].className == 'overlabel' || labels[j].className == 'overlabel2' || labels[j].className == 'overlabel23' || labels[j].className == 'overlabel3') {

      // Skip labels that do not have a named association
      // with another field.
      id = labels[j].htmlFor || labels[j].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      } 

      // Change the applied class to hover the label 
      // over the form field.
      //labels[j].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[j].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 j = 0; j < labels.length; j++) {
    field_for = labels[j].htmlFor || labels[j].getAttribute('for');
    if (field_for == field_id) {
		
      //labels[j].style.textIndent = (hide) ? '-99999em' :'0';
	  
	  
	  
	 
	  
	  if (labels[j].className == 'overlabel2' || labels[j].className == 'overlabel23') {
		  labels[j].style.marginLeft = (hide) ? '0px' :'4px';
		   labels[j].style.marginTop = (hide) ? '-15px' :'6px';
	  }else{
		  labels[j].style.marginLeft = (hide) ? '0' :'4px';
		  labels[j].style.marginTop = (hide) ? '-18px' :'2px';
	  }
	  if (labels[j].className == 'overlabel3' || labels[j].className == 'overlabel23') {
		  labels[j].style.color = (hide) ? '#858585' :'#FF0000';  
	  }else{
		  labels[j].style.color = (hide) ? '#858585' :'#858585';  
	  }
	  
	   
	  labels[j].style.fontSize = (hide) ? '10px' :'12px';
	  
      return true;
	  
    }
  }
}
	
window.onload = function () {
  setTimeout(initOverLabels, 50);
};

