$(document).ready(function() {

	$(".menu li div").css("opacity","1");

	$(".menu li div").hover(function () {
		$(this).stop().animate({
			opacity: 0
		}, "normal");
	},

	function () {
		$(this).stop().animate({
			opacity: 1
		}, "normal");
	});
	
	$('#contact').click(function() {
		$('#content-container').fadeOut('normal');
		$('#contact-container').fadeIn('normal');
	});
	$('#return').click(function() {
		$('#contact-container').fadeOut('normal');
		$('#content-container').fadeIn('normal');
	});
	$('#contact-form').click(function() {
		$('#contact-container').fadeOut('normal');
		$('#contact-form-container').fadeIn('normal');
	});
	$('#cancel').click(function() {
		Return();
		return false;
	});
	$('#send').click(function() {
		$("#Contact").validate(
			{
				errorClass: "validation-advice",
				submitHandler: function(form) {
					var Url = '/IndexPageContent/send.php';
					var Parameters = {
						Name 	: $('#Name').val(),
						Email	: $('#Email').val(),
						Title	: $('#Title').val(),
						Message	: $('#Message').val()
					}
					$.post(Url, Parameters, function(response) {
						if(response == 1) {
							alert('Poruka je uspješno poslana');
							Return();
						} else {
							alert("Poruka NIJE uspješno poslana! Molimo pokušajte ponovo!");
						}
					});
					return false;
				},
				rules: {
					Email: {
						required	:true,
						email		:true
					},
					Name: {
						required	:true
					},
					Title: {
						required	:true
					},
					Message: {
						required	:true
					}
				},
				messages: {
					Email: {
						required	:'E-mail adresa je obavezna!',
						email		:'E-mail adresa nije valjana! E-mail adresa mora biti u obliku ja@domena.hr!'
					},
					Name: {
						required	:'Ime i prezime su obavezni!'
					},
					Title: {
						required	:'Naslov poruke je obavezan!'
					},
					Message: {
						required	:'Poruka je obavezna!'
					}
				}
			}
		);		
	});
});

function Return() {
	$('#Name').val('');
	$('#Email').val('');
	$('#Title').val('');
	$('#Message').val('');
	$('#contact-form-container').fadeOut('normal');
	$('#contact-container').fadeIn('normal');
	$('label.validation-advice').hide();
}
