CDrag.Table = Class.create();
CDrag.Table.prototype = {
//列的拖拽暂时不考虑
 initialize : function () {
 //初始化
  var wc = this;
  wc.items = []; //创建列组
 },
 
 add : function () {
 //添加列
  var wc = this, id = wc.items.length, arg = arguments;
  return wc.items[id] = new CDrag.Table.Cols(id, wc, arg[0]);
 },
 
 getItemById: function (id) {
 	var wc = this;
 	for(var i=0;i<wc.items.length;i++){
 		if(wc.items[i].element.id == id){
 			return wc.items[i];
 		}
 	}
 }
};
CDrag.Table.Cols = Class.create();
CDrag.Table.Cols.prototype = {
 
 initialize : function (id, parent, element) {
 //初始化
  var wc = this;
  wc.items = []; //创建列组
  wc.id = id;
  wc.parent = parent;
  wc.element = element;
 },
 
 add : function () {
 //添加行
  var wc = this, id = wc.items.length, arg = arguments;
  return wc.items[id] = new CDrag.Table.Rows(id, wc, arg[0], arg[1], arg[2]);
 },
 
 ins : function (num, row) {
 //插入行
  var wc = this, items = wc.items, i;
  
  if (row.parent == wc && row.id < num) num --; //同列向下移动的时候
  for (i = num ; i < items.length ; i ++) items[i].id ++;
  
  items.splice(num, 0, row);
  row.id = num, row.parent = wc;
  
  return row;
 },
 
 del : function (num) {
 //删除行
  var wc = this, items = wc.items, i;
  
  if (num >= items.length) return;
  for (i = num + 1; i < items.length ; i ++) items[i].id = i - 1;
  return items.splice(num, 1)[0];
 }
 
};
CDrag.Table.Rows = Class.create();
CDrag.Table.Rows.prototype = {
 
 
 initialize : function (id, parent, element, window, locks) {
 //初始化
  var wc = this, temp;
  
  wc.id = id;
  wc.parent = parent;
  wc.root_id = element;
  wc.window = window;
  wc.element = wc.element_init();
  //alert(wc.element.innerHTML);
  temp = wc.element.childNodes[0];
//  alert(temp);
  wc.title = temp.childNodes[4];
//  alert(wc.title);
  wc.reduce = temp.childNodes[3];
  wc.lock = temp.childNodes[2], wc.locks = locks;
  wc.edit = temp.childNodes[1];
  wc.close = temp.childNodes[0];
  wc.content = wc.element.childNodes[1];
  wc.Class = wc.mousedown = wc.reduceFunc = wc.lockFunc = wc.editFunc = wc.closeFunc = null;
  wc.init();
  wc.load();
  
 },
 
 element_init : function () {
 //初始化元素
  var wc = this, div = getE("root_row").cloneNode(true);
  
  wc.parent.element.appendChild(div);
  div.style.display = "block";
  return div;
 },
 
 init : function () {
 //初始化信息
  var wc = this;
  if (wc.window == 0) {
   wc.content.style.display = "none";
   wc.reduce.innerHTML = "放大";
  } else {
   wc.content.style.display = "block";
   wc.reduce.innerHTML = "缩小";
  }
  
  wc.lock.innerHTML = "复制";
 },
 
 load : function () {
 //获取相关信息
  var wc = this, info = CDrag.database.parse(wc.root_id), script;
  wc.title.innerHTML = info.title;
  if (info.src) {
    wc.content.innerHTML = "loading";
    script = document.createElement("script");
    script.src = info.src + ".js"//, script.defer = true;
    document.getElementsByTagName("head")[0].appendChild(script);
    CDrag.load(info.className, wc.upload.bind(wc), 5);
  } else {
  //显示数据的地方
  	wc.content.innerHTML = info.title;
  	var channel = getChannel(info.type);
  	if(info.type == "newscontent"){//例外处理
  		wc.content.innerHTML = channel.buildContent(info);
  	}else{
	  	$.getJSON(
			path+'/ajax/static2dync/syncData.do',
			channel.buildParams(portal_id,info),
			function(json){
				try{
					wc.content.innerHTML = channel.buildContent(json,info);
				}catch(ex){}
			}
		);
	}
  }
 },
 
 upload : function (obj) {
 /*加载类信息
  注：这里给行加入了一个扩展类，这里行的内容可以通过扩展类来控制^o^
  不过扩展类的格式必须有open方法和edit方法，还有类名.静态成员loaded = true；为了检测是否加载完毕
  扩展类需放到单独的.js文件里，然后从database结构体内设定其参数即可
 */
  var wc = this;
  wc.Class = obj;
  wc.Class.parent = wc;
  wc.editFunc = Object.addEvent(wc.edit, ["onclick"], wc.lockF(wc.Class, wc.Class.edit, wc));
  wc.Class.open();
 },
 
 lockF : function () {
 //检索锁定
  var wc = this, arg = getA(arguments), root = arg.shift(), func = arg.shift();
  return function () {
   if (!wc.locks) func.apply(root, arg.concat(getA(arguments)));
  };
 }
 
};
