// JavaScript Document

//engage on the page load
$(function() {
  //trigger ajax on submit
  
  $('#form1').submit( function(){

  //hide the form
  $('#form1').hide();

  //show the loading bar
  $('.loader').append($('.bar'));
  $('.bar').css({display:'block'});

  //send the ajax request
  $.get('mail.php',{name:$('#TxtName').val(),
                    email:$('#TxtEmail').val(),
					phone:$('#TxtPhone').val(),
                    comment:$('#TxtMessage').val()},

  //return the data
  function(data){
    //hide the graphic
    $('.bar').css({display:'none'});
    $('.loader').append(data);
  });

  //stay on the page
  return false;
  });

  
  /* This code is executed after the DOM has been completely loaded */
	
	$('a.scroll, a#logo').click(function(e){
										  
		// If a link has been clicked, scroll the page to the link's hash target:
		
		$.scrollTo( this.hash || 0, 1500);
		e.preventDefault();
	});


	// Demo
	
	$('#backToTheTut').hover(function(){
		$(this).stop().animate({'left':-20},'slow');
	},function(){
		$(this).stop().animate({'left':-410},'slow');
	});
	
	setTimeout(function(){$('#backToTheTut').animate({'left':-410},'slow');},2000);

});




$(document).ready(function() {
			
			$("a.fancy").fancybox({
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'scrolling'			: 'no',
				'overlayShow'	    : false
			});
		});

//initiate validator on load
$(function() {
// validate contact form on keyup and submit
$("#form1").validate({
//set the rules for the field names
rules: {
TxtName: {
required: true,
minlength: 2
},
TxtEmail: {
required: true,
email: true
},
TxtMessage: {
required: true,
minlength: 2
},
},
//set messages to appear inline
messages: {
TxtName: "Please enter your name",
TxtEmail: "Please enter a valid email address",
TxtMessage: "Please enter your message"
}
});
});

