// JavaScript Document

var nbResult;
var endPrevResult = false;
var endNextResult = false;

function newSearch() {
	$("#blackContenu").load("search.php");
	document.location.hash = "search";
	window.location.hash = window.location.hash;
	ancre = "search";
}
function searchSubmitFunction() {
	closeAble = false;
	if (checkInputs()) {
		$.post("result.php", $("#rechercheForm").serialize(), function(data) {
			$("#blackContenu").html(data);
			document.location.hash = "result";
			window.location.hash = window.location.hash;
			ancre = "result";
			$("#prevResult").css("visibility","hidden");				   
			$("#nextResult").css("visibility","hidden");				   
			checkResultsEnds();
		}, "html");
	}
	closeAble = false;
	return false;   // to prevent default submit
}
function checkInputs() {
	var mot = $("#mot").val();
	var age = $("#age").val();
	var pays = $("#pays").val();
	var real = $("#real").val();
	
	if((mot=="")&&(age=="0")&&(pays=="0")&&(real=="0")) {
		alert("choisissez au moins un critere de recherche...");
		$("#age").focus();
		return false;
	}
	if ((mot != "")&&(mot.length < 3)) {
		alert ("le mot clef doit comporter au moins 3 caracteres");
		$("#mot").focus();
		return false;
	}
	return true;
}
function reinit() {
	$("#mot").val("");
	$("#age").val(0);
	$("#pays").val(0);
	$("#real").val(0);
}
function precResults() {
	if (endPrevResult) return;
	$("#resultList").animate({top:"+=210px"},"normal","swing",function(){checkResultsEnds()});
}
function nextResults() {
	if (endNextResult) return;
	$("#resultList").animate({top:"-=210px"},"normal","swing",function(){checkResultsEnds()});
}
function checkResultsEnds() {
	endPrevResult = endNextResult = false;
	$("#prevResult").css("visibility","visible");
	$("#nextResult").css("visibility","visible");
	if (nbResult%3 == 0) var lastLeft = -(nbResult - 3)*70 + "px";
	else var lastLeft = -(nbResult - nbResult%3)*70 + "px";
	var leftStr = document.getElementById("resultList").style.top;
	var left = Number(leftStr.substr(0,leftStr.length-2));
	var min = -(nbResult-3)*70 + 5;
	if (left > -6) {
		endPrevResult = true;
		$("#prevResult").css("visibility","hidden");
		document.getElementById("resultList").style.top = "0px";
	}
	if (left < min) {
		endNextResult = true;
		$("#nextResult").css("visibility","hidden");
		document.getElementById("resultList").style.top = lastLeft;
	}
}
function overPhoto(img,n,zoom) {
	with(img) {
		style.opacity = n/100;
		if (navigator.appName == "Microsoft Internet Explorer") filters.alpha.opacity = n;
		if (zoom == 1) style.width = "22px";
		else style.backgroundColor="#333333";
	}
}
function outPhoto(img,n,zoom) {
	with(img) {
		style.opacity = n/100;
		if (navigator.appName == "Microsoft Internet Explorer") filters.alpha.opacity = n;
		if (zoom == 1) style.width = "20px";
		else style.backgroundColor="#cccccc";
	}
}

