// JavaScript Document
function links_menu() {
	$("#logo").click(function(){
		document.location.href = 'index.php';
	});
	$("[trigger_menu]").click(function(){
		var trigger = $(this).attr("trigger_menu");
		if (trigger == "findus") document.location.href = 'contact.php#findus';
		else document.location.href = trigger+'.php';
	});
	$(".link[trigger]").click(function(){
		var trigger = $(this).attr("trigger");
		document.location.href = trigger+'.php';
	});
	
	$("div[page]").each(function(){
		var page = $(this).attr("page");
		$(this).mouseenter(function(){
			$("#"+page+"_pic").effect("bounce",'',500,callback(this));
		}).click(function(){
			document.location.href = page+'.php';
		})
		.mouseover(function(){
			$("#"+page+"_btn").addClass('on');
		})
		.mouseout(function(){
			$("#"+page+"_btn").removeClass('on');
		});
	});
	
	$("#header_email").focus(function(){
		if ($(this).val() == "Email") $(this).val("");
	}).blur(function() {
		if ($(this).val() == "") $(this).val("Email");
	});
	
	$("#header_fake_psw").focus(function(){
		$("#header_input").hide()
		$("#header_hold").show();
		$('input:password').focus();
	});
	$("#header_password").blur(function() {
		if ($("#header_password").val() == "") {
			$("#header_input").show()
			$("#header_hold").hide();
		}
	});
	
	$('#check').click(function() {
		return test();
	});
}

function callback(val){
	setTimeout(function(){
		var effect_id = $(val).attr("page");
		$("#"+effect_id+"_pic:hidden").removeAttr('style').hide().fadeIn();
	}, 201);
}

function test(){
	var email = $("#header_email").val();
	var pass = $("#header_password").val();
	// submit the form
	if (email != '' && pass!= '' ) {
		$.ajax({
			type: "POST",
			url: "ajax/check_user.php",
			data: "email="+email+"&pass="+pass,
			success: function(msg){
				if (msg == 1) document.location.href = "account.php";
				else {
					$("#result_pass").html(msg);
				}
			}
		});
		// return false to prevent normal browser submit and page navigation
		return false;
	}
	else {
		alert('Tous les champs doivent \352tre remplis');
		return false;
	}
}
