var selects = 900;
$.fn.customSelect = function() {
    // define defaults and override with options, if available
    // by extending the default settings, we don't modify the argument
    return this.each(function() {
        originalSelect = $(this);
        var parent = $(this).parent();
        var width = parent.width();
        var height = 18;
        if ($.support.leadingWhitespace) { height += 1; }

        var grand_parent = $(this).parent().parent();
        parent.css("z-index", selects);
        grand_parent.css("z-index", selects);
        originalSelect.after("<div class=\"selectoptions\"> </div>");
        var options = 0;

        originalSelect.find('option').each(function(i) {
            options++;
            parent = $(this).parent().parent();
            parent.find(".selectoptions").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems\" style=\"z-index: " + selects + ";\">" + $(this).text() + "</div>");
        });
        var style = "";
        if (options > 5) { style = "height: 90px; overflow: auto;"; }

        originalSelect.addClass("customselect");
        var html = Utilities.String.format(
			"<div class='iconselect' style='width:{0}px; height:{1}px; z-index:{2};'>" +
				"<span class='label'>{3}</span>" +
				"<div class='comboboxfix'></div>" +
			"</div>" +
			"<div class='iconselectholder' style='position:absolute;width:{4}px; z-index:{5};{6}'></div>" +
			"<div class='clear'></div>",
			(width - 2),
			height,
			selects,
			originalSelect.find('option:selected').text(),
			width,
			selects,
			style);

        originalSelect.before(html);
       
        originalSelect.hide();

        selects--;

        parent.find(".iconselectholder").append(parent.find(".selectoptions")[0]);
        

        /* end of initialisation code */

        var thisselection = "";

        parent.find(".iconselect").click(function() {
            $(document).keypress(function(e) {
                if (!e) var e = window.event;
                var stop = false;

                if (e.which == 13) {
                    parent.find(".iconselect span.label").text(thisselection).attr("title", thisselection);
                    parent.find(".iconselectholder").toggle();

                    $(document).unbind('keypress');
                    return;
                }

                parent.find('.selectitems').each(function(i) {
                    options++;
                    if (!stop) {

                        if (String.fromCharCode(e.which).toLowerCase() == $(this).text()[0].toLowerCase()) {
                            stop = true;
                            parent = $(this).parent().parent().parent();
                            parent.find(".selectedclass").removeClass("selectedclass");
                            $(this).addClass("selectedclass");
                            thisselection = $(this).text();
                            var originalSelectControl = parent.find("select.customselect");
                            originalSelectControl.val(this.id);
                            originalSelectControl.trigger("change");
                            parent.find(".iconselect span.label").text(thisselection).attr("title", thisselection);
                            $(this).parent().parent().scrollTo(this);
                        }
                    }
                });

            });
            parent = $(this).parent();
            parent.find(".iconselectholder").toggle();
        });

        parent.find(".selectitems").mouseover(function() {
            $(this).addClass("hoverclass");
        });

        parent.find(".selectitems").mouseout(function() {
            $(this).removeClass("hoverclass");
        });

        parent.find(".selectitems").click(function() {
            parent = $(this).parent().parent().parent();
            parent.find(".selectedclass").removeClass("selectedclass");
            $(this).addClass("selectedclass");
            thisselection = $(this).text();

            var originalSelectControl = parent.find("select.customselect");
            if (this.id != originalSelectControl.val()) {
                originalSelectControl.val(this.id);
                originalSelectControl.trigger("change");
            }
            $(document).unbind('keypress');
            parent.find(".iconselect span.label").text(thisselection).attr("title", thisselection);
            parent.find(".iconselectholder").toggle();
        });
    });
    // do the rest of the plugin, using url and settings
}