﻿/**
 * @author nicolas
 */

var obj 		= null;
var img 		= null;
var conseil 		= null;
var conseilDelay	= null;
var conseilElt		= null;
var conseilEltActif = null;
var bBlock		= false;
var iCount		= 0;
var iDelay		= 200;	// Dellay pour rollOver conseil
var iQuestion	= null


//--- TEST SI SURVOL NOEUD PARENT ---//
function checkHover() {
	if (obj) {
		// --> Cache le sous menu
		obj.find('ul').hide();
		// --> Remet le lien normal
		if(img){
			img.css("font-weight", "normal");
			// --> Sauf pour la partie en cour
			$("#menu .first:eq("+iMenu+")").css("font-weight", "bold");
			$("#menu ul li a:eq("+iSsMenu+")").css("font-weight", "bold");
			$("#ssMenu .itemSsMenu a:eq("+iMenuBas+")").css("font-weight", "bold");
		}
	}
}
function checkHoverImg() {
	if (bBlock == false) {
		// --> Remet le lien normal
		if(img){
			img.css("font-weight", "normal");
			// --> Sauf pour la partie en cour
			$("#menu .first:eq("+iMenu+")").css("font-weight", "bold");
			$("#menu ul li a:eq("+iSsMenu+")").css("font-weight", "bold");
			$("#ssMenu .itemSsMenu a:eq("+iMenuBas+")").css("font-weight", "bold");
		}
	}
}
//------------//


//--- PLACE LE TEMOIN (fleche orange) ---//
function checkT5emoin() {
	if(iMenu){
		placeTemoin($("#menu .first:eq("+iMenu+")"), "menu");
	}
	if(iSsMenu){
		placeTemoin($("#menu ul li a:eq("+iSsMenu+")"), "sousMenu");
	}
	if(iMenuBas){
		placeTemoin($("#ssMenu .itemSsMenu a:eq("+iMenuBas+")"), "menuBas");
	}
	if(iFooter){
		$("#footer p a:eq("+iFooter+")").css("color", "#f36f21");
	}
}

function placeTemoin(elt, type) {
	elt.css("font-weight", "bold");
	// --> Repere les positions où placer le témoin
	var position	= elt.offset();
	var largeur		= elt.width();
	var hauteur		= elt.height();
	// --> CReer ses positions
	if(type == "menu"){
		var posX	= position.left + (largeur/2);
		var posY	= position.top + (hauteur);
		// --> Positionne le témoin
		$("#temoinMenu").css({ 'left' : posX, 'top' : posY, "display" : "block"});
		// --> Si IE, on décale
		if($.browser.msie) { 
			$("#temoinMenu").css('margin-top', '10px');
		};
	}else if(type == "menuBas"){
		var posX	= position.left + (largeur/2);
		var posY	= position.top + (hauteur) -10;
		// --> Positionne le témoin
		$("#temoinMenuBas").css({'left' : posX, 'top' : posY, "display" : "block"});
		// --> Si IE, on décale
		if($.browser.msie) { 
			$("#temoinMenuBas").css('margin-top', '10px');
		};
	}
}
//------------//

//--- CHECK MAIL SYNTAXE ---//
function verifmail(adrr){
	// --> Expression régulière
	var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	// Si c'est OK
	if(reg.test(adrr)==true){
		return true;
	// Sinon
	}else{
		return false;
	}
}
//------------//

function validateForm(){
	var email		= $("input[name=email]").val();
	var nom			= $("input[name=nom]").val();
	var prenom		= $("input[name=prenom]").val();
	var entreprise	= $("input[name=entreprise]").val();
	var phone		= $("input[name=phone]").val();
	var metier		= $('input:radio[name=metier]:checked').val();
	var newsLetter	= $('input:radio[name=newsletter]:checked').val();
	// --> Si on a pas les info clé, on annulle
	if(email=="" || nom=="" || entreprise==""){
		if((email!="") && (verifmail(email) == false))
			alert("Vous avez oublier de remplir certains champs et votre adresse email est incorrecte");
		else
			alert("Vous avez oublier de remplir certains champs");
        return false;
	// sinon on envois
	}else{
		if(verifmail(email)){
			return true;
		}else{
			alert("votre adresse email n'est pas correcte")
			return false;
		}
	}
}

