(function($){
$.fn.smoothLinks = function(options){

	var defaults = {
//options
		time_fadeIn : 200,
		time_fadeOut : 100,
		div_position : "after"
	};
	
	var options = $.extend(defaults, options);
	
	if($("#scriptSM").length <= 0){						//si le div pour les script existe pas le créer
		$("body").prepend('<div id="scriptSM"></div>');
	}
	
	scriptHover = '$(document).ready(function(){';		//commencer les scripts
	
	this.each(function(){
	
		obj = $(this);								//l'objet en question
		
		obj.addClass("smLink");
	
		linkBG = obj.css("backgroundImage");		//image de background
		linkHeight = obj.height();					//hauteur
		linkWidth = obj.width();					//largeur
		
		if(obj.attr('class') == null){				//definir le nom de ID ou de class de chaque élément
			attrProps = "#";
			objProps = obj.attr('id');
		}else{
			attrProps = ".";
			objProps = obj.attr('class');
		}
													//créer les scripts pour chaque éléments
		scriptHover += 		'$("'+attrProps+objProps+'.smLink").hover(function(){';	
		scriptHover += 			'$(this).css("background-position","0 0");';
		scriptHover += 			'$(this).children(".smoothBGlink").stop().animate({opacity:1},'+options.time_fadeIn+');';
		scriptHover += 		'},function() {';
		scriptHover += 			'$(this).children(".smoothBGlink").stop().animate({opacity:0},'+options.time_fadeOut+');';
		scriptHover += 		'});';
		
		bgDivCSS = "display:block; position:relative; opacity:0; filter: alpha(opacity = 0);"		//css du div créé pour l'image de bg
		bgDivCSS += "height:"+linkHeight+"px;";
		bgDivCSS += "width:"+linkWidth+"px;";
		bgDivCSS += "background-image:"+linkBG+";";
		bgDivCSS += "background-position:0 -"+linkHeight+"px";
		
		if(options.div_position == "after"){
			obj.append("<div class='smoothBGlink' style='"+bgDivCSS+"'></div>");	//crée le div pour l'image
		}else{
			obj.prepend("<div class='smoothBGlink' style='"+bgDivCSS+"'></div>");	//crée le div pour l'image
		}
	
	});
	
	scriptHover += 	'});';
	
	var scriptNEW = document.createElement('script');
	scriptNEW.type = 'text/javascript';
	scriptNEW.text = scriptHover;
	var scriptPos = document.getElementById('scriptSM');
	scriptPos.appendChild(scriptNEW);
	
	
};
})(jQuery); 
