/*  MENU  */
$(document).ready(function()
{
	/* MegaMenu*/
	function addMega()
	{
	$(this).addClass("hovering");
	$(this).css("background-color", '#002F44');
	}

	function removeMega()
	{
	$(this).removeClass("hovering");
	$(this).css("background-color", 'transparent');
	}
	var megaConfig =
	{
	 interval: 100,
	 sensitivity: 4,
	 over: addMega,
	 timeout: 100,
	 out: removeMega
	};
	$("li.header_menu_main_container_element").hoverIntent(megaConfig);
	
	/* Header_bandeau_right_hover*/
	$('#header_bandeau_right map').hover(function()
	{
	$('#header_bandeau_right img').attr('src', '/img/header_bandeau_right_hover.png');
	}, function()
	{
	$('#header_bandeau_right img').attr('src', '/img/header_bandeau_right.png');
	});

});


/**
 * Init var utiles pour headerBannerMove
 *
 */
var direction	    = 'right';
var windowNumber    = 1;
var menuElement	    = new Array();
var bannerTimeout;
var actualMargin    = 0;
	
$(document).ready(function()
{
	/* Peuple le tableau menuElement */
	menuElement = 
	{
	1 :
	{
		'element'		    : $('#element_header_banner_menu_link_site'),
		'positionWidth'	    : '6px',
		'height'		    : '42px',
		'cursorMargin'	    : '45px'
	},
	2 : {
		'element'		    : $('#element_header_banner_menu_link_design'),
		'positionWidth'	    : '6px',
		'height'		    : '42px',
		'cursorMargin'	    : '205px'		    
	},
	3 : {
		'element'		    : $('#element_header_banner_menu_link_ref'),
		'positionWidth'	    : '6px',
		'height'		    : '46px',
		'cursorMargin'	    : '385px'		    
	},
	4 : {
		'element'		    : $('#element_header_banner_menu_link_hebergement'),
		'positionWidth'	    : '14px',
		'height'		    : '41px',
		'cursorMargin'	    : '610px'		    
	},
	5 : {
		'element'		    : $('#element_header_banner_menu_link_conseil'),
		'positionWidth'	    : '14px',
		'height'		    : '43px',
		'cursorMargin'	    : '840px'		    
	}
	}

	/* implante les hover sur le menu*/
	$('#element_header_banner_menu_content li a').each(function(index)
	{
	if(index>0)
	{
		$(this).hover(function()
		{
		$(this).css(
		{
			'color' : 'black',
			'background-position' : menuElement[index+1]['positionWidth'] + ' -'+ menuElement[index+1]['height']
		});
		}, function()
		{
		$(this).css(
		{
			'color' : '#676767',
			'background-position' : menuElement[index+1]['positionWidth'] + ' 0'
		});
		});
	}
	});
	/* implante le lancement periodique de bannerMover*/
	bannerTimeout = setInterval('bannerMove(false)', 5000);
}); /* document ready end*/


/*
 * Appelée par les onclick
 * stop le setInterval, et le relance
 */
function bannerstopAndMove(position)
{
	clearInterval(bannerTimeout);
	bannerMove(position);
	bannerTimeout = setInterval('bannerMove(false)', 8000);
}


/*
 * Gere l'animation globale du bandeau
 * recois la position é laquelle il doit se rendre, ou false
 * (dans ce cas -> va é la suite, tout seul comme un grand)
 *
 */
function bannerMove(position)
{
	var windowSize	    = $('#element_header_banner_window').width();
	var contentSize	    = $('#element_header_banner_content').width();
	var futurMargin;
	var oldNumber	    = windowNumber;
	if(position == false)
	{
	if(windowNumber == 5 && direction == 'right')
	{
		windowNumber    = 1;
		futurMargin	    = 0;
	}
	else if(windowNumber == 1 && direction == 'left')
	{
		direction	    = 'right';
		windowNumber    = 2;
		futurMargin	    = actualMargin - windowSize;
	}
	else if(direction == 'right')
	{
		windowNumber    = windowNumber + 1;
		futurMargin	    = actualMargin - windowSize;
	}
	else
	{
		windowNumber    = windowNumber - 1;
		futurMargin	    = actualMargin + windowSize;
	}
	}
	else
	{
	if(windowNumber <= position)
	{
		futurMargin	    = actualMargin - (position-windowNumber) * windowSize;
		windowNumber    = position;
	}
	else
	{
		futurMargin	    = actualMargin + (windowNumber-position) * windowSize;
		windowNumber    = position;
	}
	
	}
	actualMargin = futurMargin ;
	$('#element_header_banner_content').animate(
	{marginLeft : futurMargin + 'px'},
	{
		duration : 600,
		complete : function()
		{
		menuElement[windowNumber]['element'].unbind('mouseenter mouseleave');
		menuElement[windowNumber]['element'].css({
			'color' : 'black',
			'background-position' : menuElement[windowNumber]['positionWidth'] + ' -'+ menuElement[windowNumber]['height']
		});
		/* menuElement[windowNumber]['element'].css('background-position', menuElement[windowNumber]['positionWidth'] + ' -'+ menuElement[windowNumber]['height']); */
		menuElement[oldNumber]['element'].css({
			'color' : '#676767',
			'background-position' : menuElement[oldNumber]['positionWidth'] + ' 0'
		});
		menuElement[oldNumber]['element'].hover(function()
		{
			$(this).css(
			{
			'color' : 'black',
			'background-position' : menuElement[oldNumber]['positionWidth'] + ' -'+ menuElement[oldNumber]['height']
			});
		}, function()
		{
			$(this).css(
			{
			'color' : '#676767',
			'background-position' : menuElement[oldNumber]['positionWidth'] + ' 0'
			});
		});
		}
	}
	);
	$('#element_header_banner_cursor').animate(
	{marginLeft : menuElement[windowNumber]['cursorMargin'] },
	{duration : 600}
	);
}
