(function($){
 	$.fn.extend({
 
 		customStyle : function(options) {
	  		if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
	  			return this.each(function() {
					var target= $(this);
					
					if(target.is(':hidden'))
						return;
					
	  				var custombox = $('<span class="customSelectBox"><span></span></span>');
					custombox.find('span').html($(target).find('option:selected').html());
					custombox.bind('click',function(event){ 
						var list = $(event.target).closest('.customSelectBox').find('div.list');
						var hidden = list.is(':hidden');
						$('.customSelectBox div.list').hide();
						$('.customSelectBox').css('z-index',1);
						if(hidden){
							list.show();
							custombox.css('z-index',100);
							if(list.find('.selected').length)
								list.scrollTop(list.find('.selected').position().top);
						}
						else	
							list.hide();
					});
					
					var list = custombox.append('<div class="list"><ul></ul></div>');
					
					$(target).find('option').each(function(){
						var option = $('<li value="' + $(this).val() + '">' + $(this).html() + '</li>');
						option.bind('click', function(){
							target.val($(this).attr('value'));
							custombox.find('span').html($(this).html());
							custombox.find('li.selected').removeClass('selected');
							$(this).addClass('selected');
						});
						if($(this).attr('selected'))
							option.addClass('selected');
							
						list.find('ul').append(option);
					});
					
					custombox.insertAfter($(this));
					$(target).hide()
					
					$(window).bind('click', function(event){
						if(!$(event.target).hasClass('customSelectBox') && !$(event.target).parent().hasClass('customSelectBox'))
							$('.customSelectBox').find('div.list').hide();
					});
					
				});
			}
		}
 	});
})(jQuery);
