/*----------------------------------------------------------------------------//
// Javascript pour le site client  -------------------------------------------//
//----------------------------------------------------------------------------//
// Client : -
// Note	  : -
// Date	  : -
//----------------------------------------------------------------------------*/
(function(w,$,undefined){
		
	/*----------------------------------------------------------------------------*/
	// Inclusion dynamique des fichiers externes javascripts
	/*----------------------------------------------------------------------------*/
	function importJavascript(src) {
		document.write("<script type=\"text/javascript\" src=\"" + src + "\"></scr" + "ipt>");
	}
	function importCss(href, media) {
		document.write('<link rel="stylesheet" type="text/css" media="' + media + '" href="' + href + '" />');
	}
	
	/*----------------------------------------------------------------------------*/
	// Importations de fichiers
	/*----------------------------------------------------------------------------*/
	// importJavascript("/includes/js/plugins/jquery.plugin.js");
	// importCss("/includes/js/plugins/jquery.plugin.css", "screen");
	importJavascript("/includes/js/plugins/jquery.watermarkinput.js");
	importJavascript("/includes/js/plugins/jquery.ifixpng.js");
	importJavascript("/includes/js/plugins/abso.caroussel.js");
	
	/*----------------------------------------------------------------------------*/
	// Declarations jQuery
	/*----------------------------------------------------------------------------*/
	
	var CGA = {};
	
	CGA.InitDropDown = function() {
		$("div.DropDown p a").click(function() {
			var parentDD = $(this).parents("div.DropDown");
			$("ul", parentDD).show();
			$("ul a", parentDD).click(function() {
				
				$("ul a", parentDD).removeClass("On");
				$(this).addClass("On");
				$("ul", parentDD).hide();
				$("p a", parentDD).text($(this).text())
				//$(this).unbind("click");
				//return false;
			});
			$(document).bind("click", function() {
				$("ul", parentDD).hide();
				//$(this).unbind("click");
				//return false;
			});
			return false;
		});
	}
	CGA.CheckSearch = function(e) {
		if (window.event) { // IE
			keynum = e.keyCode;
		} else if (e.which) { // Netscape/Firefox/Opera
			keynum = e.which;
		}
		// Si Enter
		if (keynum == 13) {
			// Lancer la recherche
			redirectToSearchPage();
			return false;
		}		
		return true;
	}
	CGA.redirectToSearchPage = function() {
		var query = $('#txtRecherche').val();
		if (query != null && query != '') {
			window.location = searchPageUrl + "?lang=" + searchLang + "&q=" + query;
		}
	}
	
	$(document).ready(function() {
	
		//Format de contenu
		if ($("hr") != null) {
			$("hr").replaceWith("<div class=\"HR\"></div>");
		}
		//Watermark Recherche
		$("#txtRecherche").each(function() { //#Entete .Recherche input:text, body.RechercherCGA div.Formulaire input:text
		var defaultText = $(this).attr("title");
			$(this).Watermark(defaultText);
		});
	
		// DropDowns
		CGA.InitDropDown();
		
		//Pubs entête
		Abso.Caroussel.init({
			id: 'PubEntete',
			wrap: true,
			autostart: {
				interval: 6000
			},
			speed: 400,
			transition: 'fade'
		});
		
		//Accueil - Sections
		$("body.Accueil #HautPage .Onglets .Nav a").click(function() {
			var currentTab = $(this).parent().attr("class");
			$("body.Accueil #HautPage .Onglets .Nav a").removeClass("On");
			$(this).addClass("On");
			$("body.Accueil #HautPage .Onglets div.Nouvelles, body.Accueil #HautPage .Onglets div.Publications").hide();
			$("body.Accueil #HautPage .Onglets div." + currentTab).show();
		});
		$("body.Accueil #Contenu .Section h2 a").click(function() {
			$("body.Accueil #Contenu .Section").removeClass("On");
			$(this).parents(".Section").addClass("On");
		});
	
		//Accueil - Témoignages
		$.ifixpng("/images/spacer.gif");
		$("#Temoignage .Photo img").ifixpng();
	
		//Intérieur - Foire aux questions
		$("#FAQ h4 a").click(function() {
			var hadClassOn = $(this).parents(".Section").hasClass("On");
			$("#FAQ .Section").removeClass("On");
			if (!hadClassOn)
				$(this).parents(".Section").addClass("On");
			return false;
		});
		//-- Pour la recherche COVEO-----------------
		$('#btnRecherche').click(function() {
			redirectToSearchPage();
		});
	
	});
		
	w.OrdreDesCGA = CGA;
	
})(window,jQuery);

function InitDropDown() {
	OrdreDesCGA.InitDropDown();
}
function CheckSearch(e) {
	OrdreDesCGA.CheckSearch(e);
}
function redirectToSearchPage() {
	OrdreDesCGA.redirectToSearchPage();
}

