$.fn.SelectCustomizer = function(){
   var state_1 = "";
   var state_2 = "";
   var state_3 = "";
   // Select Customizer jQuery plug-in
   // based on customselect by Ace Web Design http://www.adelaidewebdesigns.com/2008/08/01/adelaide-web-designs-releases-customselect-with-icons/
   // modified by David Vian http://www.ildavid.com/dblog
   return this.each(function(){
     var obj = $(this);
     var name = obj.attr('id');
     var id_slc_options = name+'_options';
     var id_icn_select = name+'_iconselect';
     var id_holder = name+'_holder';
     var custom_select = name+'_customselect';


      obj.after("<div id=\""+id_slc_options+"\"> </div>");
      obj.find('option').each(function(i){
         $("#"+id_slc_options).append("<div title=\"" + $(this).attr("value") + "\" class=\"selectitems\"><span>" + $(this).html() + "</span></div>");
      });
      obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" id=\""+custom_select+"\"/><div id=\""+id_icn_select+"\">" + this.title + "</div><div id=\""+id_holder+"\"> </div>").remove();

      $("#"+id_icn_select).click(function(){
         if (id_holder=="adv_holder") {
            state_1 = "show";
            $("#"+id_holder).slideToggle(200);

            if (state_2=="show") {
               state_2 = "";
               $("#adv_b_holder").slideToggle(200);
            }

            if (state_3=="show") {
               state_3 = "";
               $("#adv_c_holder").slideToggle(200);
            }
         }

         if (id_holder=="adv_b_holder") {
            state_2 = "show";
            $("#"+id_holder).slideToggle(200);

            if (state_1=="show") {
               state_1 = "";
               $("#adv_holder").slideToggle(200);
            }

            if (state_3=="show") {
               state_3 = "";
               $("#adv_c_holder").slideToggle(200);
            }
         }

         if (id_holder=="adv_c_holder") {
            state_3 = "show";
            $("#"+id_holder).slideToggle(200);

            if (state_1=="show") {
               state_1 = "";
               $("#adv_holder").slideToggle(200);
            }

            if (state_2=="show") {
               state_2 = "";
               $("#adv_b_holder").slideToggle(200);
            }
         }
      });

      $("#"+id_holder).append($("#"+id_slc_options)[0]);
      $("#"+id_holder+ " .selectitems").mouseover(function(){
         $(this).addClass("hoverclass");
      });
      $("#"+id_holder+" .selectitems").mouseout(function(){
         $(this).removeClass("hoverclass");
      });
      $("#"+id_holder+" .selectitems").click(function(){
         $("#"+id_holder+" .selectedclass").removeClass("selectedclass");
         $(this).addClass("selectedclass");
         var thisselection = $(this).html();
         $("#"+custom_select).val(this.title);
         $("#"+id_icn_select).html(thisselection);
         $("#"+id_holder).slideToggle(250);

         if (document.getElementById('adv_customselect').value!='')
            window.location = document.getElementById('adv_customselect').value;

         if (document.getElementById('adv_b_customselect').value!='')
            window.location = document.getElementById('adv_b_customselect').value;

         if (document.getElementById('adv_c_customselect').value!='')
            window.location = document.getElementById('adv_c_customselect').value;

      });
   });
}