/*!
 * Copyright (C) 2004-2009 Giant Interective Group, Inc. All rights reserved.
 * 版权所有 2009-2011 e7工作室
 *
 * version #version, #date by Cailijuan
 * Depend on jQuery 1.3.x
 */

/**
 * @class 树形菜单方法处理类。
 */
if(typeof Easy == 'undefined'){
	var Easy = function() {
	};
}

( function($) {

	Easy.initTree = function(treeId, tfid, tid) {
		var tree = $('#'+ treeId +'').find('.tree-menu');
		var id = null, obj = null;
		$.each(tree, function(){
			if(this.id.indexOf('type_') >= 0){
				id = this.id.substring(5);
				obj = $(document.createElement('div'));
				obj.append($('.chdli_'+ id +'')).addClass('li-child');
				if(tfid != id){
					obj.hide();
				}
				
				$(this).after(obj);
			}
			$(this).bind('click', function(){
				Easy.clickTree(treeId, this.id);
			});
		});
	};
	
	Easy.clickTree = function(treeId, id){
		var tree = $('#'+ treeId +'').find('.tree-menu'), obj = null;
		$.each(tree, function(){
			if(this.id == id){
				obj = $(this).find('p');
				if(obj.hasClass('icon-close')){
					obj.removeClass('icon-close').addClass('icon-open');
					if(!$('#'+ id +'').hasClass('child')){
						$(this).next('div').show();
					}
				}else{
					obj.removeClass('icon-open').addClass('icon-close');
					if(!$('#'+ id +'').hasClass('child')){
						$(this).next('div').hide();
					}
				}
			}else{
				if(!$('#'+ id +'').hasClass('child') || $('#'+ id +'').parent().prev('li')[0].id != this.id){
					$(this).removeClass('cur-li').addClass('close-li');
					$(this).find('p').addClass('icon-close').removeClass('icon-open');
					if(!$('#'+ id +'').hasClass('child')){
						$(this).next('div').hide();
					}
				}
			}
		});
	};

})(jQuery);
