// JavaScript Document
$().ready(function() {
	$('#block01').flash({
		src: 'img/home/flash.swf',
		width: 406,
		height: 289,
		wmode:'opaque'
	});
//	slider();
	$("#slideshow").jCarouselLite({
        btnNext: "#bt_worknext",
        btnPrev: "#bt_workprev"
    });
	
	$("div[formula]").click(function(){
		document.location.href = $(this).attr("formula");
	});

	$("#logo").click(function(){
		document.location.href = '/';
	});
	
	$("div[workshop]").click(function() {
		document.location.href = $(this).attr("workshop");
	});
	$("div[trigger=theme]").click(function(){
		document.location.href = 'nos-themes-du-mois';
	});
	
	$("div[trigger=account]").click(function(){
		document.location.href = 'mon-compte';
	});
	
	$("div[theme]").click(function() {
		var theme_id = $(this).attr("theme");
		document.location.href = 'theme.php?theme_id='+theme_id;
	});
	
	$("div[trigger=gift]").click(function(){
		document.location.href = 'offrir-un-bon-cadeau';
	});
	
	$("div[trigger=newsletter]").click(function(){
		var email = $("#home_email").val();
		if (email == "" || email == "Email") alert ('Veuillez indiquer votre adresse email');
		else $.ajax({
			type: "POST",
			url: "ajax/add_newsletter_user.php",
			data: "email="+email,
			success: function(msg){
				alert(msg);
			}
		});
	});
	
	$("span[class=bt_script]").each(function() {
		var trigger = $(this).attr("trigger");
		$(this).click(function(){
			document.location.href = trigger;
		})
		.mouseover(function(){
			$(this).css("color","#a0a0a0");
		}).mouseout(function(){
			$(this).css("color","#b73732");
		});
	});
	
	$("#home_email").focus(function(){
		if ($(this).val() == "Email") $(this).val("");
	}).blur(function() {
		if ($(this).val() == "") $(this).val("Email");
	});

	$("#register_box").dialog({
		autoOpen: false,
		height: 420,
		width: 600,
		modal: true
	});

	$("#register").click(function(){
		var datas = $("#register_form").serialize();
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "ajax/add_user_index.php",
			data: datas,
			success: function(res){
				if (res.msg == '1') {
					$("#user_content").html(res.text);
					$("#formulaire").hide();
					$("#record_ok").show();
				}
				else if (res.msg == '0') $("#reg_result").html("PROBLEME");
				else $("#reg_result").html(res.msg);
			}
		})
	});
	$("#record_ok").click(function(){
		$("#register_box").dialog('close');
	});
});
