$(function() {
    // Find list items representing folders and
    // style them accordingly.  Also, turn them
    // into links that can expand/collapse the
    // tree leaf.
	$('#menu_div li > ul').each(function(i) {
		// Find this list's parent list item.
		var parent_li = $(this).parent('li');
 
		// Style the list item as folder.
		parent_li.addClass('folder');
 
		// Temporarily remove the list from the
		// parent list item, wrap the remaining
		// text in an anchor, then reattach it.
		var sub_ul = $(this).remove();
		parent_li.wrapInner('<a/>').find('a').click(function() {
			// Make the anchor toggle the leaf display.
			sub_ul.toggle();
		});
		parent_li.append(sub_ul);
	});

	$('#menu_div li:not(.folder)').each(function(i){
		$(this).wrapInner('<a/>').bind('click', function(){
			var id=$(this).attr('id');			
/*			if ($(this).hasClass('folder1')) {
				$(this).removeClass('folder1');
			} else {
				$('#menu_div li:not(.folder)').each(function(i){
					$(this).removeClass('folder1');
				});
				$(this).addClass('folder1');*/
/*				document.form.action=document.form.action + '?ctag=' + id;
				document.form.submit();					*/
				$('#ctag').val(id);
				$('#tag').val($(this).text());
				$.get('inc_tag.php');
				document.form.action=document.form.action + '?cambia_tag=1';
				document.form.submit();									
//			}
			
		});
	});
		// Hide all lists except the outermost.
	$('#menu_div ul ul').hide();
	$('li[@elegido=1]').each(function(){
		$(this).parents('ul').show();
//		$(this).addClass('folder1');
	});
});
