	$('.widget-category').click(function(){
		dialog_clist = 'CategoriesList';
		$('#' + dialog_clist + ' #remove-cat').hide();
		$('#' + dialog_clist + ' span.cats a').removeClass('selected');
		$('#' + dialog_clist + ' span.subcats a').removeClass('selected');
		$('#' + dialog_clist + ' span.subcats span').hide();
		cont = $(this).attr('id');
		input_name = $('#' + cont + ' span').attr('class');
		full_category = $('#' + cont + ' input.cats_id').val();

		if (typeof(full_category) != 'undefined' && full_category != '')
		{
			category = full_category.split('.');
			cat = category[0];
			subcat = category[1];

			$('#' + dialog_clist + ' span.cats a').removeClass('selected');
			$('#' + dialog_clist + ' span.subcats a').removeClass('selected');
			$('#' + dialog_clist + ' span.subcats span').hide();
			$('#' + dialog_clist + ' a#' + cat + '\\.').addClass('selected');
			$('#' + dialog_clist + ' span.subcats a#' + cat + '\\.' + subcat + '\\.').addClass('selected');

			$('#' + dialog_clist + ' span.subcats span.'+cat).show();
			$('#' + dialog_clist + ' #remove-cat').show();
		}

		$('#' + dialog_clist).dialog({
			width: 430,
			bgiframe: true,
			modal: true,
		});
		$('#' + dialog_clist).show();

		if (typeof(no_category_name) == 'undefined')
		{		
			no_category_name = 'Choose category';
		}
		addCategoryWidget(dialog_clist, cont, input_name, no_category_name);
	});

	function addCategoryWidget(dialog_clist, widget_holder, input_name, txt)
	{
		$('#' + dialog_clist + ' #remove-cat').unbind('click');
		$('#' + dialog_clist + ' span.cats a').unbind('click');
		$('#' + dialog_clist + ' span.subcats a').unbind('click');

		$('#' + dialog_clist + ' span.cats a').bind({
			click: function() {
				$('#' + dialog_clist + ' span.cats a').removeClass('selected');
				$(this).addClass('selected');
				cat_id = $(this).attr('id');
				$('#' + dialog_clist + ' span.subcats span').hide();
				$('#' + dialog_clist + ' span.subcats span.'+cat_id).show();
			}
		});
		$('#' + dialog_clist + ' span.subcats a').bind({
			click: function() {
				$('#' + dialog_clist).dialog('close');
				subcat_id=$(this).attr('id');
				subcat_name=$(this).html();
				$('#' + dialog_clist + ' span.subcats a').removeClass('selected');
				$(this).addClass('selected');
				$('#' + widget_holder + ' span').html('<input type="hidden" class="cats_id" name="'+input_name+'" value="'+subcat_id+'" />'+subcat_name+'&nbsp;');
			}
		});
		$('#remove-cat').bind({
			click: function() {
				$('#'+widget_holder+' span').html(txt);
				$('#' + dialog_clist + ' span.cats a').removeClass('selected');
				$('#' + dialog_clist + ' span.subcats a').removeClass('selected');
				$('#' + dialog_clist + ' span.subcats span').hide();
				$('#' + dialog_clist).dialog('close');
			}
		});
	}

