$(document).ready(function(){ 

	
	//Pictos - Produit
	//déplacer les pictos du contenu haut vers le contenu bas (onglets produit)
	if ( $(".pictos_bas").length ) {
	  var pictos = $(".pictos");
	  $('.pictos_bas').append(pictos.html());
	  $('.pictos_bas').removeClass('pictos_bas').addClass("pictos");
	  pictos.text('');
	}
	
	//Pictos - news single 
	//inversemment de positions entre le browser (suiv.préc) et le bloc Pictos
    if ( $(".pictos_single_news").length ) {
		var pictos = $(".pictos");
		$(".pictos_single_news").append(pictos.html());
		pictos.remove();
		$(".pictos_single_news").removeClass("pictos_single_news").addClass("pictos");
    }
   
	//alert('test');

	//Menu gauche
	$(".bouton-gauche-on a").show();

	//Bloc Ouvrir/Fermer - Flexible content
	$(".blocouvrirfermer-off a.lien-ouvrirfermer").click(function(){
		if ($(this).parent().parent().hasClass("blocouvrirfermer-off")) {
			$(this).parent().parent().children("div.contenu-ouvrirfermer").slideDown();
			$(this).parent().parent().addClass("blocouvrirfermer-on").removeClass("blocouvrirfermer-off");
			$(this).parent().parent().children("img").attr("src","fileadmin/templates/images/flechebleueclair-bas.jpg");
			return false;
		} else {
			$(this).parent().parent().children("div.contenu-ouvrirfermer").slideUp("slow",function(){ $(this).parent().addClass("blocouvrirfermer-off").removeClass("blocouvrirfermer-on");});
			$(this).parent().parent().children("img").attr("src","fileadmin/templates/images/flechebleueclair.jpg");
			return false;
		}
	});
	
	//Bloc Type FAQ - Flexible content
	$(".bloc-contenutypefaq a.lien-ouvrirfermer").click(function(){
		if ($(this).parent().parent().hasClass("bloc-contenutypefaq-off")) {
			$(this).parent().parent().children("div.contenu-contenutypefaq").slideDown();
			$(this).parent().parent().addClass("bloc-contenutypefaq-on").removeClass("bloc-contenutypefaq-off");
			return false;
		} else {
			$(this).parent().parent().children("div.contenu-contenutypefaq").slideUp("slow");
			$(this).parent().parent().addClass("bloc-contenutypefaq-off").removeClass("bloc-contenutypefaq-on");
			return false;
		}
	});

	
	//Home, rollover  - compatibilité IE6
	$("a.prehome-particulier").hover(function(){
		$(".prehome-bouton-particulier",this).css("background","url(fileadmin/templates/images/bg_prehome-bouton-particulier-hover.jpg) no-repeat right top");
	}, function(){
		$(".prehome-bouton-particulier",this).css("background","url(fileadmin/templates/images/bg_prehome-bouton-particulier.jpg) no-repeat right top");
	});
	$("a.prehome-entreprises").hover(function(){
		$(".prehome-bouton-entreprise",this).css("background","url(fileadmin/templates/images/bg_prehome-bouton-entreprise-hover.jpg) no-repeat right top");
	}, function(){
		$(".prehome-bouton-entreprise",this).css("background","url(fileadmin/templates/images/bg_prehome-bouton-entreprise.jpg) no-repeat right top");
	});
	$("a.prehome-groupe").hover(function(){
		$(".prehome-bouton-groupe",this).css("background","url(fileadmin/templates/images/bg_prehome-bouton-groupe-hover.jpg) no-repeat right top");
	}, function(){
		$(".prehome-bouton-groupe",this).css("background","url(fileadmin/templates/images/bg_prehome-bouton-groupe.jpg) no-repeat right top");
	});
	
	//Gestion du menu de niveau 3 - compatibilité IE6
	
	/*if($(".colonne-gauche-entreprises .bouton-gauche-off a").height) {
			alert ('test');
		}*/
	//alert($("colonne-gauche-entreprises .bouton-gauche-off").height());
	//alert($(".bouton-gauche-off").length);
	//alert($(".bouton-gauche-on h5 a").text().length);
	
	if ($(".colonne-gauche-particuliers .bouton-gauche-on").contents().length==1) {
		$(".colonne-gauche-particuliers .bouton-gauche-on").css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-particuliers2.gif) no-repeat");
	}
	if ($(".colonne-gauche-entreprises .bouton-gauche-on").contents().length==1) {
		$(".colonne-gauche-entreprises .bouton-gauche-on").css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-entreprises2.gif) no-repeat");
	}
	if ($(".colonne-gauche-groupe .bouton-gauche-on").contents().length==1) {
		$(".colonne-gauche-groupe .bouton-gauche-on").css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-groupe2.gif) no-repeat");
	}
	
	$(".colonne-gauche-entreprises .bouton-gauche-off").hover(function(){
		//alert($(this).contents().length);
		if ($(this).contents().length==1) {
			$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-entreprises2.gif) no-repeat");
		}
		else {
			$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-entreprises.gif) no-repeat");
		}
	},function(){
		$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-off.gif) no-repeat");
	});
	$(".colonne-gauche-particuliers .bouton-gauche-off").hover(function(){
		if ($(this).contents().length==1) {
			$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-particuliers2.gif) no-repeat");
		}
		else {
			$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-particuliers.gif) no-repeat");
		}
	},function(){
		$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-off.gif) no-repeat");
	});
	$(".colonne-gauche-groupe .bouton-gauche-off").hover(function(){
		if ($(this).contents().length==1) {
			$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-groupe2.gif) no-repeat");
		}
		else {
			$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-on-groupe.gif) no-repeat");
		}
	},function(){
		$(this).css("background","url(fileadmin/templates/images/bg_bouton-gauche-off.gif) no-repeat");
	});
	
	//alert($(".bouton-gauche-on h5 a").text().length);
	/*if($(".bouton-gauche-on h5 a").text().length > 21) 
	{ $(".bouton-gauche-on h5 a").css("padding-top","1px").height(34); }
	*/
	
	//$(".bouton-gauche-on h5 a").css("padding-top","1px").height(34);
	
	
	//Gestion du menu niveau 3 survolé - BUG (ok jch)
	$(".ligne_menu_niveau2").mouseenter(function(){
		$(this).children(".menu-extended").show();
	});
	$(".ligne_menu_niveau2").mouseleave(function(){
		$(this).children(".menu-extended").hide();
	});
	
	$(".extended li").mouseover(function(){
		var txt = $(this).children().children(".subTitle").html();
		if (txt != null) {
			$(this).parent().parent().children(".extended-2").html(txt);
		} else {
			$(this).parent().parent().children(".extended-2").html("");
		}
	});
	$(".ligne_menu_niveau2").each(function(i){
		var left = i*(90+34);
		if (i < 2) {
			$(this).children(".menu-extended").css("left",left);
		} else {
			if ($(".menu").hasClass("menu-entreprises")) { $(this).children(".menu-extended").css("left",220);}
			if ($(".menu").hasClass("menu-particuliers")) { $(this).children(".menu-extended").css("left",290);}
			if ($(".menu").hasClass("menu-groupe")) { $(this).children(".menu-extended").css("left",220);}
		}
		
	});
	
	//Suppression des menus survolé de niveau 3 vide
	$(".menu-extended").each(function(i){
		var listeAvide = $("a:empty",this).get().length; //Récupère tous les liens vide du menu
		var listeA = $("a",this).get().length; //Récupère tous les liens du menu
		if (listeAvide == listeA) {
			$(this).remove();
		}
	});
	
	//Menu niveau 2 - titre multiligne
	$(".menu-bas a.sous-menu-1-ligne").each(function(i){
		if ($(this).height() >= 28) {
			$(this).removeClass("sous-menu-1-ligne").addClass("sous-menu-1-ligne-2lignes");
		}
	
	});
	
	//Menu gauche - titre multiligne
	$(".colonne-gauche div h5 a").each(function(i){
		if ($(this).height() > 30) {
			$(this).attr('id', 'titre_long');
		}
	});
		
	//Page Plan du site
	$(".csc-sitemap a").each(function(i) {
		//-- Ajout des images
		if ($(this).siblings("ul").size() != 0) {
			$(this).before("<img src='fileadmin/templates/images/plus.gif' class='plansite_plus'/>&nbsp;");
		} else {
			$(this).before("<img src='fileadmin/templates/images/page.gif' class='plansite_page'/>&nbsp;");
		}	
	}); 
	
	$(".csc-sitemap img").click(function(){ //-- ouverture/fermeture des blocs
		if ($(this).hasClass("plansite_plus")) {
			$(this).siblings("ul").slideDown();
			$(this).addClass("plansite_moins").removeClass("plansite_plus").attr("src","fileadmin/templates/images/moins.gif");
		} else {
			$(this).siblings("ul").slideUp();
			$(this).removeClass("plansite_moins").addClass("plansite_plus").attr("src","fileadmin/templates/images/plus.gif");
		}
	});
	
	//FAQ
	$(".tx-irfaq-pi1 div.titrefaq a").click(function(){
		if ($(this).parent().parent().hasClass("faq-on")) {
			$(this).parent().parent().addClass("faq-off").removeClass("faq-on");
			$(this).parent().parent().children("div.contenufaq").slideUp("slow");
		} else {
			$(this).parent().parent().addClass("faq-on").removeClass("faq-off");
			$(this).parent().parent().children("div.contenufaq").slideDown("fast");
		}
		return false;
	});
	
	var url = location.href.split('#uidfaq_');
	if (url.length > 1) {
		$(".tx-irfaq-pi1 div.titrefaq a.uidfaq_"+url[1]).click();
	}
	
	/*Glossaire*/
	$('.glossaire img.img_clic').click(function(){
		//alert('test1');
		//var div = jQuery("div.actus").children("");
		//var div = jQuery(".actu_desc");
		var div = $(this).parent().parent().children("ul");
		//alert(div);
		if (div.css("display")=="none") {
			//alert('test2');
			div.css({display:"block"});
			$(this).attr('src','fileadmin/templates/images/afficher1.png');
		}
		else {
			div.css({display:"none"});
			$(this).attr('src','fileadmin/templates/images/masquer1.png');
		}
	});
	
	/*Tout ouvrir - On peut rajouter autant de niveaux qu'on le souhaite*/
