/*
author: nekio@163.com
ps: 最小化需要在按钮上指定style的高和宽
*/
var effect_num = 8;//大小变化效果次数
var step = 30;//效果间隔时间（毫秒）
var obj,bt,content,i,w_init,h_init,left_init,top_init,x,y,xl,yl,xo,yo,xc,yc;
var lx=0,ly=0,canDrg=false,thiso=null,width=null,height=null,cheight=null;//
var rw,rh,className;

function move_show(o,w,h,ch){
	width = w; height = h; cheight = ch;
	if(o.style.left==""){xo = getLeft(o);}else{xo = parseInt(o.style.left);}
    if(o.style.top==""){yo = getTop(o);}else{yo = parseInt(o.style.top);}
	rw=parseInt(x)-xo;
    rh=parseInt(y)-yo;
    //window.status=rw+"||文本区域||"+rh;
    //if(rh<=cheight && rw>width)window.status=rw+"||关闭区域||"+rh;//右上角的关闭区域
    //if((rh<=height && rw<=width) || (rw>width && rh>cheight && rh<=height))window.status=rw+"||拖动区域||"+rh;//绝对拖动条选择区域;
    //if(rh>height)window.status=rw+"||文本区域||"+rh;//绝对拖动条选择区域;
}

function dargit(o,e){
if(o != null){
thiso = o;
canDrg = true;
//className = thiso.style.boder;
//thiso.className = "drag";
if((rh<=height && rw<=width) || (rw>width && rh>cheight && rh<=height)){//判断拖动区域
    if(explorer=="ie"){
		thiso.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
	}else if(explorer=="ff"){
		thiso.style.opacity = "0.5";	 
	}
}
if(!document.all){
  lx = e.clientX; ly = e.clientY;
  }else{
	lx = event.x; ly = event.y;
}
 //if(document.all) thiso.setCapture();
}
    
if(rh<=cheight && rw>width){
	canDrg=false;
	//如果选择的是关闭区域;
	o.style.display="none";
}
 
}

document.onmousemove = function(e){
if(!document.all){ x = e.clientX; y = e.clientY; }else{ x = event.x; y = event.y;}
if(canDrg){
	 if((rh<=height && rw<=width) || (rw>width && rh>cheight && rh<=height)){//判断拖动区域
	 var ofsx = x - lx;
	 thiso.style.left = xo+ofsx+"px";
	 lx = x;
	 var ofsy = y - ly;
	 thiso.style.top = yo+ofsy+"px";
	 ly = y;
	 }else{canDrg=false;}
}
}

document.onmouseup=function(){
     canDrg=false;//拖拽变量设为false
if(thiso != null){
	//thiso.className = className;
	if(explorer=="ie"){
		thiso.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
	}else if(explorer=="ff"){
		thiso.style.opacity = "1.0";	 
	}
}
	 if(document.all && thiso != null){
      //thiso.releaseCapture();//ie，clear capture;
      thiso = null;
   }
}

function Max(o,t_id){
    var windowinfo = new window_info();
    //document.title = "窗口宽:"+windowinfo.winWidth+"窗口高:"+windowinfo.winHeight+"滚动宽度"+windowinfo.xScroll+"滚动高度:"+windowinfo.yScroll;
	//init div_window
    o.disabled=true;bt = o;
    xl = getLeft(o);
    yl = getTop(o);
    //alert(xl+"|"+yl+"|"+document.body.scrollWidth+"|"+document.body.scrollHeight);return;
    obj = document.getElementById(t_id);
    //reset position
	obj.style.left = parseInt(windowinfo.xScroll)+(parseInt(windowinfo.winWidth)-parseInt(obj.style.width))/2+"px";
    obj.style.top = parseInt(windowinfo.yScroll)+(parseInt(windowinfo.winHeight)-parseInt(obj.style.height))/2+"px";
	//get position
	if(obj.style.left==""){xo = getLeft(obj);}else{xo = parseInt(obj.style.left);}
    if(obj.style.top==""){yo = getTop(obj);}else{yo = parseInt(obj.style.top);}//alert(xo+"|"+yo);
    xc = xo+parseInt(obj.style.width)/2;
    yc = yo+parseInt(obj.style.height)/2;
    obj.style.display="none";
    content = obj.innerHTML;
    obj.innerHTML="";
    w_init = obj.style.width;
    h_init = obj.style.height;
    i = effect_num;
    _Max();
}

function _Max(){
   if(i>0){//alert(i);
       obj.style.width = parseInt(w_init)/i+"px";
	   obj.style.height = parseInt(h_init)/i+"px";
	   i--;
	   x = xc-parseInt(obj.style.width)/2+(xl-xc)*i/effect_num;
	   y = yc-parseInt(obj.style.height)/2+(yl-yc)*i/effect_num;
	   //alert(x+"|"+y);
	   obj.style.left = x+"px";
	   obj.style.top = y+"px";
	   obj.style.display="block";
	   setTimeout('_Max()',step);
   }else{
       obj.innerHTML = content;
	   bt.disabled="";
   }
}

function Min(id,t_id){
   var o = document.getElementById(id);
   xl = parseInt(o.style.width);
   yl = parseInt(o.style.height);
   xl += getLeft(o);
   yl += getTop(o);
   //alert(xl+"|"+yl+"|"+document.body.scrollWidth+"|"+document.body.scrollHeight);return;
   obj = document.getElementById(t_id);
   if(obj.style.left==""){xo = getLeft(obj);}else{xo = parseInt(obj.style.left);}
   if(obj.style.top==""){yo = getTop(obj);}else{yo = parseInt(obj.style.top);}//alert(xo+"|"+yo);
   xc = xo+parseInt(obj.style.width)/2;
   yc = yo+parseInt(obj.style.height)/2;
   left_init = xo+"px"; 
   top_init = yo+"px";
   content = obj.innerHTML;
   obj.innerHTML="";
   w_init = obj.style.width;
   h_init = obj.style.height;
   i = effect_num;
   _Min();
}

function _Min(){
   if(i>0){//alert(i);
       obj.style.width = parseInt(w_init)*i/effect_num+"px";
	   obj.style.height = parseInt(h_init)*i/effect_num+"px";
	   x = xc-parseInt(obj.style.width)/2-(xc-xl)/i;
	   y = yc-parseInt(obj.style.height)/2-(yc-yl)/i;
	   i--;
	   obj.style.left = x+"px";
	   obj.style.top = y+"px";
	   setTimeout('_Min()',step);
   }else{
       obj.style.display = "none";
	   obj.style.width = w_init;
	   obj.style.height = h_init;
	   obj.style.left = left_init;
	   obj.style.top = top_init;
	   obj.innerHTML = content;
   }
}

function Close(id){
   document.getElementById(id).style.display="none";
}
