 //GESTION DU MENU
 sfHover = function() {
   var sfEls = document.getElementById("menu-principal").getElementsByTagName("li");
   for (var i=0; i<sfEls.length; i++) {
     sfEls[i].onmouseover=function() {
             this.className+=" sfhover";
     }
     sfEls[i].onmouseout=function() {
             this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
     }
   }
 }
 if (window.attachEvent) window.attachEvent("onload", sfHover);

    
function GereControle(Controleur, Controle) {
    var objControleur = document.getElementById(Controleur);
    var objControle = document.getElementById(Controle);
    objControle.style.display=(objControleur.checked==true)?'block':'none';
    return true;
}

function hide_all(){
    $('#menu-item-381 > ul').hide();
    $('#menu-item-54 > ul').hide();
    $('#menu-item-184 > ul').hide();
    $('#menu-item-53 > ul').hide();
    $('#menu-item-1814 > ul').hide();
    $('#menu_publication > ul').hide();
    $('.submenu_button').parent().children(".subsub-menu").hide();
    $('.submenu_button IMG').attr("src","/wp-content/themes/eti/images/dropdown_round.jpg");
}

function hide_all_submenu(){
    $('.submenu_1073').parent().children(".subsub-menu").hide();
    $('.submenu_1073 IMG').attr("src","/wp-content/themes/eti/images/dropdown_round.jpg");
    $('.submenu_1074').parent().children(".subsub-menu").hide();
    $('.submenu_1074 IMG').attr("src","/wp-content/themes/eti/images/dropdown_round.jpg");
    $('.submenu_abos').parent().children(".subsub-menu").hide();
    $('.submenu_abos IMG').attr("src","/wp-content/themes/eti/images/dropdown_round.jpg");
    $('.submenu_essais').parent().children(".subsub-menu").hide();
    $('.submenu_essais IMG').attr("src","/wp-content/themes/eti/images/dropdown_round.jpg");
}