//var expall = function(){
	$('.outils_conteneur a[class!=glossary-back]').click(function(){
		//alert('aaa');
		//alert('test');
		var div = jQuery("ul.level2");
		var div2 = jQuery("ul.level3");
		if (div.css("display")=="none") {
			//alert('test2');
			div.css({display:"block"});
			jQuery(".img_clic").attr('src','fileadmin/templates/images/afficher1.png');
		}
		else {
			div.css({display:"none"});
			jQuery(".img_clic").attr('src','fileadmin/templates/images/masquer1.png');
		}
		if (div2.css("display")=="none") {
			//alert('test2');
			div2.css({display:"block"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/afficher1.png');
		}
		else {
			div2.css({display:"none"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/masquer1.png');
		}
	});
//}

//var expall_ps = function(){
	jQuery('#expand_ps_entr img').click(function(){
		/*var div = jQuery('.ps_entreprise').children('ul');
		var div2 = jQuery('.ps_entreprise').children().children().children('ul');*/
		
		var div = jQuery('.ps_entreprise').children('ul.level2');		
		var div2 = jQuery('.ps_entreprise').children('ul.level2').children().children('ul.level3');
		var div3 = jQuery('.ps_entreprise').children('ul.level2').children().children('ul.level3').children().children('ul.level4');
		
		
		if (div.css("display")=="none") {
			div.css({display:"block"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/afficher1.png');
		}
		else {
			div.css({display:"none"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/masquer1.png');
		}
		
		if (div2.css("display")=="none") {
			div2.css({display:"block"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/afficher1.png');
		}
		else {
			div2.css({display:"none"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/masquer1.png');
		}
		//niveau 3
		if (div3.css("display")=="none") {
			div3.css({display:"block"});
		}
		else {
			div3.css({display:"none"});
		}
	});
	
	jQuery('#expand_ps_part img').click(function(){
		//alert('test');
		//var div = jQuery("ul.level2");
		
		/*TEST*/
		var div = jQuery('.ps_part').children('ul.level2');
		
		//var div2 = jQuery("ul.level3");
		var div2 = jQuery('.ps_part').children('ul.level2').children().children('ul.level3');
		var div3 = jQuery('.ps_part').children('ul.level2').children().children('ul.level3').children().children('ul.level4');
		
		if (div.css("display")=="none") {
			div.css({display:"block"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/afficher1.png');
		}
		else {
			div.css({display:"none"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/masquer1.png');
		}
		
		if (div2.css("display")=="none") {
			//alert('test2');
			div2.css({display:"block"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/afficher1.png');
		}
		else {
			div2.css({display:"none"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/masquer1.png');
		}
		
		//niveau 3
		if (div3.css("display")=="none") {
			div3.css({display:"block"});
		}
		else {
			div3.css({display:"none"});
		}
		
	});
	
	jQuery('#expand_ps_groupe img').click(function(){

		
		
		var div = jQuery('.ps_groupe').children('ul.level2');		
		var div2 = jQuery('.ps_groupe').children('ul.level2').children().children('ul.level3');
		var div3 = jQuery('.ps_groupe').children('ul.level2').children().children('ul.level3').children().children('ul.level4');
		
		if (div.css("display")=="none") {
			//alert('test2');
			div.css({display:"block"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/afficher1.png');
		}
		else {
			div.css({display:"none"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/masquer1.png');
		}
		
		if (div2.css("display")=="none") {
			//alert('test2');
			div2.css({display:"block"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/afficher1.png');
		}
		else {
			div2.css({display:"none"});
			//jQuery(".img_clic").attr('src','fileadmin/templates/v1/img/VEL/icones/masquer1.png');
		}
		//niveau 3
		if (div3.css("display")=="none") {
			div3.css({display:"block"});
		}
		else {
			div3.css({display:"none"});
		}
	});
//}

/*RECHERCHE*/
	/*Onglets recherche*/
	/*jQuery('a.onglet-recherche-on').click(function(){
		//alert('1');
		//jQuery('a.onglet-recherche-on').removeClass("onglet-recherche-on").addClass("onglet-recherche-off");
		$(this).css({color:"red"});
	});
	jQuery('a.onglet-recherche-off').click(function(){
		//alert('2');
		//jQuery('a.onglet-recherche-off').removeClass("onglet-recherche-off").addClass("onglet-recherche-on");
		$(this).css({color:"blue"});
	});*/
	/*$('#onglet2').click(function() {
		$('#testsect').value='rl1_2';
		$('#tx_indexedsearch').submit();
	});*/
	

/*rustines*/
/*suppression d'une div sur le moteur de recherche*/
if($('form#tx_indexedsearch').length) {

   $('div').removeClass('bloc-gauche-large')
}


/*rollovers IE6*/
$(".header-droite-4").mouseover(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
		$('.header-droite-4').css("background", "url(fileadmin/templates/images/bg-header-droite-4-hover.png)");
	}
});
$(".header-droite-4").mouseleave(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
		$('.header-droite-4').css("background", "url(fileadmin/templates/images/bg-header-droite-4.png)");
	}
});

$(".bouton-questions-reponses").mouseover(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
		$('.bouton-questions-reponses').css("background", "url(fileadmin/templates/images/bg_bouton-questions-reponses-hover.jpg) no-repeat scroll 19px 19px transparent");
		$('.bouton-questions-reponses a:hover').css("color", "#FFFFFF");
	}
});
$(".bouton-questions-reponses").mouseleave(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") { 
		$('.bouton-questions-reponses').css("background", "url(fileadmin/templates/images/bg_bouton-questions-reponses-groupe.jpg) no-repeat scroll 19px 19px transparent");
		$('.bouton-questions-reponses a:hover').css("color", "#FFFFFF");
	}
});

$(".bouton-engage").mouseover(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") { 
		$('.bouton-engage').css("background", "url(fileadmin/templates/images/bg_bouton-questions-reponses-hover.jpg) no-repeat scroll 19px 19px transparent");
	}
});
$(".bouton-engage").mouseleave(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") { 
		$('.bouton-engage').css("background", "url(fileadmin/templates/images/bg_bouton-questions-reponses-groupe.jpg) no-repeat scroll 19px 19px transparent");
	}
});

$(".search-header-bouton").mouseover(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") { 
		$('.search-header-bouton').css("background", "url(fileadmin/templates/images/bg_bouton-search-header-hover.png)");
	}
});
$(".search-header-bouton").mouseleave(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") { 
		$('.search-header-bouton').css("background", "url(fileadmin/templates/images/bg_bouton-search-header.png)");
	}
});

$(".bouton-contact").mouseover(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") { 
		$('.bouton-contact').css("background", "url(fileadmin/templates/images/bouton-form-hover.jpg)");
	}
});
$(".bouton-contact").mouseleave(function(){
	if (jQuery.browser.msie && jQuery.browser.version == "6.0") { 
		$('.bouton-contact').css("background", "url(fileadmin/templates/images/bouton-form.jpg)");
	}
});

//if ($(".bouton-contact").value.le) {
//}
//alert($(".bouton-gauche-off").value.length);



	//COrrection d'un bug IE6 pour le bloc accès rapide
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
	      var nb = $(".acces-rapides .acces-rapides2 .acces-rapides-bloc").size();
		  var taille = (nb+1)*145;
		  $(".acces-rapides").width(taille);
	}



});

function extendedon (id){
	document.getElementById(id).style.display='block';
}

function extendedoff (id){
	document.getElementById(id).style.display='none';
}

function flecheon (id){
	document.getElementById(id).style.display='block';
}

function flecheoff (id){
	document.getElementById(id).style.display='none';
}

function ongleton (id){
	document.getElementById(id).className='onglet-on';
}

function ongletoff (id){
	document.getElementById(id).className='onglet-off';
}

function ongletrechercheon (id){
	document.getElementById(id).className='onglet-recherche-on';
}

function ongletrechercheoff (id){
	document.getElementById(id).className='onglet-recherche-off';
}

function divon(id_onglet,id_div){
	//désactivation du lien actif
	var actif = $("a.onglet-actif").removeClass("onglet-actif").addClass("onglet-off");
	//activation du lien inactif
	var inactif = $("#"+id_onglet).removeClass("onglet-off").addClass("onglet-actif");
	//on cache toutes les divs
	//$(".onglet div.onglet-contenu").hide();
	$(".onglet div.onglet-contenu").css({display:"none"});
	//on affiche la div associé à l'onglet activé
	//$("#"+id_div).show(); //FF
	$("#"+id_div).css({display:"block"}); //IE6
}



