//tab menu
function send() {
$.ajax({
	type: "POST",
	url: "includes/send.php",
	data: "yName="+$('form input#yName').val()+"&fEmail="+$('form input#fEmail').val()+"&subject="+$('form input#subject').val()+"&yMsg="+$('form textarea#yMsg').val(),
	success: function(r) {
		
$('form fieldset').hide("slow");
$('form p#send').hide();

$('form div#sent').css('visibility', 'visible');
$('form input#close').css('visibility', 'visible');


//$("form").animate({opacity: 0}, { duration: 200 });

$("form input#close").click(function (e){
e.preventDefault();	

$('form').animate({opacity: 0}, { duration: 0 });
$('form').stop(); 
$('form').hide(); 

});

$('form')[0].reset();	

} //end success
	
});	
}

function validate (){

// validate contact form on keyup and submit
$('form').validate({
//set the rules for the field names
rules: {
yName: {
required: true,
minlength: 2
},
fEmail: {
required: true,
email: true
},
yMsg: {
required: true,
minlength: 2
}
},
//set messages to appear inline
messages: {
yName: "Please enter your name",
fEmail: "Please enter a valid email address",
yMsg: "Please enter your message"
}

});

}//end validate

//replace() function
$.fn.replace = function(o) { return this.after(o).remove(); }; 
	
	
	
$(document).ready(function(){
 
$('form').hide();


validate();

$("form input#submit").click(function (e){
e.preventDefault();	
validate();

if ($("form").valid()){

send();

}
}); 
 
 
 $(".images a").hover(function () {
$(this).fadeTo("fast", 0.7);
}, 
function () {
$(this).fadeTo("fast", 1.0);
}

);
 
 
$(".images a").click(function (e) {
//to add href without change the url
e.preventDefault();	


var text = "assets/images/folio/" + $(this).attr('name') +"/large/"+ $(this).attr('title') + ".jpg";

//$(this).parents('.work').find('img:first').replace('<img src="assets/images/spinner.gif" alt="Wait" style="margin: 177px 306px 177px 307px"; />');

$(this).parents('.work').find('img:first').fadeOut(150, function (){
$(this).parents('.work').find('img:first').replace('<img src="'+text+'" width="629" height="370" alt="'+$(this).attr('title')+'" />');
});



});//end onclick

 
$('p#friend').click(function (e){
//to add href without change the url
e.preventDefault();	

$('form').show();
$('form').animate({opacity: 1}, { duration: 0 });
$('form div#sent').css('visibility', 'hidden');
$('form input#close').css('visibility', 'hidden');
$('form fieldset').show();
$('form p#send').show();

}); 


$('form input#cancel').click(function (e){
//to add href without change the url
e.preventDefault();	

$('form').hide();
$('form')[0].reset();
$('form .error').empty();

}); 

	  

});



