$(function() 
{

	// Departements Panels
	
	$("#departements li").mouseover(function()
	{
		// Reset all departement background colors to off
		$("#departements li").css('background-color', "#3F3F3D");
		
		// Clear all billboards;
		// $(".panel-billboard").html('');

		// Set this departement background color to on
		$(this).css('background-color', "#8ac149");
		
		// Slide the panel down
		if ($("#departements-panel:first").is(":hidden")) 
		{$("#departements-panel").slideDown();}
		category = $(this).attr('id');
		$(".departements-holder").hide();
		$("#" + category + "-holder").show();
	});
	
	// Handle each list item on a panel

	$("#departements-panel li h3 a").mouseover(function()
	{
		// Clear any existing .selected menu items on this particular panel
		$(this).parent().parent().parent().children().children().children().removeClass('selected');

		// Set this one as .selected
		$(this).addClass('selected');
		
		// Get our selection's tagline and its contents
		thisTagline = $(this).parent().next();
		taglineContents = thisTagline.html();

		// Get our panel's billboard
		thisBillboard = $(this).parent().parent().parent().next();

		// Populate our panel's billboard
		$(thisBillboard).html(taglineContents);
	});
	
	// Hide panel when leaving it
	$("#departements-outer").mouseleave(function()
	{
		if ($("#departements-panel").is(":visible")) 
		{$("#departements-panel").slideUp();} 
	});
	
	/*
	*   Examples - images
	*/

	$("a[rel=example_group]").fancybox(
	{
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});
	
	/*
	*   Examples - various
	*/
	
	$("#various1").fancybox(
	{
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	
	$("#various2").fancybox(
	{
		ajax : 
		{
		    type	: "POST",
		    example	: 'myexample=test'
		}
	});

	$("#various3").fancybox(
	{
		'width'				: '100%',
		'height'			: '100%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$("#various4").fancybox(
	{
	    'padding'           : 0,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});

	// Cycle

	$('#cycle').cycle(
	{
		fx:     'scrollHorz', 
		speed:  '300', 
		timeout: 4000, 
		next:   '#next2', 
		prev:   '#prev2' 
	});

	$('#slideshow').cycle(
	{
		fx: 'fade',
		speed: '2000', 
		timeout: 4000,
		after: function() 
		{
			$('#caption').html( $(this).children()[0].title);
		}
	});

	// Mailinglist form

	$("#subscribe-mailinglist-button").click(function()
	{
		if ( $("#newsbox").val() == "" || $("#newsbox").val()=="votre adresse e-mail ici")
		{
			alert('Avez-vous rempli tous les champs?'); 
			return;
		}
		var data = 'ACT='+ $("#mailinglist-ACT").val()+'&RET='+ $("#mailinglist-RET").val()+'&list='+ $("#mailinglist-list").val()+'&site_id='+$("#mailinglist-site_id").val()+'&email='+$("#newsbox").val();
		$.ajax(
		{
			type: 'POST',
			url: '/index.php',
			data: data,
			success: function()
			{
				$("#newsletterform").remove();
				$("#newslettercontainer").html("<p>Merci. Un e-mail de confirmation vient de vous &ecirc;tre adress&eacute;.</p>");
			}
		});
	});

	// Contact Us form

	$("#contact_form-button").click(function()
	{
		if (
			$("#contact_name").val() == "" 
			|| 
			$("#contact_enterprise").val() == "" 
			|| 
			$("#contact_role").val() == ""
			|| 
			$("#contact_email").val() == "" 
			|| 
			$("#contact_telephone").val() == "" 
			|| 
			$("#contact_message").val() == ""
			||
			$("#contact_firstname").val() == "" 
		)
		{
			alert('Avezvous rempli tous les champs?'); 
			return;
		}
		var data = 
			'ACT=' + $("#contact_ACT").val() +
			'&URI=' + $("#contact_URI").val() + 
			'&XID=' +  $("#contact_XID").val() + 
			'&status=' + $("#contact_status").val() + 
			'&return=' + $("#contact_return").val() + 
			'&redirect_on_duplicate=' + $("#contact_redirect_on_duplicate").val() + 
			'&RET=' + $("#contact_RET").val() + 
			'&form_name=' + $("#contact_form_name").val() + 
			'&id=' + $("#contact_id").val() + 
			'&params_id=' + $("#contact_params_id").val() + 
			'&site_id=' + $("#contact_site_id").val() + 
			'&contact_name=' + $("#contact_name").val() + 
			'&contact_enterprise=' + $("#contact_enterprise").val() + 
			'&contact_role=' + $("#contact_role").val() + 
			'&contact_email=' + $("#contact_email").val() + 
			'&contact_telephone=' + $("#contact_telephone").val() + 
			'&contact_message=' + $("#contact_message").val() + 
			'&contact_moreinfo=' + $("#contact_moreinfo").val() + 
			'&contact_contactme=' + $("#contact_contactme").val() +
			'&contact_firstname=' + $("#contact_firstname").val(); 
		$.ajax(
		{
			type: 'POST',
			url: '/index.php',
			data: data,
			success: function()
			{
				$(".contact table").remove();
				$(".contact").html("<p>Merci de votre int&eacute;r&ecirc;t pour l'email marketing et B2D1.</p><p>Nos &eacute;quipes vous contactent dans les plus brefs d&eacute;lais.</p>");
			}
		});
	});

});

