$.fn.SelectCustomizer = function(){
    // Select Customizer jQuery plug-in
	// based on customselect by Ace Web Design http://www.adelaidewebdesigns.com/2008/08/01/adelaide-web-designs-releases-customselect-with-icons/
	// modified by David Vian http://www.ildavid.com/dblog
    return this.each(function(){
        var obj = $(this);
		var name = obj.attr('id');
		var id_slc_options = name+'_options';
		var id_icn_select = name+'_iconselect';
		var id_holder = name+'_holder';
		var titre="";
		var custom_select = name+'_customselect';
        obj.after("<div id=\""+id_slc_options+"\"> </div>");
        var valeur_option="";
		obj.find('option').each(function(i){
			var selectionner="";
			
			if($(this).attr("selection")){selectionner=$(this).attr("selection");valeur_option=$(this).attr("value");}
            $("#"+id_slc_options).append("<div title=\"" + $(this).attr("value") + "\" class=\"selectitems "+ selectionner +"\"><span>" + $(this).html() + "</span></div>");
        if ($(this).attr("selection")=="selectedclass"){titre=$(this).html() ;}
		});
        obj.before("<input type=\"hidden\" value =\""+ valeur_option +"\" name=\"" + this.name + "\" id=\""+custom_select+"\"/><div id=\""+id_icn_select+"\">" + this.title + titre +"</div><div id=\""+id_holder+"\"> </div>").remove();
        $("#"+id_icn_select).click(function(){
            $("#"+id_holder).slideToggle(200);
        });
        $("#"+id_holder).append($("#"+id_slc_options)[0]);
        $("#"+id_holder+ " .selectitems").mouseover(function(){
			$(this).focus();
            $(this).addClass("hoverclass");
        });
        $("#"+id_holder+" .selectitems").mouseout(function(){
            $(this).removeClass("hoverclass");
        });
        $("#"+id_holder+" .selectitems").click(function(){
            $("#"+id_holder+" .selectedclass").removeClass("selectedclass");
            $(this).addClass("selectedclass");
            var thisselection = $(this).html();
            $("#"+custom_select).val(this.title);
            $("#"+id_icn_select).html(thisselection);
            $("#"+id_holder).slideToggle(50);
			$("#form").submit();
			//$("#ajax_noel").load("ajax_noel.asp",{genre:$("#adv_customselect").attr("value"),univers :$("#adv2_customselect").attr("value"),price:$("#adv3_customselect").attr("value")}
								//);
        });
    });
}
