/*

Uniform v1.0
Copyright © 2009 Josh Pyles / Pixelmatrix Design LLC
http://pixelmatrixdesign.com

Requires jQuery 1.3 or newer

Much thanks to Thomas Reynolds and Buck Wilson for their help and advice on this

License:
MIT License - http://www.opensource.org/licenses/mit-license.php

*/

(function($) {
		
	$('html').addClass('js');
	
  $.uniform = {
    options: {
      selectClass:   'selector'
    }
  };

	if($.browser.msie && $.browser.version < 7){
		$.selectOpacity = false;
	}else{
		$.selectOpacity = true;
	}

  $.fn.uniform = function(options) {
    
		options = $.extend($.uniform.options, options);
	
		function doSelect(elem){
			
			var divTag = $('<div />'),
	  			spanTag = $('<span />');
		
			divTag.addClass(options.selectClass);
			
			spanTag.html(elem.children(":selected").text());
			
			elem.css('opacity', 0);
			elem.wrap(divTag);
			elem.before(spanTag);
			
			//redefine variables
			
			divTag = elem.parent("div");
			spanTag = elem.siblings("span");
			
			elem.change(function() {
       	spanTag.text(elem.children(":selected").text());
     	});
     	
		}
		
    return this.each(function() {
			if($.selectOpacity){
					
				if($(this).is("select")){
					doSelect($(this));
				}
				
			}
    });
  };
})(jQuery);
