jQuery.fn.styledSelect=function(settings){settings=jQuery.extend({selectClass:'styledSelect',openSelectClass:'open',optionClass:'option',selectedOptionClass:'selected',closedOptionClass:'closed',firstOptionClass:'first',lastOptionClass:'last',zIndexApply:false,zIndexStart:250,deactiveOnBackgroundClick:true},settings);var currentZIndex=settings.zIndexStart;this.each(function(){var s=jQuery(this);var cs=jQuery('<div></div>').attr('class',settings.selectClass);if(settings.zIndexApply){cs.css('z-index',currentZIndex-2);};var csl=jQuery('<ul></li>');if(settings.zIndexApply){csl.css('z-index',currentZIndex-1);};cs.append(csl);s.hide(0).after(cs);cs=s.next();jQuery('option',s).each(function(){if(jQuery(this).attr('value')==undefined){jQuery(this).attr('value',jQuery(this).text());}});var closedSelect=function(){jQuery('ul',cs).html('');addOption(s.val(),jQuery(':selected',s).text(),clickSelect);cs.removeClass(settings.openSelectClass);jQuery('ul li',cs).removeClass(settings.selectedOptionClass).removeClass(settings.optionClass).addClass(settings.closedOptionClass);if(settings.deactiveOnBackgroundClick){$(document).unbind('mousedown',closedSelect);cs.unbind('mousedown');}};var clickSelect=function(){jQuery('ul',cs).empty();jQuery('option',s).each(function(i){addOption(jQuery(this).val(),jQuery(this).text(),clickOption);});cs.addClass(settings.openSelectClass);jQuery('ul li:first-child',cs).addClass(settings.firstOptionClass);jQuery('ul li:last-child',cs).addClass(settings.lastOptionClass);if(settings.deactiveOnBackgroundClick){$(document).bind('mousedown',closedSelect);cs.bind('mousedown',function(){return false;});}};var clickOption=function(){var val=jQuery(this).attr('rel');s.val(val);if(s.val()!=""){window.location=s.val();}else{closedSelect();}};var addOption=function(optVal,optName,callBack){var cso=jQuery('<li></li>').attr('rel',optVal).text(optName).click(callBack).addClass(settings.optionClass);if(settings.zIndexApply){cso.css('z-index',currentZIndex);};if(s.val()==optVal){cso.addClass(settings.selectedOptionClass);};jQuery('ul',cs).append(cso);};closedSelect();s.change(closedSelect);currentZIndex-=3;});return this;};
