/* JV made several changes to this file, could be further improved: don't use id's, since it will only allow one instance on a page */

jQuery.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() {  
		var selectedContent = 'Selecteer taal';
		var selectedValue = null;
		
		obj = $(this);
		obj.after("<div id=\"selectoptions\"> </div>");
		obj.find('option').each(function(i){ 
			var parts = $(this).attr("class").split('_');
			var language = parts[1];
			var icon = imgPath + 'icon_flag_' + language + '.gif';
			var htmlContent = "<img src=\"" + icon + "\" /><span>" + $(this).html() + "</span>";
			$("#selectoptions").append("<div id=\"" + $(this).attr("value") + "\" class=\"selectitems\">" + htmlContent + "</div>");
			if($(this).attr("selected") == true){
				selectedContent = htmlContent;
				selectedValue = $(this).attr("value");
			}
		});
		obj.before("<input type=\"hidden\" value =\"\" name=\"" + this.name + "\" class=\"customselect\"/><div id=\"iconselect\">" + this.title + "</div><div id=\"iconselectholder\"> </div>").remove();

		$("#iconselect").html(selectedContent);
		$(".customselect").val(selectedValue);

		$("#iconselect").click(function(){
			$("#iconselectholder").slideToggle("fast");
		});
		$("#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();

			if($(".customselect").val() != this.id){
				$(".customselect").val(this.id);
				document.location = this.id;
			}
			$("#iconselect").html(thisselection);
			$("#iconselectholder").slideToggle("fast")
		});
	});  
  // do the rest of the plugin, using url and settings
}

