
$(document).ready(function() {

	initMenu();
	
	//Form validation
	initContactUsFormValidation();
	initMovingFormValidation();
	initLivraisonCourrielFormValidation();
	
	//init page tarifs
	initTarifs();
	
	
	//watermark de la boÓte de recherche
	$("#txtSearch").focus(function(){$(this).val('');}).blur(function(){$(this).val('Rechercher');});
});



var initMenu = function(){
	$('#nav4').droppy({speed:200});
	$("#nav4 > li").each(function(i){
		
		var maxTextWidth = $(this).width();
		$(this).children("ul").children("li").each(function(i){
			$("#text_width").html($(this).html());
			if($("#text_width").width() > maxTextWidth)
			maxTextWidth = $("#text_width").width();	
		});
		
		maxTextWidth = maxTextWidth + 50;
		$(this).children("ul").css("cssText", "width: " + maxTextWidth + "px !important;")
			.children("li").css("cssText", "width: " + maxTextWidth + "px !important;");
	
	});
	
	$("#text_width").remove();		
	$("#nav4 li").addClass("menu_noActiveMenu");//css('width', '148px !important');
}

var initContactUsFormValidation = function(){
	$("#formContactUs").validate({
		messages:{
			txtPrenom: '&nbsp;Le pr&eacute;nom est requis.',
			txtNom: '&nbsp;Le nom est requis.',
			txtEmail: {
				required: '&nbsp;L\'adresse de courriel est requise.',
				email:	'&nbsp;L\'adresse de courriel est invalide.'
			},
			txtMessage: '&nbsp;Le message est requis.'
		},
		errorClass: 'txtError',
		errorLabelContainer: '#divError',
		wrapper: 'li'
	});
}

var initMovingFormValidation = function(){
	$("#formMoving").validate({
		messages:{
			txtPrenom: '&nbsp;Le pr&eacute;nom est requis.',
			txtNom: '&nbsp;Le nom est requis.',
			txtPhone: '&nbsp;Le num&eacute;ro de t&eacute;l&eacute;phone est requis.',
			txtEmail: {
				required: '&nbsp;L\'adresse de courriel est requise.',
				email:	'&nbsp;L\'adresse de courriel est invalide.'
			},
			txtAddress: '&nbsp;L\'adresse est requise.',
			txtCity: '&nbsp;La ville est requise.',
			txtPostalCode: '&nbsp;Le code postal est requis.'
		},
		errorClass: 'txtError',
		errorLabelContainer: '#divError',
		wrapper: 'li'
	});
}

var initLivraisonCourrielFormValidation = function(){
	$("#formLivraisonCourriel").validate({
		messages:{
			txtPrenom: '&nbsp;Le pr&eacute;nom est requis.',
			txtNom: '&nbsp;Le nom est requis.',
			txtNoMembre: '&nbsp;Le n<sup>o</sup> de membre est requis.',
			txtPhone: '&nbsp;Le num&eacute;ro de t&eacute;l&eacute;phone est requis.',
			txtEmail: {
				required: '&nbsp;L\'adresse de courriel est requise.',
				email:	'&nbsp;L\'adresse de courriel est invalide.'
			},
			txtAddress: '&nbsp;L\'adresse est requise.',
			txtCity: '&nbsp;La ville est requise.',
			txtPostalCode: '&nbsp;Le code postal est requis.'
		},
		errorClass: 'txtError',
		errorLabelContainer: '#divError',
		wrapper: 'li'
	});
}

var initTarifs = function(){
	
	$(".divTarifsContainer table").addClass("tblTarifs");
	$(".tblTarifs").each(function(i){
		$(this).children("tbody").children("tr").each(function(indexRow){
			if(indexRow == 0)
				$(this).addClass("tblTarifs_FirstRow");
			else if (indexRow == 1)
				$(this).addClass("tblTarifs_SecondRow");
			else{
				$(this).addClass("tblTarifs_DataRow");
				if(indexRow % 2 == 1 && indexRow > 2)
					$(this).css('background', '#DDD');
			}
		});
	
	});
	
	$(".tblTarifs .tblTarifs_FirstRow").each(function(i){
		$(this).children('th:first, td:first').addClass('tblTarifsFirstHeaderCell');
	});
			
	$(".tblTarifs_DataRow").each(function(i){
		$(this).children("td:first").addClass("tblTarifs_Categorie");
	});
	
	$(".voirInformations").click(function(){
		var nodeId = $(this).attr("rel");
		if($('#divInformations_' + nodeId).height() > 0){
			$(this).html("Afficher plus d'informations");
			$("#divInformations_" + nodeId).animate({height: '0px', opacity: 0}, LENGTH, function(){$("#divInformations_" + nodeId).hide();});
		} else {
			$(this).html("Cacher les informations");
			$("#divInformations_" + nodeId).animate({height: '140px', opacity: 1.0}, LENGTH);
		}
		
		return false;
	});

}