/*
 * jQuery Custom Select Menu Script v1.1
 * http://www.emarketed.com/
 *
 * Copyright (c) 2010 emarketed.
 *
 *
 * 
 *
 * PARAMETERS:
 * 	Coming Soon
 *
 * USAGE/EXAMPLE:
 *  Coming Soon
 *
 *
 * CHANGELOG
 * ------------------------------------------------
 * Version 1.1
 *  - Fixed default selector HTML to use the label of the
 *    select tag rather than it's value
 *
 */
 
(function($) {
		  /*
	var customSelectOverlay = document.createElement('div');
	$(function() {
				$(customSelectOverlay).attr({
								  class: 'customSelect_Overlay',
								  width: $(document.body).width()+'px',
								  height: $(document.body).height()+'px'
								  });
			   $(document.body).prepend($(customSelectOverlay));
			   $(window).resize(function() {
										 $(customSelectOverlay).attr({
																	 width: $(document.body).width()+'px',
																	 height: $(document.body).height()+'px'
																	 });
										 });
			   });*/
	$.fn.customSelect = function() {
		$(this).each(function() {
							  if(this.tagName == 'SELECT') {
								  var divContainer = document.createElement('div');
								  var mainDiv = document.createElement('div');
								  var valueHolder = document.createElement('input');
								  var divChildrenContainer = document.createElement('div');
								  var overlay = document.createElement('div');
								  var divChildren = new Array();
								  
								  var dontSelect = function(element) {
									  if($.browser.mozilla){//Firefox
										$(element).css({
													   'MozUserSelect': 'none',
													   'outline': 'none'
													   });
									  }
									  else if($.browser.msie){//IE
										$(element).bind('selectstart',function(){return false;});
									  }
									  else{//Opera, etc.
										$(element).mousedown(function(){return false;});
										$(element).css('outline','none');
									  }
									  return element;
								  }
								  
								  $(this).children('option').each(function() {
																		   
									   divChildren[divChildren.length] = 
									   $(document.createElement('div')).
									   click(function(){
										  $(valueHolder).attr('value',$(this).children('input:hidden').attr('value'));
										  $(mainDiv).html($(this).children('a').html());
										  $(divChildrenContainer).toggle();
									   }).
									   append($(dontSelect(document.createElement('a'))).mousedown(function() { $(this).blur(); }).html($(this).html()).attr('href','javascript:;')).
									   append($(document.createElement('input')).attr({
																					  type:'hidden',
																					  value: $(this).attr('value')
																					  })).
									   attr('class',$(this).attr('class')).appendTo($(divChildrenContainer));
									   });
								  var parent = this;
								  divChildrenContainer.okToFade = true;
								  dontSelect(mainDiv);
								  dontSelect(divChildrenContainer);
								  $(divContainer).attr({'class': 'customSelect_Container'}).
								  append($(mainDiv).attr('class','customSelect_CurrentDisplay').css('cursor','default')
								  .html($(this).children(':selected').text()) //modified on 4/21/2010
								  .click(function() {
																		$(divChildrenContainer).toggle().focus();
																		
								  })).
								  append($(divChildrenContainer).attr({'class': 'customSelect_DropdownContainer','style': 'display: none'})
																.blur(function() { if(this.okToFade) $(this).fadeOut('fast'); })
																.mouseover(function() { this.okToFade = false;})
																.mouseout(function() { this.okToFade = true;$(this).focus(); })).
								  append($(valueHolder).attr({'type': 'hidden','name': $(this).attr('name')}))
								  $(this).replaceWith($(divContainer));
							  }});
	}

}) (jQuery);
