/**************************************************\
*                BASE COMPONENT                    *
* Author: Andrew Green                             *
* Modified: 13/10/2008                             *
* Description:                                     *
\**************************************************/
if(!Component)
	var Component={};
Component.base=baseClass({
	constructor : function(json){
		this.properties={};
		this.events={};
		this.children=[];


		if(json){
			if(json.set){
				for(var key in json.set){
					this.set(key,json.set[key]);
				}}
			if(json.on){
				for(var key in json.on){
					this.on(key,json.on[key]);
				}}
			if(json.append){
				for(var i=0;i<json.append.length;i++){
					if(json.append[i])
						this.append(json.append[i]);
				}}
		}
	},
	get : function(property){
		if(this['get'+property])
			return this['get'+property].apply(this,arguments);
		return this.properties[property];
	},
	set : function(property,value){
		if(this['set'+property])
			return this['set'+property].call(this,value);
		return this.properties[property]=value;
	},
	on : function(eventName,eventFunction){//set functions for events
		
		if(this['on'+eventName])
			return this['on'+eventName].call(this,eventFunction);
		
		if(!this.events[eventName])//if no array for even then create
			this.events[eventName]=[];
		
		this.events[eventName].push(eventFunction);
		

		return eventFunction;
	},
	fire : function(eventName){//fire all functions for an event
	
		if(this['fire'+eventName])
			return this['fire'+eventName].apply(this,arguments);
		if(this.events[eventName]){
			for(var i in this.events[eventName])
				this.events[eventName][i].apply(this,arguments);
		}
	},
	remove : function(component){
		var i=0;
	
		while(this.children[i]!=component){
			if(this.children[i]==null){
				return;}
			i++;
		}
		
		while(this.children[i]!=null){
			this.children[i]=this.children[i+1];
			i++;
		}
		this.children.length--;
		component.parentNode=undefined;
		
	},
	append: function(component){
		this.children[this.children.length]=component;
		component.parentNode=this;

	},
	render: function(){
		
		for(var i=0;i<this.children.length;i++){
			if(this.children[i] && this.children[i].render)
				this.children[i].render();
		}
		this.fire('render');
		window.i++;
	},
	getBaseElement : function(){
		if(this.baseElement)
			return this.baseElement.getBaseElement();
		return null;
	}
});

