(function($){
	$.fn.extend({ 
		//plugin name
		funkyselect: function(options) {

			//Settings list and the default values
			var defaults = {
				className: 'funkyselect',
				className: 'funkyselect2'

			};
			
			var options = $.extend(defaults, options);
		
    		return this.each(function() {
				var o =options;
				
				//Assign current element to variable, in this case is UL element
				var obj = $(this);
				//check if its a <select> tag
				if('select'!=obj[0].nodeName.toLowerCase()){
					return false;
				}
				obj.hide();	
				
				var lists = obj.children('option');
				
				//construct html
				var html = '<div class="'+o.className+'"><p>'+lists.eq(0).text()+'</p><ul>';
				$.each(lists, function(i, el){
					html += '<li>'+$(el).text()+'</li>';
				});
				html += '</ul></div>';
				
				//add to dom
				
				var funky = $(html).appendTo(obj.parent());
				funky.children('ul').css('top',$('.'+o.className).height()+'px');
				funky.data('down',false);
				//Attach mouseover and mouseout event to the LI  
				funky.click(function(e){
					if(funky.data('down')==false){
						$(funky).children('ul').slideDown('fast');
						funky.css('z-index',100);
						$('.'+o.className).not(funky).each(function(){
							if($(this).data('down')){
								$(this).trigger('click');	
							}
						});
						funky.data('down',true);
					} else {
						$(funky).children('ul').slideUp('fast');
						funky.css('z-index',99);
						funky.data('down',false);
					}
					e.stopPropagation();
				});
				
			
				$(document).click(function(){
					$('.'+o.className).not(funky).each(function(){
							if($(this).data('down')){
								$(this).trigger('click');	
							}
						});   
				});
									   
				funky.children('ul').children('li').click(function(){
					funky.children('p').html($(this).text());	
					obj.val($(this).data('value'));	
				});
    		});
    	}
	});
})(jQuery);
