// JavaScript Document

$("link:first").attr("href","css/global_js.css");

jQuery.event.add(window, "resize", resizeFrame);

var timer_footer_1 = 0; /* Utilisé pour le setTimeout */
var timer_footer_2 = 0; /* Utilisé pour le setTimeout */

// centrage d'un élément sur l'axe horizontal et par rapport à l'écran
// [objet] = l'objet jquery à positionner
// [decalage] = (optionnel) decalage de l'élément par rapp au centre
function centrer_horizontal(objet, decalage) {
	//if(objet.data("registered_resize") == undefined) { register_resize(objet); }
	var w_objet = objet.width();
	var position_h = (width_win/2) - (w_objet/2);
	
	if(typeof decalage != 'undefined') // 
		position_h = position_h + decalage;
	
	objet.css('left',position_h);
}

// centrage d'un élément sur l'axe vertical et par rapport à l'écran
// [objet] = l'objet jquery à positionner
// [hauteur_statique] = (optionnel) hauteur statique de l'élément, utiliser au cas ou le script n'arrive pas à determiner sa hauteur
function centrer_vertical(objet,hauteur_statique) {
	var h_objet = objet.height();
	//alert("hauteur_statique = "+hauteur_statique)
	
	if(typeof hauteur_statique != 'undefined') // si hauteur_statique est défini
		//alert("hauteur_statique = "+hauteur_statique)
		h_objet = hauteur_statique;
		
	//alert("h_objet = "+h_objet)
	objet.css('margin-top',(height_win/2) - (h_objet/2));
}

function replier_footer() {
	$("#footer").stop().animate({ 
        top: height_win
    }, 800 );
	
	$("#footer .footer_close_button").stop().animate({ 
        height: "25px",
		top: "-25px"
    }, 1300, function () {
		$(this).mouseover(
			function () {
				deplier_footer();
			}
		);
	});
}

function deplier_footer() {
	$("#footer .footer_close_button").stop().animate({ 
        height: "0",
		top: "0"
    }, 300);
	
	$("#footer").stop().animate({ 
        top: height_win - $("#footer").height()
    }, 800, function () {
		timer_footer_1 = setTimeout("replier_footer()",4000); /* Se replie au bout de 4sec si le on mouse move ne se declenche pas */;
		$(this).mousemove(
			function () {
				reste_deplie();
			}
		);
	});
}

function reste_deplie() {
	clearTimeout(timer_footer_1);
	clearTimeout(timer_footer_2);
	timer_footer_2 = setTimeout("replier_footer()",4000);
}

function deplie_menu_header(objet) {
	target = objet;
	target.data("hauteur",target.css("height"));
	
	target.stop().animate({ 
        height: "40px"
    }, 200, function() {
		target_decalage = target.children("LI > UL > LI:first")
		
		target_decalage.stop().animate({marginLeft:"39px"}, 400);
	});
}

function replie_menu_header(objet) {
	target = objet;
	//alert("target.data('hauteur') = "+target.data('hauteur'));
	
	target.stop().animate({ 
        height: target.data("hauteur")
    }, 200);
}

/* general */
function init_frame() {
	height_win = $(window).height();
	width_win = $(window).width();
	
	$("#footer").css('top',height_win-$("#footer").height());
	resizeFrame();
	$("#conteneur").css('visibility','visible');
	windowReady_local();
}

function resizeFrame() 
{
	height_win = $(window).height();
	width_win = $(window).width() - 20;
	
	if($("#cadre_drag").length) {
		$("#cadre_drag").css('height',height_win);
		$("#cadre_drag").css('width',width_win);
	}
	timer_footer_1 = setTimeout("replier_footer()",1500);	
	
	centrer_horizontal($("#footer"));
	centrer_horizontal($("#header"));
	
	resizeFrame_local();
}

$(document).ready(function(){	
   $("#conteneur").css('visibility','hidden');
	//init_frame();
	setTimeout("init_frame()",300);
	
	$("#footer").prepend("<div class=\"footer_close_button\"><a href=\"#\">...</a></div>");
	
	//windowReady_local();
	
	$("#header_menu_collection, #header_menu_apropos").hover(
		function(){
			deplie_menu_header($(this));
		},
		function() {
			replie_menu_header($(this));
		}
	)
	
	$("#footer").mousemove(
		function () {
			reste_deplie();
		}
	)
});

