// javascript
	
function display_div() {
	$("div#date_img").animate({"opacity": "1"}, "slow");
	$("div#date_img").show();
}
	
function del_div() {
	$("div.error").removeClass("hidden");
	$("div#date_img").hide();
}

$(document).ready(function () {

	/*$("img").live("hover", function() {
		date = $(this).attr("alt");
		if ($("div.auteur."+date).html()) {
			$("div."+date).css({"width" : $(this).width()});
			$("div."+date).animate({
				bottom : "130px",
				opacity : 1
			}, 500);
		}
	})*/
	
	$(window).scroll(function () {
		size_page = $("body").height();
		where_i_am = $(window).scrollTop() + $(window).height();
		//$(".last_element").each(function() { $(this).addCl });
		//alert(size_page+" < "+(where_i_am+($("body").height()))/2);
		if (size_page < (where_i_am+($("body").height()))/2) {
			$.ajax({
				type: "POST",
				url: "http://www.bonjourprincesse.fr/templates/js/bp_ajax.php",
				data: "ajax=true&need=new_pictures",
				success: function(data){
					$("div#content").html($("div#content").html()+data);
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					alert(XMLHttpRequest.status);
				}
			});
		}	
	});
	
	
	$("#signin").click(function() {
		$("#seconnecter").show();
		$(this).hide();
	});
	
	$("#form .connexion input").change(function() {
		var i = 0;
		$("#form .connexion input").each(function() {
			if ($(this).val() != "")
				i++;
		});
		$("#form .connexion .right span.steps").html(i);
		$("#form .connexion .right #bgthree").css("background-position", "0 -"+i*12+"px");
	});
	
	$("#form .supp input, #form .supp select").change(function() {
		var i = 0;
		$("#form .supp input, #form .supp select").each(function() {
			if ($(this).val() != "")
				i++;
		});
		if ($("#form .supp select").val() == 0)
			i--;
		$("#form .supp .right span.steps").html(i);
		$("#form .supp .right #bgfour").css("background-position", "0 -"+i*12+"px");
	});
	
	$("#form input.submit").click(function() {
		if ($("#form .connexion .right span.steps").html() == "3" && $("#form .supp .right span.steps").html() == "4")
			$("#form form").submit();
		else {
			error = "<ol>";
			if ($("#form .connexion .right span.steps").html() != "3")
				error += "<li>Les informations de connection ne sont pas compl&egrave;tes.</li>";
			if ($("#form .supp .right span.steps").html() != "4")
				error += "<li>Les informations suppl&eacute;mentaires ne sont pas compl&egrave;tes.</li>";
			error += "</ol>";
			$(".error").html(error);
			$(".error").show();
		}
	});
	
	$("#date #choisir #select_date select").change(function() {
		
		var cur		=	new Date();
		var day 	=	($("select.day").val() <= 9 ? "0"+$("select.day").val() : $("select.day").val());
		var month 	=	($("select.month").val() <= 9 ? "0"+$("select.month").val() : $("select.month").val());
		var year 	=	$("select.year").val();
			
		if (year == cur.getFullYear()) {
			$("select.month option").each(function() {
				if ((cur.getMonth()+1) < $(this).val())
					$(this).attr("disabled", "");
			});
			if (month == cur.getMonth()+1) {
				$("select.day option").each(function() {
					if ((cur.getDate()-1) < $(this).val())
						$(this).attr("disabled", "");
				});
			}
			else {
				$("select.day option").each(function() { $(this).removeAttr("disabled"); });
			}
		}
		else {
			$("select.day option").each(function() { $(this).removeAttr("disabled"); });
			$("select.month option").each(function() { $(this).removeAttr("disabled"); });
		}
		
		var data 	=	day+month+year;
		
		$("div.error").addClass("hidden");
		$("div#date_img").animate({"opacity": "0"}, "fast");
		$("#copy_press input").val("http://www.bonjourprincesse.fr/date-"+data+".html");
		$("div#date_img img").attr("src", "/pictures/"+data+".jpg");
	});
	
	var i = true;
	$("#date #choisir #share").click(function() {
		if (i) {
			$("#copy_press").show();
			i = false;
		}
		else {
			$("#copy_press").hide();
			i = true;
		}
	});
	
	$("#date #choisir #copy_press #close").click(function() {
		$("#copy_press").hide();
		i = true;
	});
});
