var draged=false;
tdiv=null;
function dragStart(){
ao=event.srcElement;
if((ao.tagName=="DT"))ao=ao.parentElement;
else return;
draged=true;
tdiv=document.createElement("div");
tdiv.innerHTML=ao.outerHTML;
tdiv.style.display="block";
tdiv.style.position="absolute";
tdiv.style.filter="alpha(opacity=70)";
tdiv.style.cursor="move";
tdiv.style.width=ao.offsetWidth;
tdiv.style.height=ao.offsetHeight;
tdiv.style.top=getInfo(ao).top;
tdiv.style.left=getInfo(ao).left;
document.body.appendChild(tdiv);
lastX=event.clientX;
lastY=event.clientY;
lastLeft=tdiv.style.left;
lastTop=tdiv.style.top;
try{
ao.dragDrop();
}catch(e){}
}
function draging(){//重要:判断MOUSE的位置
if(!draged)return;
var tX=event.clientX;
var tY=event.clientY;
tdiv.style.left=parseInt(lastLeft)+tX-lastX;
tdiv.style.top=parseInt(lastTop)+tY-lastY;
for(var i=0;i<$("outFrame").childNodes.length;i++){
var parentCell=getInfo($("outFrame").childNodes[i]);
if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
var subTables=$("outFrame").childNodes[i].getElementsByTagName("dl");
if(subTables.length==0){
if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
$("outFrame").childNodes[i].appendChild(ao);
}
break;
}
for(var j=0;j<subTables.length;j++){
var subTable=getInfo(subTables[j]);
if(tX>=subTable.left&&tX<=subTable.right&&tY>=subTable.top&&tY<=subTable.bottom){
$("outFrame").childNodes[i].insertBefore(ao,subTables[j]);
break;
}else{
$("outFrame").childNodes[i].appendChild(ao);
}
}
}
}
}
function dragEnd(){
if(!draged)return;
draged=false;
mm=ff(150,15);
saveLayout();
}
function getInfo(o){//取得坐标
var to=new Object();
to.left=to.right=to.top=to.bottom=0;
var twidth=o.offsetWidth;
var theight=o.offsetHeight;
while(o!=document.body){
to.left+=o.offsetLeft;
to.top+=o.offsetTop;
o=o.parentElement;
}
to.right=to.left+twidth;
to.bottom=to.top+theight;
return to;
}
function ff(aa,ab){//从GOOGLE网站来,用于恢复位置
var ac=parseInt(getInfo(tdiv).left);
var ad=parseInt(getInfo(tdiv).top);
var ae=(ac-getInfo(ao).left)/ab;
var af=(ad-getInfo(ao).top)/ab;
return setInterval(function(){if(ab<1){
clearInterval(mm);
tdiv.removeNode(true);
ao=null;
return
}
ab--;
ac-=ae;
ad-=af;
tdiv.style.left=parseInt(ac)+"px";
tdiv.style.top=parseInt(ad)+"px"
}
,aa/ab)
}
function saveLayout(){
var left="";
var center="";
var right="";
var panel=$("leftPanel").childNodes;
for(var i=0;i<panel.length;i++)
{
if(i==0)
left=panel[i].id;
else
left+=","+panel[i].id;
}
panel=$("centerPanel").childNodes;
for(var i=0;i<panel.length;i++)
{
if(i==0)
center=panel[i].id;
else
center+=","+panel[i].id;
}
panel=$("rightPanel").childNodes;
for(var i=0;i<panel.length;i++)
{
if(i==0)
right=panel[i].id;
else
right+=","+panel[i].id;
}
xkzi.savePanel(left,center,right)
}
function layPanel(){
this.left1="<dl id='left1' class='dragDl'><dt>left1</dt><dd></dd></dl>";
this.left2="<dl id='left2' class='dragDl'><dt>left2</dt><dd></dd></dl>";
this.left3="<dl id='left3' class='dragDl'><dt>left3</dt><dd></dd></dl>";
this.center1="<dl id='center1' class='dragDl'><dt>center1</dt><dd></dd></dl>";
this.center2="<dl id='center2' class='dragDl'><dt>center2</dt><dd></dd></dl>";
this.right1="<dl id='right1' class='dragDl'><dt>right1</dt><dd></dd></dl>";
this.right2="<dl id='right2' class='dragDl'><dt>right2</dt><dd></dd></dl>";
this.right3="<dl id='right3' class='dragDl'><dt>right3</dt><dd></dd></dl>";
this.right4="<dl id='right4' class='dragDl'><dt>right4</dt><dd></dd></dl>";
}
function inint(){//初始化
var laypanel=new layPanel();
var left=xkzi.loadPanel("left").value.split(",");
var center=xkzi.loadPanel("center").value.split(",");
var right=xkzi.loadPanel("right").value.split(",");
for(var i=0;i<left.length;i++)
$("leftPanel").innerHTML+=laypanel[left[i]];
for(var i=0;i<center.length;i++)
$("centerPanel").innerHTML+=laypanel[center[i]];
for(var i=0;i<right.length;i++)
$("rightPanel").innerHTML+=laypanel[right[i]];
for(var i=0;i<$("outFrame").childNodes.length;i++){
var subTables=$("outFrame").childNodes[i].getElementsByTagName("dl");
for(var j=0;j<subTables.length;j++){
subTables[j].childNodes[0].className="dragTR";
subTables[j].childNodes[0].attachEvent("onmousedown",dragStart);
subTables[j].attachEvent("ondrag",draging);
subTables[j].attachEvent("ondragend",dragEnd);
}
}
}
inint();