$( function()
{
	/*!
	* définitions utiles
	*/
	$.fx.speeds['pagination'] = $.browser.msie ? 0 : 150;
	$.fx.speeds['clouds'] = 67200;


	/*
	* Compatibilité navigateur en premier
	*/
	if ( $.browser.msie )
	{
		if ( $.browser.version < 7 )
		{
			$("form button:submit").click( function( evt ) { evt.preventDefault(); $(this).closest("form").submit() ; } );
		}

		if ( $.browser.version < 8)
		{
			$("table.info-list tr:nth-child(even)").addClass("even");
		}
	}

	if ( $.browser.mozilla && parseFloat($.browser.version) < 1.9 )
	{
		$("html").addClass("FF2");
	}


	if ( document.width < 960 )
	{
		$("html").css("overflow-x","auto");
	}




	// animation des nuages
	if ( !$.browser.msie )
	{
		$(document).bind('clouds', function clouds()
		{
			if ( !$(document).data('clouds') )
			{
				$("#header").css({backgroundPosition: '0px'}).animate( { backgroundPosition: -1680 }, 'clouds', 'linear', clouds );
			}
		});
	}



	// Animation des paginations
	$("nav.pagination-top a").hover( function ()
	{
		$(this).stop().animate( { top : 0 }, 'pagination' );
	},function ()
	{
		$(this).stop().animate( { top : -20 }, 'pagination' );
	});



	$("nav.pagination-bottom a").hover( function ()
	{
		$(this).stop().animate( { top : 0 }, 'pagination' );
	}, function ()
	{
		$(this).stop().animate( { top : 20 }, 'pagination' );
	});



	// Overlay des filtres de recherche... Ouverture/fermeture
	$("p.filter a:first, #filter a:first").bind('click', function( evt )
	{
		evt.preventDefault();
		$("#filter").toggleClass('hide');
		if ( !$.browser.msie || $.browser.version > 6 )
		{
			$("p.filter").toggleClass('filter_opened');
		}
		try { _gaq.push(['_trackEvent','Filter',$("#filter").is(':visible') ? 'View' : 'Hide']); } catch(e) {}
	});




	// Pour question esthétique, on ne soumet pas les inputs sans valeur
	$("form.search").submit( function( evt )
	{
		$(this).find('input').each(function()
		{
			if ( !$(this).val() ) $(this).removeAttr('name');
		});
	});




	// Warning pour IE6
	$("#ie_warning").bind('click', function() { $("#ie_warning span.hide").toggle(); });



	// Affichage des régions
	$("#france area").bind('click', function(evt)
	{
		evt.preventDefault();

		$("#france-background").css( 'background-position', $(this).attr('pos') ); // bouge le fond de carte
		$("#rg-info").children().css( 'display', 'none' ); // cache tous les textes
		$("#rg-" + $(this).attr('id')).css( 'display', 'block' ); // et montre le notre
	}).mouseover(function() { $("#france-background").css( 'background-position', $(this).attr('pos') ); })
	.mouseout(function() { $("#france-background").css('background-position',500); });


	// decode.js compilé
	$(".encoded").each(function(){var b=$(this).attr("data-content"),d="",f,e,h,c,g,a=0;for(b=b.replace(/[^A-Za-z0-9\+\/\=]/g,"");a<b.length;){f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(a++));e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(a++));c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(a++));g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(b.charAt(a++)); f=f<<2|e>>4;e=(e&15)<<4|c>>2;h=(c&3)<<6|g;d+=String.fromCharCode(f);if(c!=64)d+=String.fromCharCode(e);if(g!=64)d+=String.fromCharCode(h)}b="";for(c=c1=c2=a=0;a<d.length;){c=d.charCodeAt(a);if(c<128){b+=String.fromCharCode(c);a++}else if(c>191&&c<224){c2=d.charCodeAt(a+1);b+=String.fromCharCode((c&31)<<6|c2&63);a+=2}else{c2=d.charCodeAt(a+1);c3=d.charCodeAt(a+2);b+=String.fromCharCode((c&15)<<12|(c2&63)<<6|c3&63);a+=3}}$(this).replaceWith(b)});


	$(document).trigger('clouds');
});