  $(document).ready(function() {
      initOverLabels();
	  initCartExpand();
	  $('a[rel*=facebox]').facebox();
	  
	  initNavTabs();
	  initForgotPassword();
	  initSTFLink();
	  
	  initContactForm();
	  
  });

function initContactForm(){
	$('#contactReason').change(function(){
		var currValue = $(this).val();
		
		if(currValue == 'Other'){
			$('#otherField').show();
		}else{
			$('#otherField').hide();
		}
		
	});
}

function initSTFLink(){
	$('.stfLink').click(function(){
		ColdFusion.Window.show('stfWindow');
		return false;		
	});
	
}

function initForgotPassword(){
	$('.forgotPW').click(function(){
		ColdFusion.Window.show('forgotPWWindow');
		return false;
	});
}

function initNavTabs(){
	$('#tabNav a').click(function(){
		ColdFusion.navigate($(this).attr('href'),'prodListing');
		
		clearTabs();
		
		$(this).addClass('selected');
		
		return false;
	});
		
}


function clearTabs(){
	$('#tabNav a').removeClass('selected');
}

function initCartExpand()
{
	$('.btnPlus').click(function(){
		$('#cartAux').toggle();
		return false;
	});
	$('#cartAux .close').click(function(){
		$('#cartAux').toggle();
		return false;
	});	
}




function initOverLabels () {
  if (!document.getElementById) return;      

  var labels, id, field;
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {

    if (labels[i].className == 'overlabel') {
      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      } 

      labels[i].className = 'overlabel-apply';

      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      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.textIndent = (hide) ? '-1000em' : '0px';
      return true;
    }
  }
}

function clearValue(field){
	if (field.defaultValue == field.value)
	field.value = "";
}

function restoreValue(field,originalValue){
	if (field.value == "")
		field.value = originalValue;
}

