jQuery(function($){
  // Add email to submit. - NO SPAM
  $('#submitEmail').attr('href', 'mailto:blog@oncemade.com?subject=Oncemade Blog :: Articles/Ideas');
  
  // Clear input on focus
  $("#s").focus(function() {
  	if( this.value == this.defaultValue ) {
  		this.value = "";
  	}
  }).blur(function() {
  	if( !this.value.length ) {
  		this.value = this.defaultValue;
  	}
  });

  $('.anchorLink').click(function() {
    var elementClick = $(this).attr("href")
		var destination = $(elementClick).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 500 );
	  	return false;
  });
  
	// LEAVE COMMENT
	var postComment = $('#postComment'),
		 leaveReply = $('#leaveReply');
	if (postComment && leaveReply) {
		postComment.click(function() {
			leaveReply.slideToggle(function(){
				$('#author').focus();
			});
			return false;
		});
		
		$('#cancelComment, #noCommentLink').click(function() {
			postComment.trigger('click');
			return false;
		});
	};
	
	// SUBMIT FORM
	if ($('#contactForm')) {
		$("#contactForm").submit(function(){  
			var str = $(this).serialize();
		   $.ajax({
			   type: "POST", 
			   url: "/wp-content/themes/oncemade/contact/contact.php",  
			   data: str,
			   success: function(msg){  
					$("#note").ajaxComplete(function(event, request, settings){  
						if(msg == 'OK') {
							result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';  
							$('#contactForm input[type="text"], #contactForm textarea').val("");
							$('#name').focus();
						}else{  
							result = msg;  
						}  
						$(this).html(result).fadeIn();
					});
				}  
			});
			return false;
		});
		
	}
  

});
