
$(function(){
	
	if (section == "sa") $("#partieDroite").append("<div id='depuis1963'>A votre service depuis 1963</div>");
	
	$("#partieGauche").append("<div id='barreCouleur'></div>");
	
	if (section == "sa") {coul = "#7CCBDD"; coulTxt = "#478B9E"; }
	else if (section == "telesurveillance") {coul = "#F2D78E"; coulTxt = "#C6860D"; }
	else if (section == "services-de-securite") {coul = "#F49C00"; coulTxt = "#EA640B"; }
	else if (section == "alarme") {coul = "#CB9FC0"; coulTxt = "#663558"; }
	else if (section == "detectiv") {coul = "#A5B83C"; coulTxt = "#6B8C1C"; }
	else coul = "white";
	$("#barreCouleur").css({backgroundColor:coul});	
	
	$("#contenu h2, #blocMission h2").css("color", coulTxt);

	$("ul#menuCourant li a").mouseenter(function(){
		$(this).css("backgroundImage", "url("+IMGPATH+"fond-menu-hover-"+section+".png)");
	}).mouseleave(function(){
		if (! $(this).hasClass("selected")) $(this).css("backgroundImage", "url("+IMGPATH+"fond-menu.png)");
	});
	
	$("ul#menuCourant li a.selected").css("backgroundImage", "url("+IMGPATH+"fond-menu-hover-"+section+".png)");
	
	$("#contenu h3").prepend("<img src='"+IMGPATH+"puce.png' class='puce' />");
	
	// Centrage des images dans les blocs de mise en avant
	// En fonction de la hauteur de l'image et de la hauteur du titre
	$(".blocEnAvant").each(function(){
		objImg = $(this).children("img");
		hImg = objImg.height();		
		objTitre = $(this).children("h3");
		hTitre = objTitre.height();		
		margeY = (128 - hTitre - hImg) >> 1;
		objImg.css("marginTop", margeY+"px").css("marginBottom", margeY+"px");
		
		// Centrage latéral si hmax atteinte
		if (hImg == 110)
		{
			margeX = (132 - objImg.width()) >> 1;
			objImg.css("marginLeft", margeX + "px");
		}
	});
	
	// Clic sur les blocs en avant
	$(".blocEnAvant").click(function(){
		lien = $(this).children("h3").children("a").attr('href');
		document.location.href = lien;
	});
	
	// Mise en page des images insérées dans les pages
	// Et gestion du zoom
	$("img.size-full, img.size-large, img.size-medium").removeAttr("width").removeAttr("height").css("width", "150px").addClass("zoomable");
	gestionZoom();	
});

function go() 
{
	positionnerElements();	
	window.onresize = positionnerElements;	
	$("body").css("visibility", "visible");		
}

function positionnerElements()
{
	l = $(window).width(); h = $(window).height();
	x = (l - 1000) >> 1; if (x < 0) x = 0;	
	xPartieDroite = x+180;	
	$("#partieGauche").css({width:xPartieDroite+"px", height:h+"px", backgroundPosition:(xPartieDroite-393)+"px"+" 0px"});
	$("#partieDroite").css({left:xPartieDroite+"px", height:h+"px", width:(l-xPartieDroite)+"px"});
	$("#barreCouleur").css({width:(xPartieDroite-179)+"px"});
}

function gestionZoom()
{
	$(".zoomable").click(function(){
		source = $(this).attr('src');
		$("body").append("<img id='photoBig' src='"+source+"'/>");
		lp = $(this).width(); hp = $(this).height();
		xp = $(this).offset().left; yp = $(this).offset().top;		
		$("#photoBig").css("width", lp+"px").css("left", xp+"px").css("top", yp+"px");
		$("#photoBig").animate({width:'450px', left:'-=150', top:'-='+hp}, 300);
		$("#photoBig").one("click", function(){
			$(this).animate({width:'150px', left:'+=150', top:'+='+hp}, 300, function(){$(this).remove();});			
		}).one("mouseleave", function(){
			$(this).animate({width:'150px', left:'+=150', top:'+='+hp}, 300, function(){$(this).remove();});			
		});
	});
}


function verifFormu()
{
	nom = $("#nom").attr("value");
	tel = $("#tel").attr("value");
	email = $("#email").attr("value");
	
	if (nom == "" || tel == "" || email == "") {alert("Veuillez renseigner tous les champs !"); return false;}
	
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
	if (! reg.test(email)) {alert("Votre adresse email comporte une erreur. Veuillez vérifier."); return false;}
	
	return true;
}



	




