function fc_search(){
	var champ = $('#searchbox');
	if(champ.val() == "Rechercher..."){
		champ.val("");
	}
};

function showImage(src){
	//$("#galerie_image").addClass("loading");
	//$("#loader img").fadeOut("normal").remove();

	var largeImage = new Image();

	$(largeImage).load(function(){
		//$("#loader").removeClass("loading");
		//$(this).hide();
		$("#galerie_image").html(this);
		//$(this).fadeIn("slow");
	});

	$(largeImage).attr("src", src);
}

function loadPopup(){
	if(popupStatus==0){
		$("#dark").css({
			"opacity": "0.8"
		});
		$("#dark").fadeIn("fast");
		$("#popupDiv").fadeIn("fast");
		popupStatus = 1;
	}
}
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#dark").fadeOut("fast");
		$("#popupDiv").fadeOut("fast");
		popupStatus = 0;
	}
}
function centerPopup(){

	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var popupHeight = $("#popupDiv").height();
	var popupWidth = $("#popupDiv").width();

	//centering
	$("#popupDiv").css({
		"position": "absolute",
		"top": windowHeight/2 + f_scrollTop() - popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});

	//only need force for IE6
	$("#dark").css({
		"height": windowHeight
	});
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


var popupStatus = 0;

$(function(){
	$("#btOptSubmit").hide();

	$("#nbParPage, #event").change(function(){
		$("#frmOptShow").submit();
	});

	$("#lstVignette a").hover(
		function(){
			var imageSource = "photos/" + $(this).attr("id") + ".jpg";
			//if( imageSource != $('#loader').children("img").attr('src'))
			showImage(imageSource);
			return false;
		},
		function(){
			return false;
		}
	);

	$(".tableQuery tr").click(function(e) {
		var id =  $(this).attr("id");
		if(isNaN(id)||id=="") return; // si on click sur la ranger TR
		$("#popupDiv").load("index.php?event=popup&id=" + id,"", function(){
				centerPopup();
				loadPopup();
		});
	});

	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#dark").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

  $(".tableQuery tr").mouseover(function (){
    $(this).addClass('trover');
  });
  $(".tableQuery tr").mouseout(function (){
    $(this).removeClass('trover');
  });
  $(".tableQuery tr:even").addClass('trodd');
});
