$(document).ready(function() {
	
	
	$("a[href^='http:']").each(function(i){$(this).not("[href*=\""+document.domain+"\"]").not(":has(img)").html($(this).html()).attr('target','_blank').addClass("lienExt");});
	$("a[href$='.pdf']").each(function(i){$(this).not("[href*=\""+document.domain+"\"]").not(":has(img)").html($(this).html()+"<img src=\"../../../public/commun/medias/images/pdf_logo.png\" alt=\"\" title=\"Ouvrir ce fichier dans une nouvelle fenetre\"  >").attr('target','_blank').addClass("lienPDF");});
	$(".menu_principal").find("a").bind("mouseover", afficherMenuSecondaire);
	$(".menu_principal").find("a").bind("mouseout", cacherMenuSecondaire);
	$(".menu_secondaire_div").hide();
	$(".lienSousMenu").removeClass("hide");
	$(".menu_secondaire_div").trigger("mouseover")
	
	$("#tweet").fadeIn(1500);
	
	function afficherMenuSecondaire()
	{
		var monHref = $(this).attr("href");
		var positionDash  = monHref.lastIndexOf("/") + 1;
		var positionDoth  = monHref.lastIndexOf(".");
		var nomPage 	   = ""; 
		//alert(positionDoth)
		if (positionDoth == -1 || positionDoth == 1 || positionDoth == 4) {
			
			nomPage = monHref.substring(positionDash);
		
		} else {
		
			nomPage = monHref.substring(positionDash, positionDoth);
		
		}
		$("#menu_secondaire_" + nomPage).show();
		$("#menu_secondaire_" + nomPage).bind("mouseover", garderAfficher)
	}
	
	
	function cacherMenuSecondaire()
	{
		var monHref = $(this).attr("href");
		var positionDash  = monHref.lastIndexOf("/") + 1;
		var positionDoth  = monHref.lastIndexOf(".");
		var nomPage 	   = ""; 
		if (positionDoth == -1 || positionDoth == 1 || positionDoth == 4) {
			nomPage = monHref.substring(positionDash);
		} else {
			nomPage = monHref.substring(positionDash, positionDoth);
		}
		$("#menu_secondaire_" + nomPage).hide();
	}
	
	function garderAfficher()
	{
		var position = $(this).attr("id").lastIndexOf("_");
		var nomPage = $(this).attr("id").substring(position+1);
		$("#menu_principal_" + nomPage).addClass("menu_principal_jquery");
		$(this).show();
		$(this).bind("mouseout", cacherMenuSecondaireDeux);
	}
	
	function cacherMenuSecondaireDeux()
	{
		var position = $(this).attr("id").lastIndexOf("_");
		var nomPage = $(this).attr("id").substring(position+1);
		$("#menu_principal_" + nomPage).removeClass("menu_principal_jquery");
		$(this).hide();	
	}
});
