(function($) {
$.fn.slidingBg = function(ext) {

    ext = $.extend({ fx: "linear", speed: 500, click: function(){} }, ext || {});
	var parent=$('#menuPrincipal').offsetParent;
	var menuParent =$('#menuPrincipal').position();
	//console.log(menuParent.top);
	if ($('#menuPrincipal').find('#'+ext.selectedId).hasClass('liens-general'))
		$('#menuPrincipal').find('#'+ext.selectedId).addClass('selectedBackground').removeClass('liens-general');
	if ($('#menuPrincipal').find('#'+ext.selectedId).hasClass('liens-general-long'))
		$('#menuPrincipal').find('#'+ext.selectedId).addClass('selectedBackground-long').removeClass('liens-general-long');
	var thisHover = '';
	$('.liens-general').hover(function(){
			var hoverEl = $(this).position();
			thisHover = $(this);
			opacityHover=1;
			if ($('#hoverBg').css('opacity')!=0)
			thisHover.find('a').css({'color':'#333'});
			$('#menuPrincipal').find('#'+ext.selectedId).animate({'opacity':0.4});
			id = $(this).attr('id');
			var coeff = 0;
			if ($('#hoverBg').css('opacity')==0) {			
				$('#hoverBg').css({'top':(hoverEl.top+179)}).stop().animate({'opacity':1},function(){
							thisHover.find('a').css({'color':'#fff'});
					});
			}
			else {
				$('#hoverBg').css({'opacity':'1'});
				$('#hoverBg').stop().animate({'top':(hoverEl.top+179)},ext.speed,ext.fx,function(){
							thisHover.find('a').css({'color':'#fff'});	
				});
			}
		});
};
})(jQuery);
