Cufon.replace('ul#sub-nav li a', { fontFamily:'avenir-65med', hover:true });
Cufon.replace('ul#sub-nav li.subcontractors', { fontFamily:'avenir-65med', hover:true });
Cufon.replace('ul#main-nav li a', { fontFamily:'avenir-65med', hover:true });
Cufon.replace('ul#home-sections li .title', { fontFamily:'avenir-65med' });
Cufon.replace('#content #text-area h1', { fontFamily:'avenir-35light' });
Cufon.replace('#projects-text-area h1', { fontFamily:'avenir-35light' });
Cufon.replace('#projects-text-area h2', { fontFamily:'avenir-65med' });
Cufon.replace('#text-area #text h2', { fontFamily:'avenir-85heavy' });
Cufon.replace('#text-area #text-container-full h2', { fontFamily:'avenir-85heavy' });
Cufon.replace('#contact-form #contact-text h2', { fontFamily:'avenir-85heavy' });
Cufon.replace('#projects-text-area #text h3', { fontFamily:'avenir-85heavy' });
Cufon.replace('#properties-text-area #contact h3', { fontFamily:'avenir-85heavy' });
Cufon.replace('#property-text-area h1', { fontFamily:'avenir-35light' });
Cufon.replace('#property-text-area h2', { fontFamily:'avenir-65med' });

Cufon.replace('#content #text-area #text h2', { fontFamily:'avenir-85heavy' });
Cufon.replace('ul#sub-nav li.heading', { fontFamily:'avenir-65med'});


$(document).ready(function() {
  $("#login-pop form .text").each(function(index) {
    $(this).focus(function() {
     $(this).addClass('text-border');
    });
    $(this).blur(function() {
     $(this).removeClass('text-border');
    });
  });
  
  $("#sub-login-login").bind('click', function(e) {
    e.preventDefault();
    $("#login-pop").fadeIn(200);
  });  
  
  $("#login-pop form a#submit").bind('click', function(e) {
     e.preventDefault();
    $("#login-form").submit();
   });
  
  $("#login-pop form a#close").bind('click', function(e) {
    e.preventDefault();
    $("#login-pop").fadeOut(200);
  });
  
  $("input#edit-name").wrap('<div class="input-text-half-container input-text-half-back" />');
  $("input#edit-pass").wrap('<div class="input-text-half-container input-text-half-back" />');
  
  
  $("input#edit-name, input#edit-pass, input#username, input#password").keypress(function(e){
      if(e.which == 13){
        e.preventDefault();
        $("#login-form").submit();
      }
  });

  $('.input-text-half-container').each(function(index) {
		var parent = this;
	    $(".input-text-half, .form-text", this).focus(function() {
			$(parent).removeClass('input-text-half-back');
			$(parent).addClass('input-text-half-back-focus');
		});
	    $(".input-text-half, .form-text", this).blur(function() {
			$(parent).removeClass('input-text-half-back-focus');
			$(parent).addClass('input-text-half-back');
		});
	  });
	$('.input-textarea-half-container').each(function(index) {
		var parent = this;
	    $(".input-textarea-half", this).focus(function() {
			$(parent).removeClass('input-textarea-half-back');
			$(parent).addClass('input-textarea-half-back-focus');
		});
	    $(".input-textarea-half", this).blur(function() {
			$(parent).removeClass('input-textarea-half-back-focus');
			$(parent).addClass('input-textarea-half-back');
		});
	  });
  $('.input-text-half-container-projname').each(function(index) {
    var parent = this;
      $(".input-text-half-projname, .form-text", this).focus(function() {
      $(parent).removeClass('input-text-half-back-projname');
      $(parent).addClass('input-text-half-back-projname-focus');
    });
      $(".input-text-half-projname, .form-text", this).blur(function() {
      $(parent).removeClass('input-text-half-back-projname-focus');
      $(parent).addClass('input-text-half-back-projname');
    });
    });
  $('.input-textarea-half-container-apply').each(function(index) {
    var parent = this;
      $(".input-textarea-half-apply", this).focus(function() {
      $(parent).removeClass('input-textarea-half-back-apply');
      $(parent).addClass('input-textarea-half-back-apply-focus');
    });
      $(".input-textarea-half-apply", this).blur(function() {
      $(parent).removeClass('input-textarea-half-back-apply-focus');
      $(parent).addClass('input-textarea-half-back-apply');
    });
  });


  // sub contractor form
  $(".web-form-50").bind('click', function(e) {
    e.preventDefault();
    hasErrors = false;
    // validate
    name = $("#edit-submitted-name").val();
    company = $("#edit-submitted-company").val();
    email = $("#edit-submitted-email").val();
    phone = $("#edit-submitted-phone").val();
    fax = $("#edit-submitted-fax").val();

    if (name == "") {
            hasErrors = true;
            $("#name-label").empty().append('<span class="error">Please enter your name</span>');
       } else { $("#name-label").empty().append('Name <span class="form-required" title="This field is required.">*</span>');}
    if (company == "") {
            hasErrors = true;
            $("#company-label").empty().append('<span class="error">Please enter your company</span>');
       } else { $("#company-label").empty().append('Company <span class="form-required" title="This field is required.">*</span>');}   
    if (email == "" || !echeck(email)) {
            hasErrors = true;
            $("#email-label").empty().append('<span class="error">Please enter a valid email</span>');
       } else { $("#email-label").empty().append('Email Address <span class="form-required" title="This field is required.">*</span>');}
    if (phone == "") {
            hasErrors = true;
            $("#phone-label").empty().append('<span class="error">Please enter your phone</span>');
       } else { $("#phone-label").empty().append('Phone <span class="form-required" title="This field is required.">*</span>');}
    if (fax == "") {
            hasErrors = true;
            $("#fax-label").empty().append('<span class="error">Please enter your fax</span>');
       } else { $("#fax-label").empty().append('Fax <span class="form-required" title="This field is required.">*</span>');}

    // passed
    if(!hasErrors) {
      $("#webform-client-form-50").submit();
    }

  });


});






//Validate email address
function echeck(str) {
    var at = "@";
    var dot = ".";
    var lat = str.indexOf(at);
    var lstr = str.length;
    var ldot = str.indexOf(dot);
    if (str.indexOf(at) == -1) { return false; }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) { return false; }
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) { return false; }
    if (str.indexOf(at, (lat + 1)) != -1) { return false; }
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) { return false; }
    if (str.indexOf(dot, (lat + 2)) == -1) { return false; }
    if (str.indexOf(" ") != -1) { return false; }
    return true;
}

