//////////////////////////////// Menu ////////////////////////////////
$(function(){
	$('#a a')
		.css( {backgroundPosition: "-20px 35px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-20px 35px"})
			}})
		})
});

(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
////////////////////////////////////////////////////////////////

//////////////////////////////// FadeIn du contenu ////////////////////////////////
function fadeContenu()
{
	$("#contenu").fadeOut('fast');
	$("#contenu2").fadeOut('fast');
	$("#contenu").fadeIn('slow');
	$("#contenu2").fadeIn('slow');
}
////////////////////////////////////////////////////////////////

//////////////////////////////// InfoBulle de la map France ////////////////////////////////
AfficherInfoBulle = function(e)
{
  var text = $(this).next('.info-bulle-contenu');
  if (text.attr('class') != 'info-bulle-contenu')
	return false;

  text.fadeIn()
	.css('top', e.pageY)
	.css('left', e.pageX-147);

  return false;
}
CacherInfoBulle = function(e)
{
  var text = $(this).next('.info-bulle-contenu');
  if (text.attr('class') != 'info-bulle-contenu')
	return false;

  text.fadeOut();
}

InstallationInfoBulle = function()
{
  $('.info-bulle-css')
	.each(function(){
	  $(this)
		.after($('<span/>')
		  .attr('class', 'info-bulle-contenu')
		  .html($(this).attr('title')))
		.attr('title', '');
	})
	.hover(AfficherInfoBulle, CacherInfoBulle);
}

$(document).ready(function() {
	InstallationInfoBulle();
	fadeContenu();
});
////////////////////////////////////////////////////////////////

//////////////// Coloration de la map France avec le menu ////////////////
function couleurMap(numMap)
{
	switch(numMap)
	{
		case 1 : $("#bloc1 a").css('background','url("images/france0.png") -94px -395px no-repeat'); break;
		case 2 : $("#bloc2 a").css('background','url("images/france0.png") -94px -591px no-repeat'); break;
		case 3 : $("#bloc3 a").css('background','url("images/france0.png") -109px -791px no-repeat'); break;
		case 4 : $("#bloc4 a").css('background','url("images/france0.png") -127px -990px no-repeat'); break;
		case 5 : $("#bloc5 a").css('background','url("images/france0.png") -116px -1187px no-repeat'); break;
		
		case 6 : $("#bloc1 a").css('background','url("images/france0.png") -94px -185px no-repeat'); break;
		case 7 : $("#bloc2 a").css('background','url("images/france0.png") -94px -171px no-repeat'); break;
		case 8 : $("#bloc3 a").css('background','url("images/france0.png") -109px -161px no-repeat'); break;	
		case 9 : $("#bloc4 a").css('background','url("images/france0.png") -127px -150px no-repeat'); break;
		case 10 : $("#bloc5 a").css('background','url("images/france0.png") -116px -137px no-repeat'); break;
	}
}
////////////////////////////////////////////////////////////////

//////////////// Hover de toutes les parties du bouton d'un menu ////////////////
sfHover = function() {
        var sfEls = document.getElementById("menu2").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 hover(num)
{
	document.getElementById(num+"a").style.backgroundImage = 'url("images/menu1a.gif")';
	document.getElementById(num+"b").style.backgroundImage = 'url("images/menu1b.gif")';
}
////////////////////////////////////////////////////////////////

function unhover(num)
{
	document.getElementById(num+"a").style.backgroundImage = 'url("images/menu0a.gif")';
	document.getElementById(num+"b").style.backgroundImage = 'url("images/menu0b.gif")';
}
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
$(document).ready(function(){

	$("#menu1 a").hover(function() {
		$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
	});


});
////////////////////////////////////////////////////////////////
