$.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 + "\" />" + $(this).html() + "</div>");
});

obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"customselect\"/><div id=\"iconselect\"><img src=\"" + this.title + "\" /></div><div id=\"iconselectholder\"> </div>")
.remove();
var x = 0;

	$("#iconselectholder").append( $("#selectoptions")[0] );
	
	$(".selectitems").mouseover(function()
	{
		$(this).addClass("hoverclass");
	});
	
	$(".selectitems").mouseout(function(){
	$(this).removeClass("hoverclass");
	});
	
	var old = this.title;
    
	$(".selectitems").click(function()
	{
      
		$(".selectedclass").removeClass("selectedclass");
		$(this).addClass("selectedclass");
		var thisselection = $(this).html();
		if (old != "/images/flags/" + this.id + ".gif")
          {
            
            $(".customselect").val(this.id);
            
            $("#iconselect").html(thisselection);
    
            $("#iconselectholder").slideUp("fast", function()
            {
              $("body").fadeOut('slow', function(){
              window.location.href='/language/' + $(".customselect").val() + '/';
              });
            });
          }
          else
            {
              $("#iconselectholder").slideUp("fast");
            }

	});
	

	var x = 0;
	$("#iconselect").click(function()
	{
        if (x == 0)
          {
        $("#iconselectholder").slideDown("fast");
		x = 1;
          }
          else
              {
        $("#iconselectholder").slideUp("fast");
		x = 0;
          }


	});
	
    });  
  // do the rest of the plugin, using url and settings
}

