$.fn.customselect = function(fn) {
  return this.each(function() {
    var $$ = $(this)
    var select = $('<div class="select"></div>')
    var items  = $('<ul class="select-items" style="display:none"></ul>')

    $$.find('option').each(function() {
      var option = $('<li>' + $(this).html() + '</li>')
      option.attr('v', this.value).click(function() {
        if (typeof fn == 'function') fn($(this).attr('v'))
      }).hover(function() {
        $(this).addClass('hover')
      }, function() {
        $(this).removeClass('hover')
      })
      
      if (this.value == '') option.hide()
      items.append(option)
    })

    select.append('<span class="selected">' + $$.find('option:selected').html() + '</span>')
    select.append(items).click(function(e) {
      items.slideToggle('fast')
    }).dblclick(function(e) {
      items.toggle()
    })
    
    $$.after(select).hide()
  })
}

// $.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() {  
//  obj = $(this);  
// obj.after("<div id=\"selectoptions\"> </div>");
// obj.find('option').each(function(i){ 
//   $("#selectoptions").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems\"><img src=\"" + this.title + "\" /><span>" + $(this).html() + "</span></div>");
// });
// obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"customselect\"/><div id=\"iconselect\">" + this.title + "</div><div id=\"iconselectholder\"> </div>")
// .remove();
// $("#iconselect").click(function(){
// $("#iconselectholder").toggle("slow");});
//  $("#iconselectholder").append( $("#selectoptions")[0] );
// $(".selectitems").mouseover(function(){
//  $(this).addClass("hoverclass");
// });
//  $(".selectitems").mouseout(function(){
//  $(this).removeClass("hoverclass");
//  });
//  $(".selectitems").click(function(){
//  $(".selectedclass").removeClass("selectedclass");
//  $(this).addClass("selectedclass");
//  var thisselection = $(this).html();
// $(".customselect").val(this.id);
//  $("#iconselect").html(thisselection);
//  $("#iconselectholder").toggle("slow")
//  });
//     });  
// }