$(document).ready(function(){

    hide_all();

    $('li.current_menu > ul').show();


    $('.menu-item-381').hover(
        function () {
            hide_all();
            $('#menu-item-381 > ul').show();
            $('#menu-conteneur').addClass("over_home");
            $('li.current_menu').addClass("grey_link");
        },
        function () {
            hide_all();
            $('li.current_menu > ul').show();
            $('#menu-conteneur').removeClass("over_home");
            $('li.current_menu').removeClass("grey_link");
        }
    );

    $('.menu-item-54').hover(
        function () {
            hide_all();
            $('#menu-item-54 > ul').show();
            $('#menu-conteneur').addClass("over_boutique");
            $('li.current_menu').addClass("grey_link");
        },
        function () {
            hide_all();
            $('li.current_menu > ul').show();
            $('#menu-conteneur').removeClass("over_boutique");
            $('li.current_menu').removeClass("grey_link");
        }
    );

    $('.menu-item-184').hover(
        function () {
            hide_all();
            $('#menu-item-184 > ul').show();
            $('#menu-conteneur').addClass("over_actu");
            $('li.current_menu').addClass("grey_link");
        },
        function () {
            hide_all();
            $('li.current_menu > ul').show();
            $('#menu-conteneur').removeClass("over_actu");
            $('li.current_menu').removeClass("grey_link");
        }
    );

    $('.menu-item-53').hover(
        function () {
            hide_all();
            $('#menu-item-53 > ul').show();
            $('#menu-conteneur').addClass("over_bao");
            $('li.current_menu').addClass("grey_link");
        },
        function () {
            hide_all();
            $('li.current_menu > ul').show();
            $('#menu-conteneur').removeClass("over_bao");
            $('li.current_menu').removeClass("grey_link");
        }
    );
    
    $('.menu-item-1814').hover(
        function () {
            hide_all();
            $('#menu-item-1814 > ul').show();
            $('#menu-conteneur').addClass("over_formation");
            $('li.current_menu').addClass("grey_link");
        },
        function () {
            hide_all();
            $('li.current_menu > ul').show();
            $('#menu-conteneur').removeClass("over_formation");
            $('li.current_menu').removeClass("grey_link");
        }
    );

    $('.menu_publication').hover(
        function () {
            hide_all();
            $('#menu_publication > ul').show();
            $('#menu-conteneur').addClass("over_publication");
            $('li.current_menu').addClass("grey_link");
        },
        function () {
            hide_all();
            $('li.current_menu > ul').show();
            $('#menu-conteneur').removeClass("over_publication");
            $('li.current_menu').removeClass("grey_link");
        }
    );


    $('.submenu_1073').hover(
        function () {
                hide_all_submenu()
                $('.submenu_1073').parent().children(".subsub-menu").show();
                $('.submenu_1073 IMG').attr("src","/wp-content/themes/eti/images/dropdown_deplie2.jpg");
        },
        function () {    
        }
    );

    $('.submenu_1074').hover(
        function () {
                hide_all_submenu()
                $('.submenu_1074').parent().children(".subsub-menu").show();
                $('.submenu_1074 IMG').attr("src","/wp-content/themes/eti/images/dropdown_deplie2.jpg");
        },
        function () {
        }
    );

    $('.submenu_abos').hover(
        function () {
                hide_all_submenu()
                $('.submenu_abos').parent().children(".subsub-menu").show();
                $('.submenu_abos IMG').attr("src","/wp-content/themes/eti/images/dropdown_deplie2.jpg");
        },
        function () {
        }
    );

    $('.submenu_essais').hover(
        function () {
                hide_all_submenu()
                $('.submenu_essais').parent().children(".subsub-menu").show();
                $('.submenu_essais IMG').attr("src","/wp-content/themes/eti/images/dropdown_deplie2.jpg");
        },
        function () {
        }
    );

    $('.submenu_2860').hover(
        function () {
                hide_all_submenu()
                $('.submenu_2860').parent().children(".subsub-menu").show();
                $('.submenu_2860 IMG').attr("src","/wp-content/themes/eti/images/dropdown_deplie2.jpg");
        },
        function () {
        }
    );

    $('.bandeau .togglelog').click(function() {
		$('#header-login #log').css("top", "");
		$('#header-login #log').css("left", "");
    	$("a span.bt_arrow_login").addClass("bt_arrow_login_hover");
    });
	
    $('#header-login ul.login-menu li').toggle(
        function() {
            $('#header-login #log').css("top", "");
            $('#header-login #log').css("left", "");
            $("a span.bt_arrow_login").addClass("bt_arrow_login_hover");
        },
        function() {
            $('#header-login #log').css("top", "-999px");
            $('#header-login #log').css("left", "-999px");
            $("a span.bt_arrow_login").removeClass("bt_arrow_login_hover");
        }
        );

});

 $('.affiche').hide();
 $(function(){
var box= $('#tool_box');
$("img[name='i_toolbox']").hover(
                                    function(){
                                                $(this).mousemove(function(e){
                                                   box.css({display:'block',top:e.pageY+3,left:e.pageX+3 });
                                     })
                                    },function(){ box.css({display:'none'});
                                  });
});

$('.affiche').hide();
$(function(){
    if($("body").hasClass("page-template-pageaccueil-php") || $("body").hasClass('page-template-page-boutique-php'))
        {
    $('#wrapper_carousel').cycle({
        fx:'all',
    next:$('span .chevronsdroite'),
    prev:$('span .chevronsgauche'),
    speed: 1000,
     pager:$('#btn_carousel'),
     pagerAnchorBuilder:false,
    activePagerClass: 'lien_blanc'
 
    });
    var speed = 18000;
    //supprime les liens ajouter automatiquement : <a href#> 1 </a> etc...
    for(i=0;i<$('div[id^="affiche"]').length;i++) $('#btn_carousel a').last().remove();

   $('#toggle1 a').click(function(){
         $('#wrapper_carousel').cycle(0).cycle('pause').delay(speed).cycle('resume');
   });
    $('#toggle2 a').click(function(){
         $('#wrapper_carousel').cycle(1).cycle('pause').delay(speed).cycle('resume');
   });
    $('#toggle3 a').click(function(){
         $('#wrapper_carousel').cycle(2).cycle('pause').delay(speed).cycle('resume');
   });

        }
});



