jQuery.fn.DeseoSelectReset = function() { 

this.children('input').attr('value', '');
this.children('.DeseoSelectContainer').html('<span class="DeseoSelectTextPlease DeseoSelectSpan">-- wybierz --</span>')

}

jQuery.fn.DeseoSelect = function(width, multiLevel) { 
	
	text_please = '-- wybierz --';
	objName = this.attr('id');
	value = this.val();
	if(value)
	{
		selectedIndex = this.attr('selectedIndex');
		valueName =this.children().eq(selectedIndex).html();
	}


	id = '#'+objName;

	marginTop = '';
	if(multiLevel==true)
	marginTop = 'style="margin-top: 3px"';

	html = '<div id="'+objName+'" '+marginTop+'>';
	html += '<input type="hidden" name="'+objName+'" value="'+value+'" />';

	html += '<div class="DeseoSelectContainer">';
	
	if(value)
	html += '<span class="DeseoSelectSpan">'+valueName+'</span>';
	else
	html += '<span class="DeseoSelectTextPlease DeseoSelectSpan">-- wybierz --</span>';
	
	html += '</div>';
	
	
	//if(this.children().size() > 9)

	html += '<div class="DeseoSelectSelect">';

	
	SelectWidth = OptionWidth = width;

	if ($.browser.safari && $.browser.version=='525.19' || $.browser.mozilla || $.browser.opera)
	SelectWidth -=2;
	else if($.browser.safari)
	SelectWidth -=4;


	this.children().each(function(i) {
		
		addClass = $(this).attr('alt');
		if(i%2==0) addClass+=' ac_odd';

		if(this.value=='')
			name = '<span class="DeseoSelectTextPlease DeseoSelectSpan">'+text_please+'</span>';
		else
			name = '<span class="DeseoSelectSpan">'+$(this).html()+'</span>';
			
		html += '<div class="DeseoSelectOption '+addClass+'" style="width: '+OptionWidth+'" alt="'+this.value+'">'+name+'</div>';
		
	});


	

	html += '</div>';

	this.after(html);
	this.remove();

	jQuery(id+' .DeseoSelectContainer').width(SelectWidth);
	//jQuery(id+' .DeseoSelectSelect').width(SelectWidth);
	jQuery(id+' .DeseoSelectOption, '+id+' .DeseoSelectContainer').hover(
		function () {jQuery(this).addClass('select_hover'); jQuery(this).children().addClass('active'); return false; },
		function () {jQuery(this).removeClass('select_hover'); jQuery(this).children().removeClass('active'); return false;});
	
	

	jQuery(id+' .DeseoSelectOption').click(function() {
		value = jQuery(this).attr('alt');
		name = jQuery(this).html();

		jQuery(this).parent().prev().html(name);
		span = jQuery(this).parent().prev().children();
		
		span.css('color', span.attr('oldcolor'));

		jQuery(this).parent().prev().prev().attr('value', value);
		jQuery(this).parent().hide();
	});


	jQuery(id+' .DeseoSelectContainer').click(function() {jQuery('.DeseoSelectContainer').next().fadeOut(); jQuery(this).next().show();return false;});

	jQuery(document).click(function() {jQuery('.DeseoSelectContainer').next().fadeOut();});
}
