$(function(){

	function createLI(item,title){
		var $li=$("<li></li>");
		var $a=$("<a></a>").attr({
			"href":"SubList.jsp?title="+title+"&type="+item.id,
			"target":"_blank"
		}).append(item.name).click(function(event){
			event.stopPropagation();
			return true;
		});
		$li.append($a).unbind();
		return $li;
	}
	
	$('.menuRoot').toggle(function(){
		$('.selectedRoot').click();
		this.style.listStyleImage="url(images/minus.gif)";
		//$(this).css("listStyleImage","url(images/minus.gif)");
		$(this).find('ul').show();
		$(this).addClass('selectedRoot');
		$(this).find('.menuCRoot span').click();
	},function(){
		this.style.listStyleImage="url(images/plus.png)";
		$(this).removeClass('selectedRoot');
		$(this).find('ul').hide();
		$(this).find('.menuCRoot span').click();
	});
	$('.menuCRoot').css('listStyleImage','none').css("listStyle","none");
	$('.menuCRoot span').toggle(function(){
			$(this).parent().find("ul").remove();
			var id=$(this).parent().attr("rootId");
			var $ul=$("<ul></ul>");
			var title=$(this).parent().attr("lang");
			var obj=$(this).parent();
			$.getJSON("listChildren.action",{id:id},function(response){
				$.each(response.newsTypeChildrens,function(i,item){
					$ul.append(createLI(item,title));
				});
				$(obj).append($ul);
			});
		},function(){
			$(this).parent().find("ul").remove();
		});
		
	$('#kepuchangshiLi').click();
	//$('#kepuchangshiLi .menuCRoot span').click();
});
