  function mvd(id,title,top,left,height,width,contentNode) {

    // PROPERTIES
    this.mx              = 0;
    this.my              = 0;
    this.id              = id;
		this.title           = title;
    this.height          = height;
    this.width           = width;		
    this.navHeight       = 15;
    this.cPadding        = 10;    
    this.paddingBottom   = 15;    		
		this.el              = document.createElement('div');
    this.top             = parseInt(this.el.style.top)  ? parseInt(this.el.style.top)  : top;
    this.left            = parseInt(this.el.style.left) ? parseInt(this.el.style.left) : left;
		this.top            += (window.scrollY) ? window.scrollY : document.documentElement.scrollTop;
		this.left           += (window.scrollX) ? window.scrollX : document.documentElement.scrollLeft;		
    this.el.id           = this.id;
    this.el.style.width  = width + 'px';
    this.el.style.height = height + 'px';
    this.el.style.top    = this.top  + 'px';
    this.el.style.left   = this.left + 'px';
    this.el.className    = 'mvd';
		this.el.onclick      = new Function('mvdar["'+this.id+'"].setCurrent()');
    this.md              = new Function('e','mvdar["'+this.id+'"].start(e)');
    this.mm              = new Function('e','mvdar["'+this.id+'"].move(e)');
    this.mu              = new Function('e','mvdar["'+this.id+'"].stop(e)');
    this.mrd             = new Function('e','mvdar["'+this.id+'"].startResize(e)');		
    this.mrm             = new Function('e','mvdar["'+this.id+'"].resize(e)');		
    this.mru             = new Function('e','mvdar["'+this.id+'"].stopResize(e)');				
    this.toggleDisplay   = new Function('mvdar["'+this.id+'"].display()');
    
		// METHODS    
    
    mvd.prototype.createNavbar = function(){
      
      var bar         = document.createElement('div');
      bar.className   = 'top';
			bar.onmousedown = this.md;
      bar.ondblclick  = this.toggleDisplay;
      
      var close       = document.createElement('a');
      close.className = 'close';
      close.onclick   = new Function('mvdar["'+this.id+'"].remove()');
      close.appendChild(document.createTextNode('close'));
      bar.appendChild(close);
      
      var min         = document.createElement('a');
      min.id          = this.id+'_display';       
      min.className   = 'min';
      min.onclick     = new Function('mvdar["'+this.id+'"].toggleDisplay()');
      bar.appendChild(min);            
     
      bar.appendChild(document.createTextNode(this.title));
      
      return bar;
    }



    mvd.prototype.createContent = function(){
      var c           = document.createElement('div');
      c.style.height  = this.height - (this.navHeight+this.cPadding) + 'px';
      c.className     = 'content';
      c.id            = this.id+'_c';
      c.appendChild(contentNode);
			
      return c;
    }


    
    mvd.prototype.display = function(){
      var el                   = document.getElementById(this.id+'_c');
      el.style.display         = ((el.style.display == '') || (el.style.display == 'block')) ? 'none' : 'block';
			
      var el                   = document.getElementById(this.id);
      el.style.height          = (parseInt(el.style.height) == this.height) ? this.navHeight+'px' : this.height+'px';
      el.style.paddingBottom   = ((el.style.paddingBottom == '') || (parseInt(el.style.paddingBottom) == this.paddingBottom)) ? '0' : this.paddingBottom+'px';

			var el                   = document.getElementById(this.id+'_corner');
			el.style.display         = ((el.style.display == '') || (el.style.display == 'block')) ? 'none' : 'block';			
			
      var el                   = document.getElementById(this.id+'_display');
      el.className             = (el.className == 'min') ? 'max' : 'min';
    }    



    mvd.prototype.start = function(e){
      document.addEventListener ? document.addEventListener('mousemove',this.mm,true) : document.attachEvent('onmousemove',this.mm);
      document.addEventListener ? document.addEventListener('mouseup',this.mu,true)   : this.el.attachEvent('onmouseup',this.mu);

      this.setCurrent();
			
      this.top          = getPageOffsetTop(this.el);
      this.left         = getPageOffsetLeft(this.el);

      if(!e){ e = window.event; }
	
      this.mx    = e.clientX;
      this.my    = e.clientY;

      if(e.preventDefault){
				e.preventDefault();
			}
			else {
				e.cancelBubble = true;
				e.returnValue  = false;
			}
    }
		
    mvd.prototype.startResize = function(e){
      document.addEventListener ? document.addEventListener('mousemove',this.mrm,true) : document.attachEvent('onmousemove',this.mrm);
      document.addEventListener ? document.addEventListener('mouseup',this.mru,true)   : this.el.attachEvent('onmouseup',this.mru);

      this.setCurrent();
			
      this.top          = getPageOffsetTop(this.el);
      this.left         = getPageOffsetLeft(this.el);

      if(!e){ e = window.event; }
	
      this.mx    = e.clientX;
      this.my    = e.clientY;

      if(e.preventDefault){
				e.preventDefault();
			}
			else {
				e.cancelBubble = true;
				e.returnValue  = false;
			}
    }		



    mvd.prototype.setCurrent = function(){
      var ar = document.getElementsByTagName('div');
      for(var i=0;i<ar.length;i++){
        if(ar[i].className.indexOf('mvd') != -1){
          ar[i].className = 'mvd';
        }
      }
      document.getElementById(this.id).className = 'mvd curr';
    }



    mvd.prototype.move = function(e){
      if(!e){ e = window.event; }

			var x = ((this.left - (this.mx-e.clientX)) >= 0) ? (this.left - (this.mx-e.clientX)) : 0;
			var y = ((this.top  - (this.my-e.clientY)) >= 0) ? (this.top  - (this.my-e.clientY)) : 0;

    	this.el.style.top   = y + 'px';
    	this.el.style.left  = (this.left - (this.mx-e.clientX)) + 'px';

      if(e.preventDefault){
				e.preventDefault();
			}
			else {
				e.cancelBubble = true;
				e.returnValue  = false;
			}
    }


    mvd.prototype.resize = function(e){
      if(!e){ e = window.event; }

			el = document.getElementById(this.id+'_c');

			if(this.height - (this.my-e.clientY) > 50){
				this.el.style.height = this.height - (this.my-e.clientY) + 'px';
				el.style.height      = this.height - (this.my-e.clientY) - (this.navHeight+this.cPadding) + 'px';
			}
			if(this.width - (this.mx-e.clientX) > 150){
    		this.el.style.width  = this.width - (this.mx-e.clientX) + 'px';
			}
			
      if(e.preventDefault){
				e.preventDefault();
			}
			else {
				e.cancelBubble = true;
				e.returnValue  = false;
			}
    }


    mvd.prototype.stop   = function(e){ 
      document.removeEventListener ? document.removeEventListener('mousemove',this.mm,true) : document.detachEvent('onmousemove',this.mm);
			e.currentTarget ? e.currentTarget.className = 'mvd last' : this.el.className = 'mvd last'; 
		}
	
    mvd.prototype.stopResize   = function(e){ 
      document.removeEventListener ? document.removeEventListener('mousemove',this.mrm,true) : document.detachEvent('onmousemove',this.mrm);
      document.removeEventListener ? document.removeEventListener('mouseup',this.mru,true)   : this.el.detachEvent('onmouseup',this.mru);
						
			this.height = parseInt(this.el.style.height);
			this.width  = parseInt(this.el.style.width);			
			e.currentTarget ? e.currentTarget.className = 'mvd last' : this.el.className = 'mvd last'; 
		}		



    mvd.prototype.remove = function(){ document.getElementsByTagName('body')[0].removeChild(this.el); }



    this.el.appendChild(this.createNavbar());
    this.el.appendChild(this.createContent());
		
		var a         = document.createElement('a');
		a.className   = 'corner';
		a.id          = this.id+'_corner';
		a.onmousedown = this.mrd;
		a.appendChild(document.createTextNode('drag to resize'));
		
		this.el.appendChild(a);
					
    document.getElementsByTagName('body')[0].appendChild(this.el);
  }
	


function getPageOffsetLeft(el) {
  var x;
  x = el.offsetLeft;
  if (el.offsetParent != null) { x += getPageOffsetLeft(el.offsetParent); }
  return x;
}


function getPageOffsetTop(el) {
  var y;
  y = el.offsetTop;
  if (el.offsetParent != null) { y += getPageOffsetTop(el.offsetParent); }
  return y;
}	
