	selectbox = {
		
	init:function(classe) {
		var combos = jQuery.makeArray($("." + classe));
		var newSel = '';
		var listOpen;

		var showList = function(obj) {
			if( (obj.offset().left - $('div').children().eq(0).offset().left) + obj.children().eq(1).outerWidth() > 990 )
				obj.children().eq(1).css('margin-left', '-' + (obj.children().eq(1).outerWidth() - obj.outerWidth()) + 'px');
			obj.css('z-index', '9989');
			obj.children().eq(1).css('z-index', '9999');
			obj.children().eq(1).slideDown("fast",
				function(){
					listOpen = $(this);
					$(this).css({'overflow-x' : 'hidden', 'overflow-y' : 'scroll'});
					$(document).bind('click', onBlurList);
				}
			);
		}
		var hideList = function(obj) {
			listOpen = null;
			obj.children().eq(1).css({'overflow-x' : 'hidden', 'overflow-y' : 'hidden', 'z-index' : '8888'});
			obj.children().eq(1).slideUp("fast");
			$(document).unbind('click', onBlurList);
		}
		var onBlurList = function(e) {
			if(listOpen != null) {
				hideList(listOpen.parent());
			}
		}
		
		for(i=0; i<combos.length; i++)
		{
			var change = $('#' + combos[i].id).attr('onchange');
			newSel = '<div class="' + classe + '" id="' + combos[i].id + '"><div class="' + classe + '_selected">' + combos[i].options[0].text + '</div><div class="' + classe + '_list">';
			for(k=0; k<combos[i].length; k++)
				newSel += '<div class="' + classe + '_item" val="' + combos[i].options[k].value + '"' + (combos[i].options[k].style.fontStyle != '' ? (' style="font-style:' + combos[i].options[k].style.fontStyle + ';"') : '') + '>' + combos[i].options[k].text + '</div>';
			newSel += '</div><input type="hidden" name="' + combos[i].name + '" value="' + combos[i].value + '"></div>';
			
			$("#" + combos[i].id).replaceWith(newSel);
			$("#" + combos[i].id).children().eq(1).hide();
			var maxWidth = $("#" + combos[i].id).children().eq(1).innerWidth() + 20;			
			$("#" + combos[i].id).children().eq(1).css({'width' : maxWidth + 'px'});
			
			$("#" + combos[i].id).children().eq(2).bind("change", change );

			$("#" + combos[i].id).bind("click", function(){ showList($(this)) } );
	
			$("#" + combos[i].id + " :nth-child(2) > *").bind("click",
				function(e){
					e.stopPropagation();
					$(this).parent().parent().children().eq(0).html($(this).html());
					$(this).parent().parent().children().eq(2).val($(this).attr("val"));
					if($(this).attr("val") != '')
						$(this).parent().parent().children().eq(2).change();
					hideList($(this).parent().parent().eq(0));
				}
			);
	
			$("#" + combos[i].id + " :nth-child(2) > *").hover(
				function(){
					$(this).addClass('' + classe + '_item__hover');
				},
				function(){
					$(this).removeClass('' + classe + '_item__hover');
				}
			);
		}
	}
}

jQuery.fn.setVal = function(val){
	var child = 9999;
	for(i=0; i<this.children().eq(1).children().size(); i++)
		if(this.children().eq(1).children().eq(i).attr('val') == val)
			child = i;
	if(child != 9999)
	{
		this.children().eq(0).html(this.children().eq(1).children().eq(child).html());
		this.children().eq(4).val(this.children().eq(3).children().eq(child).attr('val'));
	}
};