//--- ON MASQUE OU PAS LE SOUS MENU ---//
$(window).load(function(){

	// --> On Place les témoins
	setTimeout(	"checkT5emoin()",	200);// on regarde sans cesse se on survol le parent

	$("#menu div").each(function(){
		// Au rollOver
		$(this).mouseover(function(){
			// --> Cache l'ancien
			if (obj) {
				obj.find('ul').hide();
				obj = null;
			}
			// --> Montre la liste
			$(this).children("ul").show();
		});
		
		// Au rollOut
		$(this).mouseout(function(){
			obj = $(this);
			setTimeout(	"checkHover()",	1000);// on regarde sans cesse se on survol le parent
		});
	});
	
	// CHANGE L'IMAGE AU ROLLOVER - ROLLOUT
	$("#menu .first").each(function(){
			if($(this).children() == $("#menu .first:eq(0)").children()){
				alert("coucou");
			}
		$(this).mouseover(function(){
			// --> Gestion du témoin (fleche orange)
			if(img){
				// --> Remet le lien normal
				img.css("font-weight", "normal");
				// --> Sauf pour la partie en cour
				$("#menu .first:eq("+iMenu+")").css("font-weight", "bold");
				$("#menu ul li a:eq("+iSsMenu+")").css("font-weight", "bold");
				$("#ssMenu .itemSsMenu a:eq("+iMenuBas+")").css("font-weight", "bold");
				// --> Supr la ref
				img = null;
			}
			bBlock	= false;
			// --> Change l'image
			$(this).css("font-weight", "bold");
		});
		$(this).mouseout(function(){
			img = $(this);
			bBlock	= false;
			setTimeout(	"checkHoverImg()", 0);// on regarde sans cesse se on survol le parent
		});
	});
	// CHANGE L'IMAGE SOUSMENU AU ROLLOVER - ROLLOUT
	$("#menu ul li a").each(function(){
		$(this).mouseover(function(){
			// --> Change l'image
			bBlock	= true;
			$(this).css("font-weight", "bold");
		});
		$(this).mouseout(function(){
			// --> Remet le lien normal
			bBlock	= false;
			$(this).css("font-weight", "normal");
			// --> Sauf pour la partie en cour
			$("#menu .first:eq("+iMenu+")").css("font-weight", "bold");
			$("#menu ul li a:eq("+iSsMenu+")").css("font-weight", "bold");
			$("#ssMenu .itemSsMenu a:eq("+iMenuBas+")").css("font-weight", "bold");
		});
	});
	
	
	// POUR LA PARTIE conseil //
	// --> Cache tout les actif
	$("#page #conseil ul li .actif").css("visibility", "Visible");
	$("#page #conseil ul li .actif").hide();
	// --> Montre le actif séléctionné
	$("#page #conseil ul li").click(function(event){
		// Test si pas déja déscendu
		if($(this).find(".inactif").val() == 0){
			$("#page #conseil ul li .inactif").val(0);
			$(this).find(".inactif").val(1);
			$("#page #conseil ul li .actif").hide();
			$("#page #conseil ul li .inactif").show();
			//$("#page #conseil ul li .actif").stop().hide();
			$(this).find(".actif").show();
			$(this).find(".inactif").hide();
		}
	}, { delay: 0 });
	if(iQuestion != null && iQuestion != ""){
		$("#page #conseil ul li .actif:eq("+iQuestion+")").show();
		$("#page #conseil ul li .inactif:eq("+iQuestion+")").hide();
	}
	
	
	// POUR PAGE ACCUEIL (block bas droite) //
	// --> Générique // --> Change l'image
	$("#page .content_bottom .right #text div").delayedMouseover(function(event){
		$(this).find("img").attr("src", "./images/btnLinkHover.png");
	}, { delay: 50 });
	$("#page .content_bottom .right #text div").mouseout(function(){
		$(this).find("img").attr("src", "./images/btnLink.png");
	});
	
	// --> Etudes
	$("#page .content_bottom .right #text #etudes").delayedMouseover(function(event){
		$(this).find("img").css({'margin-top' : '0px', 'margin-right' : '0px'});
		$(this).find("a").css('margin-left' , '9px');
		$(this).css('margin-left' , '78px');
	}, { delay: 50 });
	$("#page .content_bottom .right #text #etudes").mouseout(function(){
		$(this).find("img").css({'margin-top' : '6px', 'margin-right' : '6px'});
		$(this).find("a").css('margin-left' , '11px');
		$(this).css('margin-left' , '84px');
	});
	// --> gammes
	$("#page .content_bottom .right #text #gamme").delayedMouseover(function(event){
		$(this).find("img").css({'margin-top' : '-18px', 'margin-left' : '125px'});
		$(this).css('margin-bottom',"0px");
	}, { delay: 50 });
	$("#page .content_bottom .right #text #gamme").mouseout(function(){
		$(this).find("img").css({'margin-top' : '-11px', 'margin-left' : '131px'});
		$(this).css('margin-bottom',"15px");
	});
	// --> agencement
	$("#page .content_bottom .right #text #agencement").delayedMouseover(function(event){
		$(this).find("img").css({'margin-top' : '-18px', 'margin-left' : '145px'});
		$(this).css('margin-bottom',"-7px");
	}, { delay: 50 });
	$("#page .content_bottom .right #text #agencement").mouseout(function(){
		$(this).find("img").css({'margin-top' : '-11px', 'margin-left' : '154px'});
		$(this).css('margin-bottom',"15px");
	});
	// --> visioclips
	$("#page .content_bottom .right #text #visioclips").delayedMouseover(function(event){
		$(this).find("img").css({'margin-top' : '-18px', 'margin-left' : '125px'});
		$(this).css('margin-bottom',"0px");
	}, { delay: 50 });
	$("#page .content_bottom .right #text #visioclips").mouseout(function(){
		$(this).find("img").css({'margin-top' : '-11px', 'margin-left' : '131px'});
		$(this).css('margin-bottom',"15px");
	});
	
	// SLIDESHOW  HOME //
	$("#page .content .black .right img").hide();
	startSlidshow(0);
	//$("#page .content .black .right img:eq(0)").fadeIn("slow");

	
});
function startSlidshow(id){
	$("#page .content .black .right img:eq("+id+")").fadeIn("slow",function(){startSlidshow(id+1)});

}
// FONCTION POUR AJOUTER "delayedMouseover" //
(function($) {
 
  $.fn.delayedMouseover = function(callback, options) {
 
	var options = $.extend({ delay: 1000 }, options);
 
	return this.each(function() {
		var obj = $(this);
		var timer = false;
		obj.mouseover( function(event) {
			if(timer) clearTimeout(timer);
			timer = setTimeout( function() { callback.apply(obj[0], [event]); }, options.delay );
		});		
		obj.mouseout( function(event) {
			if(timer) clearTimeout(timer);
			timer = false;
		});		
	});
  };
 
})(jQuery);

