(
function($){
	$.fn.wkCombobox=function(options){
		$.each($(this),function(i,n){
			var defaults={border:'black',background:'white',backgroundHover:'black',text:"black",textHover:"white"};
			this.opts=$.extend(defaults,options);
			if(!$(this).is("select")){return}var newCont=document.createElement("div");
			var textCont=document.createElement("span");
			var newContList=document.createElement("div");
			newContList.className="wkContList";
			var newButton=document.createElement("div");
			this.cont=newCont;
			this.list=newContList;
			newButton.list=newContList;
			newButton.select=this;
			$.fn.wkCombobox.pos(this);
			$(window).wresize(function(){
				$.fn.wkCombobox.pos(newButton.select);
			});
			var marginOffset = ($.browser.msie && $.browser.version == "6.0")? -2 : 0;
			var heightVal = ($.browser.msie && $.browser.version == "6.0")? 11 : 15;
			$(newButton).css({float:"right", position:"relative", top:-1, left:1, marginBottom:marginOffset, borderLeft:"1px "+this.opts.border+" solid", width:21, height:18, background:"url("+this.opts.btn+") no-repeat 0px 0px"});
			$(textCont).css({float:"left", display:"block",width:$(this).width()-25,height:heightVal, overflow:"hidden",padding:2, lineHeight:"1em"});
			$(newButton).hover(function(){
				$(this).css({backgroundPosition:"0px -19px"});
				},
				function(){
					$(this).css({backgroundPosition:"0px 0px"});

				});
			$(newButton).bind("click",function(){
				$(document).unbind("click");
				$.fn.wkCombobox.fillList(newButton.select);
				$(".wkContList").slideUp();
				if(!$(this.list).is(":visible")){
					$(this.list).slideDown("fast",function(){
						$(document).bind("click",function(){
							$(".wkContList").slideUp();
						});
					});
				}});
			$(textCont).appendTo(newCont);
			$(newButton).appendTo(newCont);
			$(newCont).appendTo($(this).parent("p"));
			$(this).parent("p").css({zIndex:1000})
			$(newCont).after(newContList);
			$(this).css({visibility:"hidden"});
			$.fn.wkCombobox.fillList(this);
		});
	};
	$.fn.wkCombobox.fillList=function(select){$(select.list).html("");
	var newList=document.createElement("ul");
	$(newList).css({listStyle:"none"});
	$.each($("option",select),function(i,n){var newOption=document.createElement("li");
	$(newOption).css({margin:1,cursor:"pointer",color:select.opts.text});
	$(newOption).hover(function(){
		$(this).css({background:select.opts.backgroundHover,color:select.opts.textHover});
		},function(){
		$(this).css({background:select.opts.background,color:select.opts.text});
	});
	$(newOption).html("<span>"+$(this).text()+"</span>");
	newOption.option=i;
	newOption.select=select;
	$(newOption).appendTo(newList);
	if($(this).is(":selected")){
		$("span",this.parentNode.cont).html(this.text);
	}
	$(newOption).bind("click",function(){
		$(this.select).trigger('change');
		this.select.selectedIndex=this.option;
		$("span",this.select.cont).html(this.select[this.select.selectedIndex].text);
	});
});
$(newList).appendTo(select.list);
};
$.fn.wkCombobox.pos=function(select){$(select.cont).css({width:$(select).width()+4,height:$(select).height()+2,position:"absolute",left:$(select).position().left,top:$(select).position().top+2,border:"1px "+select.opts.border+" solid",background:select.opts.background,color:select.opts.text,zIndex:997});
$(select.list).css({width:$(select).width()-17,height:"auto",position:"absolute",left:$(select).position().left,top:$(select).position().top+$(select).height()+5,border:"1px "+select.opts.border+" solid",background:select.opts.background,display:"none",zIndex:998});
};
$.fn.wresize=function(f){version='1.1';
wresize={fired:false,width:0};
function resizeOnce(){if($.browser.msie){if(!wresize.fired){wresize.fired=true;
}else{var version=parseInt($.browser.version,10);
wresize.fired=false;
if(version<7){return false;
}else if(version==7){var width=$(window).width();
if(width!=wresize.width){wresize.width=width;
return false;
}}}}return true;
}function handleWResize(e){if(resizeOnce()){return f.apply(this,[e]);
}}this.each(function(){if(this==window){$(this).resize(handleWResize);
}else{$(this).resize(f);
}});
return this;
};
})(jQuery);
