// JavaScript Document

Function.prototype.fasten = function (object){

	var method = this;

	return function (){

		return method.apply(object, arguments);

	};

};

//------------------------------\\

function Enumerator(arr){

	this.items=arr;

	this.currentIndx=0;

	this.atEnd=function(){

		if((this.items.length)==this.currentIndx) return true;

		return false;

	};

	this.current=function(){

		return(this.items[this.currentIndx]);

	};

	this.moveFirst=function(){

		this.currentIndx=0;

	};

	this.moveNext=function(){

		this.currentIndx++;

	};

	this.last=function(){

		return(this.items[this.items.length-1]);

	};

	this.first=function(){

		return(this.items[0]);

	};

}

function IList(owner){

	if(!owner)return null;

	this.owner=owner;

	this.items=new Array();

	this.indexes=new Object();



	this.enm=Enumerator;

	this.enm(this.items);

	this.count=function(){return (this.items.length)};

	this.add=function(obj){

		if(obj.name){

			if(this.indexes[obj.name] && this.indexes[obj.name].destroyed===false && !overwrite){

				alert("IList.add Error:the object="+obj.name+" Child of "+this.owner.name+" exist");

				return;

			}

			this.indexes[obj.name]=this.items.length;

		}

		this.items.push(obj);

	};

	this.clear=function(){

		this.items=new Array();

		this.indexes=new Object();

		this.currentIndx=0;

	};

	this.remove=function(obj){

		this.removeAt(this.indexOf(obj));

	};

	this.removeAt=function(indx){

		if(!(indx>-1 && indx<this.items.length)) return;

		if(this.items[indx].name){ delete this.indexes[this.items[indx].name];}

		this.items.splice(indx,1);

		if(indx<=this.currentIndx) this.currentIndx--;

	};

	this.indexOf=function(obj){

		if(this.indexes.hasOwnProperty(obj)) return this.indexes[obj];

		else if(obj.hasOwnProperty('name') && this.indexes.hasOwnProperty(obj.name)) return this.indexes[obj.name];

		else	for(var dx in this.items){

			if(this.items[dx]===obj) return dx;

		}

		return -1;

	};

	this.valueOf=function(indx){

		if(!(indx>-1 && indx<this.items.length)) return;

		return (this.items[indx]);

	}

	this._=function(obj){

		return(this.items[this.indexOf(obj)])

	};

};

var Drag={

	_obj:null,

	_lastX:0,

	_lastY:0,

	construct:function(objDragged){

		

	},

	startDrag:function(evt){

		evt = this._fixE(evt);

		var Sender=(evt.target)?evt.target:evt.srcElement;

		if(!this._obj || this._obj.className!='holder'){

			this._obj=Sender.parentNode.parentNode.parentNode.parentNode.parentNode;

			document.onmousemove = this.startDrag.fasten(this);

			document.onmouseup = this.end.fasten(this);

			if(this._obj.style.position!='absolute')this._obj.style.position='fixed';

			/*var text='';

			for(var dx in evt){

				text+="event."+dx+"="+evt[dx]+"\n";

			}

			alert(text);

			document.body.debugEvent=evt;*/

		}

		this._obj.style.top=((evt.clientY)-12)+'px';

		this._obj.style.left=(evt.clientX-(this._obj.offsetWidth/2))+'px';

		

		

		

		

	},

	startResize:function(evt){

		evt = this._fixE(evt);

		if(!this._obj || this._obj.className!='holder'){

			var Sender=(evt.target)?evt.target:evt.srcElement;

			this._obj=Sender.parentNode.parentNode.parentNode.parentNode.parentNode;

			this._lastX=(this._obj.offsetLeft-8)+this._obj.offsetWidth;

			document.onmousemove = this.startResize.fasten(this);

			document.onmouseup = this.end.fasten(this);

		}

		dx=evt.clientX-this._lastX;

		if(this._obj.clientWidth<301){this._obj.style.width='310px';this.end();return}

		this._obj.style.width=(this._obj.clientWidth+dx)+'px';

		this._lastX=evt.clientX;

	},

	start:function(evt){

		evt = this._fixE(evt);

		if(!this._obj){

			this._obj=(evt.target)?evt.target:evt.srcElement;

			this._obj.Drag=this;

			document.onmousemove = this.drag.fasten(this);

			document.onmouseup = this.end.fasten(this);

		}

		this._lastX=evt.clientX;

		this._lastY=evt.clientY;

		

	},

	drag:function(evt){

		evt = this._fixE(evt);

		target=this._obj;

		var oTable=target.parentNode.parentNode.parentNode;

				

		//new way

		var dx=evt.clientX-this._lastX;

		target.previousSibling.width=parseInt(target.previousSibling.clientWidth+dx)+'px';

		if(target.previousSibling.Body)	target.previousSibling.Body.style.width=parseInt(target.previousSibling.width)+'px';

		for(var i=0;i<oTable.tBodies[0].rows.length;i++){

			oTable.tBodies[0].rows[i].cells[target.previousSibling.cellIndex].width=parseInt(target.previousSibling.width)+'px';

			if(oTable.tBodies[0].rows[i].cells[target.previousSibling.cellIndex].Body)

				oTable.tBodies[0].rows[i].cells[target.previousSibling.cellIndex].Body.style.width=parseInt(target.previousSibling.width)+'px';

		}

		this._lastX=evt.clientX;

		

	},//drag End;

	end:function(){

		document.onmousedown=null;

		document.onmousemove = null;

		document.onmouseup = null;

		this._obj = null;

		this._lastX=0;

		this._lastY=0;

	},//end End;

	_fixE:function(evt){

		if (typeof evt == 'undefined') evt = window.event;

		if (typeof evt.layerX == 'undefined') evt.layerX = evt.offsetX;

		if (typeof evt.layerY == 'undefined') evt.layerY = evt.offsetY;

		return evt;

   	}//_fixE End;

}