var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);

function ddInit(e){
	m_top=ie4 ? "BODY" : "HTML";
	m_which=ie4 ? document.all.theLayer : document.getElementById("theLayer");  
	m_hot=ie4 ? event.srcElement : e.target;  
	while (m_hot.id!="titleBar"&&m_hot.tagName!=m_top){
		m_hot=ie4 ? m_hot.parentElement : m_hot.parentNode;
	}  
	if (m_hot.id=="titleBar"){
		offsetx=ie4 ? event.clientX : e.clientX;
		offsety=ie4 ? event.clientY : e.clientY;
		nowX=parseInt(m_which.style.left);
		nowY=parseInt(m_which.style.top);
		ddEnabled=true;
		document.onmousemove=dd;
	}
}

function dd(e){
	if (!ddEnabled) return;
	m_which.style.left=ie4 ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
	m_which.style.top=ie4 ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
	return false;  
}

function hideMe(){
	if (ns6) {
		document.getElementById("theLayer").style.visibility="hidden";
	} else if(ie4) {
		document.getElementById("theLayer").style.visibility="hidden";
	} else if(ns4) {
		document.theLayer.visibility="hide";
	}
}

function showMe(m_x, m_y){
	start(m_x, m_y);
	if (ns6) {
		document.getElementById("theLayer").style.visibility="visible";
	} else if(ie4) {
		document.getElementById("theLayer").style.visibility="visible";
	} else if(ns4) {
		document.theLayer.visibility="show";
	}
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

function layerObject(id, left, top) {
	if (ns6) {
		this.obj = document.getElementById(id).style;
		this.obj.left = left;
		this.obj.top = top;
		return this.obj;
	} else if(ie4) {
		this.obj = document.all[id].style;
		this.obj.left = left;
		this.obj.top = top;
		return this.obj;
	} else if(ns4) {
		this.obj = document.layers[id];
		this.obj.left = left;
		this.obj.top = top;
		return this.obj;
	}
}

function layerSetup(m_x, m_y) {
	floatLyr = new layerObject('theLayer', m_x, m_y);
}

function main() {
	if (ns4) {
		this.currentY = document.layers["theLayer"].top;
		this.scrollTop = window.pageYOffset;
	} else if(ns6) {
		this.currentY = parseInt(document.getElementById('theLayer').style.top);
		this.scrollTop = scrollY;
	} else if(ie4) {
		this.currentY = theLayer.style.pixelTop;
		this.scrollTop = document.body.scrollTop;
	}
}
			
function start(m_x, m_y) {
	if(ns6||ns4) {
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		layerSetup(m_x, m_y);
	} else if(ie4) {
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		layerSetup(m_x, m_y);
	}
}