/**
*class treegrid plugin
*
*/
var tg_plugin;
(function($){
	/**
	*treegrid plugin class
	*/
	var tgp = tg_plugin = function(){
		this.construct.apply(this, arguments);
	};	//end function
	tgp.prototype.construct = function(){
		this.registerEvent('click');
		this.registerEvent('over');
		this.registerEvent('out');
	};	//end function
	/**
	*拥有者
	* @access : public    
	*/
	tgp.prototype.__ower__ = null;
	tgp.prototype.owner = function(value) {		
		if(arguments.length>0){
			if(value instanceof treegrid){
				this.__owner__ = value;
			}
			else{
				throw new Error('The object is not a instance of treegrid.');
			}
		}
		return this.__owner__;
	};	//end function
	/**
	*启动
	* @access : public
	*/
	tgp.prototype.start = function() {
		return false;
	};	//end function
/**
*事件
*/
	tgp.prototype.__event_registers__ = [];
	tgp.prototype.registerEvent = function(/*string*/type){
		if(!this.is_event( type )){
			this.__event_registers__.push( type );
		}
	};
	tgp.prototype.is_event = function(/*string*/type){
		if(this.__event_registers__.indexOf){
			return ( this.__event_registers__.indexOf(type) > -1 );

		}
		else{
			for(var i=0, length=this.__event_registers__.length; i<length; ++i){
				if(type==this.__event_registers__[i])
					return true;
			}
		}
		return false;
	};

	tgp.prototype.__event_listeners__ = {};
	tgp.prototype.addListener = function(/*string*/eventType, /*function*/handler){
		if( this.is_event( eventType ) ){
			if(!this.__event_listeners__[ eventType ])
				this.__event_listeners__[ eventType ] = [];
			this.__event_listeners__[ eventType ].push( handler );
		}
		else{
			throw new Error('The event has not been registered.');
		}
	};
	/**
	*触发事件
	* @access : public
	* @return : boolean
	*/
	tgp.prototype.dispatchEvent = function(/*string*/eventType, /*array*/parameters){
		if(this.__event_listeners__[ eventType ] && this.__event_listeners__[ eventType ].length > 0){
			for(var i=0, length=this.__event_listeners__[ eventType ].length; i<length; ++i){
				this.__event_listeners__[ eventType ][i].apply( this, parameters );
			}
			return true;
		}
		else
			return false;	
	};	//end function
	/**
	*点击动作
	* @access : public
	* @return : void
	*/
	tgp.prototype.click = function(/*string*/dom_id){
		this.dispatchEvent( 'click', [ dom_id ] );
		ejs.cancelBubble();
	};	//end function
	/**
	*点击动作
	* @access : public
	* @return : void
	*/
	tgp.prototype.over = function(/*string*/dom_id){
		this.dispatchEvent( 'over', [ dom_id ] );
		ejs.cancelBubble();
	};	//end function
	/**
	*点击动作
	* @access : public
	* @return : void
	*/
	tgp.prototype.out = function(/*string*/dom_id){
		this.dispatchEvent( 'out', [ dom_id ] );
		ejs.cancelBubble();
	};	//end function

})(jQuery); 
