$(document).ready(function(){
	$.fn.extend({
 
 		customStyle : function(options) {
		  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
		  return this.each(function() {
		  
				var currentSelected = $(this).find(':selected');
				if ($(this).next().hasClass('customStyleSelectBox')) $(this).next().remove();
				$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner"><span style="display:block;overflow:hidden;padding-right:5px;">'+currentSelected.text()+'</span></span></span>').css({position:'absolute',opacity:0,zIndex:1,fontSize:$(this).next().css('font-size')});
				var selectBoxSpan = $(this).next();
				if ($.browser.msie) {
					var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right')) - 21;
				} else if ($.browser.webkit) {
					var selectBoxWidth = parseInt($(this).outerWidth()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right')) - 21;
				} else {
					var selectBoxWidth = parseInt($(this).width('auto').width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right')) - 21;
					$('span.customStyleSelectBoxInner').addClass('s_width');
				}
				var selectBoxSpanInner = selectBoxSpan.find(':first-child');
				selectBoxSpan.css({display:'inline-block'});
				selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
				var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
				$(this).height(selectBoxHeight).bind('change.customStyle',function(){
					var $innerInner = selectBoxSpanInner.children('SPAN');
					var selOption = this.options[this.selectedIndex>=0?this.selectedIndex:0];
					$innerInner.css({width:selectBoxWidth}).text(selOption?selOption.text:'');
					selectBoxSpanInner.parent().addClass('changed');
					//selectBoxSpanInner.text(this.options[this.selectedIndex].text).parent().addClass('changed');
				}).trigger('change.customStyle').bind('keyup',function(){$(this).trigger('change.customStyle');});

				$(this).data('customStyleElement',selectBoxSpan);
				
		  });
		  }
		}
	 });
	
	
	$('select:visible').customStyle();
});
