(function($){  
$.fn.select = function(options) {  
	
	var defaults = {
		textLabel: 'text du select',
		addEmpty: false,
		emptyLabel: '--- Sélectionner ---',
		emptyUrl: '/'
	}
	var options = $.extend(defaults, options);  
	
	var select = document.createElement('select');
	var label = document.createElement('label');
	$(label).html(options.textLabel);
	
	return this.each(function() {  

		var obj = $(this);
		
		if (options.addEmpty){
			var option = document.createElement('option');
			$(option).text(options.emptyLabel);
			$(option).attr('value', options.emptyUrl);
			$(select).append(option);
		}
		
		$(obj).find('li').each(function(){
			
			var a = $(this).find('a');
			var texte = $(a).length == 0 ? $(this).text() : $(a).text();  
			var option = document.createElement('option');
			$(option).attr('value', $(a).attr('href'));
			$(option).text(texte);
			if ($(a).hasClass('current') && !jQuery.browser.safari) $(option).attr('selected', 'selected'); 
			$(select).append(option);
		
		})
		
		$(select).change(function(){
			var url = $(this).val();
			window.location.href = '/' + url;			
			return false;
		});
	
		$(obj).replaceWith(select);
		$(select).before(label);
		

	});  


};
})(jQuery); 