/**
*	modello框架
**
*	author 贺博
*	date 2006-11-11(光棍节)
**
*	用来描述基类 图形对象
*/
Component = Class.create();
Component.register("com.duxiu.js.Component");

Component.construct = function($self, $class){
	var _dom_object;
	
	this.initialize = function(_d){
		if(typeof _d == 'object'){
			_dom_object = _d;
		}
		else if(typeof _d == 'string'){
			try{
				_dom_object = getObject(_d);
			}
			catch(e){
				_dom_object = document.createElement("div");
				_dom_object.id = _d;
			}			
		}
		else{
			throw new Error("["+_d+"] ,[class Component] '_d' is not a object.");
		}
	}	
	
	//获得DOM对象
	this.getDomObject = function(_d){
		return 	_dom_object;		
	}

	//添加子节点
	this.add = function(childobj){
		if(typeof childobj == 'object'){
			_dom_object.appendChild(childobj);
		}
		else{
			throw new Error("["+childobj+"] ,[class Component] 'childobj' is not a object.");
		}
	}
	
	//删除所有子节点
	this.removeChilds = function(){		
		while(_dom_object.firstChild){
			_dom_object.removeChild(_dom_object.firstChild);			
		}	
	}
	
	//删除节点
	this.remove = function(){
		if(_dom_object.parentNode){
			_dom_object.parentNode.removeChild(_dom_object);		
		}
	}
	
	//插入HTML代码
	this.setInnerHTML =function(_html){
		if(typeof _html=="string"){
			_dom_object.innerHTML = _html;	
		}		
	}
	
	//获得HTML代码
	this.getInnerHTML = function(){
		return _dom_object.innerHTML;	
	}

	//设置 index-Z
	this.setIndexZ = function(_z){
		_dom_object.style.zIndex = _z;		
	}
	
	//设置顶位置
	this.setTop = function(_t){		
		_dom_object.style.top= formatPX(_t);	
	}
	
	//设置左位置
	this.setLeft = function(_l){
		_dom_object.style.left= formatPX(_l);	
	}	
	
	//设置位置
	this.setLocation = function(_t,_l){
		if(_t!="") this.setTop(_t);
		if(_l!="") this.setLeft(_l);
	}
	
	//设置底板颜色
	this.setBackgroundColor = function(_bc){
		_dom_object.style.backgroundColor = _bc;
	}	
	
	//设置文本颜色
	this.setFontColor = function(_fontColor){
		_dom_object.style.color = _fontColor;
	}	
	
	//设置鼠标形状
	this.setCursor = function(_cursor){
		_dom_object.style.cursor = _cursor;		
	}
	
	//设置边宽
	this.setBorderWidth = function(_b){
		_dom_object.style.borderWidth = formatPX(_b);		
	}
	
	//设置边的样式
	this.setBorderStyle = function(_b){
		_dom_object.style.borderStyle = _b;
	}	
	
	//设置边颜色
	this.setBorderColor = function(_borderColor){
		_dom_object.style.borderColor = _borderColor;
	}	
	
	//设置宽
	this.setWidth = function(_w){
		_dom_object.style.width=formatPX(_w);	
	}
	
	//设置高
	this.setHeight = function(_w){
		_dom_object.style.height=formatPX(_w);	
	}
	
	//设置加载方式
	this.setPosition = function(_p){
		_dom_object.style.position=_p;	
	}
	
	//设置内补丁
	this.setPadding = function(_p){
		_dom_object.style.padding=formatPX(_p);	
	}
	
	//设置超出显示
	this.setOverflow = function(_o){
		_dom_object.style.overflow=_o;	
	}
	
	//设置超出显示
	this.setOverflowX = function(_o){
		_dom_object.style.overflowX=_o;	
	}
	
	
	//设置超出显示
	this.setOverflowY = function(_o){
		_dom_object.style.overflowY=_o;	
	}
	
	
	
	//设置透明度
	this.setTransparence =function(_op){
		_dom_object.style.filter="alpha(opacity="+_op+")";
	}	
	//设置显示
	var isDisplay=true;
	this.setDisplay = function(_b){
		isDisplay = _b;
		if(_b){
			_dom_object.style.display = "block";
		}
		else{
			_dom_object.style.display = "none";	
		}	
	}
	//获得显示
	this.getDisplay = function(){
		return isDisplay;
	}
	
	//设置颜色与父亲相同
	this.setParentColor = function(){
		var parent = _dom_object.parentNode;
		if(parent){
			_dom_object.style.borderColor = parent.style.borderColor;
			_dom_object.style.backgroundColor = parent.style.backgroundColor;
			_dom_object.style.color = parent.style.color;
		}
		else{
			throw new Error(_dom_object.toString()+"[com.duxiu.js.Component] has no parentNode.");	
		}
	}
	//获得对象宽
	this.getWidth = function(){
		if(_dom_object.style.width.trim()==""){
			return _dom_object.offsetWidth;
		}
		else{
			return parseInt(_dom_object.style.width.replace(/\D/g,""));
		}
	}
	//获得对象高
	this.getHeight = function(){
		if(_dom_object.style.height.trim()==""){
			return _dom_object.offsetHeight;
		}
		else{
			return parseInt(_dom_object.style.height.replace(/\D/g,""));
		}
	}
	//获得边的宽度
	this.getBorderWidth = function(){
		return _dom_object.style.borderWidth;
	}
	//获得顶位置
	this.getTop = function(){
		if(_dom_object.style.top.trim()==""){
			return _dom_object.offsetTop;
		}
		else{
			return parseInt(_dom_object.style.top.replace(/\D/g,""));
		}
	}
	//获得左位置
	this.getLeft = function(){		
		if(_dom_object.style.top.trim()==""){
			return _dom_object.offsetLeft;
		}
		else{
			return parseInt(_dom_object.style.left.replace(/\D/g,""));
		}
	}	
	//获得Id
	this.getId = function(){		
		return _dom_object.id;
	}
}