$(function(){
   if( $('tr[id^="tr_abo"]').size()==0 ) {jQuery('#abonnements').hide(); };

});
   
$(function(){
   $(".hover_gradient_shadow").hover(
  function () {
    $(this).addClass("gradient_shadow_boutique shadow");
  },
  function () {
    $(this).removeClass("gradient_shadow_boutique shadow");
  }
);

$(".bg_center_arrondis_gris2").hover(
  function () {
    $(this).addClass("gradient_shadow_boutique shadow");
  },
  function () {
    $(this).removeClass("gradient_shadow_boutique shadow");
  }
);
  
});





jQuery.fn.extend({
   findPos : function() {
       obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});

function show_overlay(id) {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objPlan = document.getElementById(id);
	var objOverlay = document.getElementById('overlay');
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objPlan.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 600) / 2) + 'px');
	objPlan.style.left = (((arrayPageSize[0] - 600) / 2) + 'px');
	jQuery('#overlay').fadeIn("slow");
	jQuery('#'+id).fadeIn("slow");
	}
function close_overlay(id) {
	jQuery('#'+id).fadeOut("slow");
	jQuery('#overlay').fadeOut("slow");
}
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){pageHeight = windowHeight;} else {pageHeight = yScroll;}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth) {pageWidth = windowWidth;} else {pageWidth = xScroll;}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function check_mail(email)
{
	var verif = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/;
	if (verif.exec(email) == null)
	{
		alert("Votre adresse e-mail est incorrecte");
		return false;
	}
	else
		return true;
}

function	change_div_lightbox(link, id)
{
	var	content;

	content = '<div class="bg_popup_top">&nbsp;</div>';
	content += '<div class="wrapper_proposer">';
		content += '<div class="top"><a href="javascript:close_overlay(\'proposer-lieu\')" id="lieuClose">[x] Fermer</a></div>';
		content += '<h2>Proposer un autre lieu</h2>';
		content += '<h3>Merci pour votre contribution !</h3>';
		content += '<p>Votre proposition a bien &eacute;́t&eacute;́ enregistr&eacute;e. Nous nous engageons &agrave;̀ modifier votre inscription dans une autre ville si la formation est ouverte pr&egrave;s de chez vous.<br/><br/>';
	content += 'En attendant vous pouvez d&egrave;s &agrave;̀ pr&eacute;́sent r&eacute;server cette formation dans les villes disponibles.<br/><br/></p>';
	content += '<form action="' + link + '/reservation/inscription-12/" method="post">';
	content += '<input type="hidden" value="' + id + '" name="id_formation" />';
	content += '<div id="inscription2" class="center"><input  type="submit" value="Je r&eacute;serve ma place" class="inscription_submit" /></div>';
	content += '</form>';
	content += '</div>';
	content += '<div class="bg_popup_bottom">&nbsp;</div>';
	jQuery('#proposer-lieu').html(content);
}

function add_lieu(path, link, id)
{
	if (!check_mail(jQuery('#lieu_email').val()))
		return false;
	var	msg = jQuery('#lieu').serialize();
	jQuery.post(path, msg, function success(data) { if (data != 'OK') alert(data); else change_div_lightbox(link, id) });
	return false;
}

function dl_file(path, link, id)
{
	if (!check_mail(jQuery('#tele_email').val()))
		return false;
	var	msg = jQuery('#dl_file').serialize();
	jQuery.post(path, msg, function success(data) { if (data == 'Vous devez renseigner votre secteur' || data == 'Vous devez renseigner votre fonction') alert(data); else jQuery('#' + id).html(data); });
	return false;
}

function precharger_image(url)
{
        var img = new Image();
        img.src=url;
        return img;
}
