$(document).ready(function() {

$("#contactForm").validate({

	errorPlacement: function(error, element) {
    	error.insertBefore(element)
	}

});

	$(".cAbout").hide();
	$(".cServices").hide();
	$(".cPortfolio").hide();
	$(".cContact").hide();
	
  $("#message").hide(); 
  $("#loading").hide();
  	
	var queryhash = window.location.hash
	switch (queryhash) {
		case "#about":
			showAbout();
			break;
		case "#services":
			showServices();
			break;
		case "#portfolio":
			showPortfolio();
			break;
		case "#contact":
			showContact();
			break;
		default:
			showAbout();
			break;
	}

  $("#tAbout").click(function() {
    showAbout();
  });  
  
  $("#tServices").click(function() {
    showServices();
  });  
  
  $("#tPortfolio").click(function() {
    showPortfolio();
  });  
  
  $("#tContact").click(function() {
    showContact();
  });
  $("#tContactAbout").click(function() {
    showContact();
  });
  $("#tContactServices").click(function() {
    showContact();
  });
});	

/* End OnLoad */
  
  function showAbout() {
    $(".cServices").slideUp(600);
    $(".cPortfolio").slideUp(600);
    $(".cContact").slideUp(600);
    setTimeout("$('.cAbout').toggle('blind', { direction: 'vertical' }, 800);",500);
   }
   
   function showServices() {
    $(".cAbout").slideUp(600);
    $(".cPortfolio").slideUp(600);
    $(".cContact").slideUp(600);
    setTimeout("$('.cServices').toggle('blind', { direction: 'vertical' }, 800);",500);
  }

  function showPortfolio() {
    $(".cAbout").slideUp(600);
    $(".cServices").slideUp(600);
    $(".cContact").slideUp(600);
    setTimeout("$('.cPortfolio').toggle('blind', { direction: 'vertical' }, 800);",500);
  } 
  
  function showContact() {
    $(".cAbout").slideUp(600);
    $(".cServices").slideUp(600);
    $(".cPortfolio").slideUp(600);
    setTimeout("$('.cContact').toggle('blind', { direction: 'vertical' }, 800);",500);
  } 
  
// Email Message
   $(function() {    
    $("#emailHeader").click(function() {
      $('#contactHeader').fadeTo("slow", 0.01, function() {
        $(this).slideUp("slow", function() {
          $(this).remove();
        });
      });      
      $("#wrapEmail").toggle("blind", { direction: "vertical" }, 600);
    });
  
  
	$(".submit").click(function() {
   
	if ($("#contactForm").valid()) {
    
      $('#emailHeader').fadeOut("slow");
      
      $('#wrapEmail').fadeTo("slow", 0.01, function() {
        $(this).slideUp("slow", function() {
          $(this).remove();
        });
      });
      
      $('#loading').fadeIn("slow");
    
  	  var name = $("input#name").val();
      var email = $("input#email").val();
      var subject = $("input#subject").val();
      var message = $("textarea#message").val();
      

	var dataString = 'name=' + name + '&email=' + email + '&subject=' + subject + '&message=' + message;
	//alert (dataString);return false;
  $.ajax({
    type: "POST",
    url: "inc/email.php",
    data: dataString,
    success: function() {
      $('#loading').fadeTo("slow", 0.01, function() {
        $(this).slideUp("slow", function() {
          $(this).remove();
        });
      });
      $('#message').fadeIn("slow");
    }
  });
  return false;
	
	}
	
	});
    
  });  
 // End Email Message  
