(function ($) {
	$.fn.cross = function (options) {
		return this.each(function (i) { 
			var $$ = $(this);
			var target = $$.attr('src').replace(/_off/g, '_on');
			
			$$.wrap('<span style="position: relative;"></span>')
				.parent()
				.prepend('<img>')
				.find(':first-child')
				.attr('src', target);

			// Cross-browser
			if (($.browser.msie&& $.browser.version >7) || $.browser.mozilla) {
				$$.css({
					'position' : 'absolute', 
					'left' : 0,
					'background' : '',
					'top' : this.offsetTop
				});
			}
			if (($.browser.msie&& $.browser.version <8)) {
				$$.css({
					'position' : 'absolute', 
					'left' : 0,
					'background' : '',
					'top' : 0
				});
			}
			else if ($.browser.opera && $.browser.version < 9.5) {                
				$$.css({
					'position' : 'absolute', 
					'left' : 0,
					'background' : '',
					'top' : "0"
				});
			} else { // Safari
				$$.css({
					'position' : 'absolute', 
					'left' : 0,
					'background' : ''
				});
			}

			// L'animation
			$$.hover(function () {
				$$.stop().animate({
					opacity: 0
				}, 500);
			}, function () {
				$$.stop().animate({
					opacity: 1
				}, 2000);
			});
		});
	};
	
})(jQuery);

// Attention ne pas utiliser .ready ici !
$(window).bind('load', function () {
	// $('#main_menu').find('li').not('li.active').find('img').cross();
	$('#main_menu li img').cross();
	var active = $('#main_menu li.active img');
	if (active.size()) {
		active = active.attr('src').replace(/_off/g, '_on');
		$('#main_menu li.active:first img').attr('src', active);
	}
	$('#afficher_recherche').click(
		function() {
			$('#search_block_top').slideToggle();
			$('#search_query').focus();
		}
	);
});
