Ext.namespace("Ext.hansub.tree");

Ext.hansub.tree.RegionTreePanel = function(parent, config) {
	
	this.config = config;
	
	

    // tree root 
	this.root =  new Ext.tree.AsyncTreeNode({
                        	id:'treeRoot_'+this.config.id,
                        	leaf:false,
                            text:this.config.rootTitile,
                            leafview:true
                        })
                        
	this.config.autoHeight = true;
	this.config.autoScroll = true;
	this.config.lines = true;
	this.config.singleExpand = false;
	this.config.useArrows = false;
	this.config.rootVisible = true;
	this.config.root = this.root;
	this.config.enableDD = false;
	this.config.animate = true;
	
	
	
	Ext.hansub.tree.RegionTreePanel.superclass.constructor.call(this, this.config);
	
	this.config.loader.on("beforeload", function(treeLoader, node) {  
 	
    	this.config.loader.baseParams.uid = node.attributes.uid;
		this.config.loader.baseParams.table = node.attributes.table;
        
    }, this);					      
	
    
    this.on('click', this.onClick, this);
    
    this.on('click', this.onDoubleClick, this);
	
	this.on('activate', this.init, this);
	/**
    this.root.on('expand', function loadList(){
		this.onClick(this.root,null);
	},this)
**/
    
    
};

Ext.extend(Ext.hansub.tree.RegionTreePanel, Ext.tree.TreePanel, {
	
	init : function(){
		
		this.root.expand(false);
		this.root.select();
		
		//this.onClick(this.root,null);
				
		//this.onClick(this.root,null);
	},
	
	reload : function(){
		this.root.reload();
	},
	
	addBunyang : function(){
		
		bunyangWindow = new AddBunyangWindow();
		bunyangWindow.init();
		bunyangWindow.show(); 
		
	},
	
	onDoubleClick : function(node, e){
		/**
		this.selectedNode = node;

		if(this.selectedNode.attributes.table == 'apt_region3'){
			
			unitPriceChart = new Ext.hansub.chart.UnitPriceChart(this.selectedNode.attributes,'center');
			unitPriceChart.init(this.selectedNode.attributes);
			Ext.getCmp('centerCenterPanel').add(unitPriceChart);
			Ext.getCmp('centerCenterPanel').activate(unitPriceChart);
			
			
			
				
		}
		
		
		
		if (this.selectedNode.attributes.table == 'apt_apt') {
		
		
		
			if (Ext.getCmp("WrapperPanel" + this.selectedNode.attributes.id)) {
				if (this.selectedNode.attributes.type == "apt") {
					this.selectedNode.text = this.selectedNode.text + " - APT";
					Ext.getCmp('centerCenterPanel').activate("WrapperPanel" + this.selectedNode.attributes.id);
				}
				else {
					this.selectedNode.text = this.selectedNode.text + " - 공시지가";
					Ext.getCmp('centerCenterPanel').activate("LandWrapperPanel" + this.selectedNode.attributes.id);
				}
			}
			else {
			
				if (this.selectedNode.attributes.type == "apt") {
					this.selectedNode.text = this.selectedNode.text + " - APT";
					wrapperPanel = new Ext.hansub.panel.PriceWrapperPanel(this.selectedNode);
				}
				else {
					this.selectedNode.text = this.selectedNode.text + " - 공시지가";
					wrapperPanel = new Ext.hansub.panel.LandPriceWrapperPanel(this.selectedNode);
				}
				
				
				Ext.getCmp('centerCenterPanel').add(wrapperPanel);
				Ext.getCmp('centerCenterPanel').activate(wrapperPanel);
			}
			
		}else if(this.selectedNode.attributes.type == 'bunyang' && this.selectedNode.attributes.leaf) {
			
			if (Ext.getCmp("BunyangWrapperPanelID_" + this.selectedNode.attributes.id)) {
				
				Ext.getCmp('centerCenterPanel').activate("BunyangWrapperPanelID_" + this.selectedNode.attributes.id);
				
			}else{
				bunyangWrapperPanel = new BunyangWrapperPanel(this.selectedNode);
				Ext.getCmp('centerCenterPanel').add(bunyangWrapperPanel);
				Ext.getCmp('centerCenterPanel').activate(bunyangWrapperPanel);
			}
			
			
			
			
		}
		**/
		
		
	},
		
	onClick : function(node, e){
		
		this.selectedNode = node;

		if (!this.selectedNode.attributes.leaf) {

			//if (Ext.getCmp('campingGridExID').isVisible()) {
			if (Ext.getCmp('campingGridExID') && Ext.getCmp('campingGridExID').isVisible()) {

    				Ext.getCmp('campingGridExID').setData({
    					viewtype: 'title',
    					text: '인기순위 -' + this.selectedNode.text,
           		iconCls:'database',
    					table: this.selectedNode.attributes.table,
    					uid: this.selectedNode.attributes.uid
    				})
    			
    


			}else{


  			if (!Ext.getCmp('campingGridID')) {
  				/**
  				var campingGridID = new Ext.hansub.camping.CampingGridPanel({
  					id: 'campingGridID',
  					title: '<b>캠핑장목록</b>',
  	 		    	iconCls:'database',
  				  	closable: false,
  					data: {
  						viewtype: 'title',
  						table: this.selectedNode.attributes.table,
  						uid: this.selectedNode.attributes.uid
  					}
  				});
  				Ext.getCmp('centerCenterPanel').add('campingGridID');
  				**/
  			}
  			else {
  			  
  				Ext.getCmp('campingGridID').setData({
  					viewtype: 'title',
  					text: '캠핑장목록 -' + this.selectedNode.text,
         		iconCls:'database',
  					table: this.selectedNode.attributes.table,
  					uid: this.selectedNode.attributes.uid
  				})
  			}
  			Ext.getCmp('centerCenterPanel').setActiveTab('campingGridID');
  
      }
			//Ext.getCmp('centerCenterPanel').setActiveTab('campingGridID');

			
		}else{
			if (Ext.getCmp("CampingWrapperPanel_"+this.selectedNode.attributes.data.uid)) {
		
				Ext.getCmp('centerCenterPanel').activate("CampingWrapperPanel_"+this.selectedNode.attributes.data.uid);
			}
			else {
			
				this.campingWrapperPanel = new Ext.hansub.camping.CampingWrapperPanel({
					id:"CampingWrapperPanel_"+this.selectedNode.attributes.data.uid,
					x:this.selectedNode.attributes.data.x,
					y:this.selectedNode.attributes.data.y,
					name: this.selectedNode.attributes.data.name,
					record_data : this.selectedNode.attributes.data
				});
				Ext.getCmp('centerCenterPanel').add(this.campingWrapperPanel);
				Ext.getCmp('centerCenterPanel').activate(this.campingWrapperPanel);
			}
		}
		
		
		Ext.getCmp('layout').doLayout();

	}

	

});

