$(document).ready(function(){

	$("#submitbutton").mouseover(function(){
		$(this).css('background-color','#0080A6');		
	})

	$("#submitbutton").mouseout(function(){
		$(this).css('background-color','#7900C3');
	})	

	$("#input_naam").click(function(){
		if($(this).val()=="Naam"){
			$(this).val('');
		}
	})	

	$("#input_email").mouseover(function(){
		$(this).css('background-color','#666');
	})
	
	$("#input_email").mouseout(function(){
		$(this).css('background-color','#000');
	})


	$("#input_naam").mouseover(function(){
		$(this).css('background-color','#666');
	})
	
	$("#input_naam").mouseout(function(){
		$(this).css('background-color','#000');
	})

	$("#input_email").click(function(){
		if($(this).val()=="Email"){
			$(this).val('');
		}
	})	

	$("#input_naam").blur(function(){
		if($(this).val()==''){
			$(this).val('Naam');
		}
	})	

	$("#input_email").blur(function(){
		if($(this).val()==''){
			$(this).val('Email');
		}
	})	

	var options = { 
        target:        '#subscribed',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
	};
	$("#subscribeform").ajaxForm(options);

	$("#subscribeform").validate({

		errorPlacement: function(error, element) { 
			element.css('border-color','#f00');
    	}
	});

	function showRequest(formData, jqForm, options) { 
		ret=true;
		if($("#input_naam").val()=='Naam'){
			$("#input_naam").val('')
			ret=false;
		}
		if($("#input_email").val()=='Email'){
			$("#input_email").val('')
			ret=false;
		}
		ret=$("#subscribeform").validate().form();
		if(ret){
			$("#subscribeform").hide('slow');	
		}else{
			setTimeout(function(){  
			$("#subscribed").hide('slow');		
			$("#subscribeform").show('slow');	
			if($("#input_naam").val()=='')
				$("#input_naam").val('Naam');
			if($("#input_email").val()=='')
				$("#input_email").val('Email');
			$("#input_naam").css('border-color','#fff');
			$("#input_email").css('border-color','#fff');
		}, 2000 );
		}
		return(ret);
	}

	function showResponse(responseText, statusText, xhr, $form)  { 
		$("#subscribed").show('slow');
		$("#subscribed").html(responseText);
		setTimeout(function(){  
			$("#subscribed").hide('slow');		
			$("#subscribeform").show('slow');	
			$("#input_naam").val('Naam');
			$("#input_email").val('Email');
			$("#input_naam").css('border-color','#fff');
			$("#input_email").css('border-color','#fff');
		}, 2000 );
	}
});
