var chkOnTop = true;
var dragObj = null;
var tx;
var ty;
var ie5 = document.all != null && document.getElementsByTagName != null;
var mz = document.getElementById && !document.all && document.documentElement;

//-----------------------------------------------------------------------------
function getByClass(el, classStr) {
	tmp = el;
	while ((tmp != null) && (tmp.tagName != "BODY")) {
		if (tmp.className == classStr){
			el = tmp;
			return el;
		}
		tmp = tmp.parentElement;
	}
	return el;
}
//-----------------------------------------------------------------------------
function fn_onmousedown(e) {
	if (!e){
		var e = window.event;
		eSrc = e.srcElement;
	}
	else{
		eSrc = e.target;
	}
	el = getByClass(eSrc, "iC");
	if (el.className == "iC") {
		tmp = el.getAttribute("dragfor");
		if (tmp == null) {
			dragObj = null;
			return;
		}
		else
			dragObj = document.getElementById(tmp);

		tx = e.clientX - getLeft(dragObj);
		ty = e.clientY - getTop(dragObj);
		
		if(mz){
			e.preventDefault();
			e.stopPropagation();
		}
		else{
			window.event.returnValue = false;
			window.event.cancelBubble = true;
		}
	}
	else {
		dragObj = null;
	}
}
//-----------------------------------------------------------------------------
function fn_onmouseup() {
	if(dragObj) {
		dragObj = null;
	}
}
//-----------------------------------------------------------------------------
function fn_onmousemove(e) {
	if (dragObj) {
		if (!e){var e = window.event;}
		if (e.clientX >= 0 && e.clientY >= 0) {
			if (mz){
				dragObj.style.left = e.clientX - tx + "px";
				dragObj.style.top = e.clientY - ty + "px";
			}
			else{
				dragObj.style.left = e.clientX - tx;
				dragObj.style.top = e.clientY - ty;
			}
		}
		if(mz){
			e.preventDefault();
			e.stopPropagation();
		}
		else{
			window.event.returnValue = false;
			window.event.cancelBubble = true;
		}
	}
}
//-----------------------------------------------------------------------------
function getLeft(el) {
	if (ie5) {
		if (el.currentStyle.left == "auto")
			return 0;
		else
			return parseInt(el.currentStyle.left);
	}
	else {
		if(mz){
			return parseInt(el.style.left);
		}
		else{
			return el.style.pixelLeft;
		}
	}
}
//-----------------------------------------------------------------------------
function getTop(el) {
	if (ie5) {
		if (el.currentStyle.top == "auto")
			return 0;
		else
			return parseInt(el.currentStyle.top);
	}
	else {
		if(mz){
			return parseInt(el.style.top);
		}
		else{
			return el.style.pixelTop;
		}
	}
}

//-----------------------------------------------------------------------------
if (document.all) {
	document.onmousedown = fn_onmousedown;
	document.onmouseup = fn_onmouseup;
	document.onmousemove = fn_onmousemove;
}
else 
{
	if( document.getElementById ) {
		document.captureEvents( Event.MOUSEDOWN );
		document.onmousedown = fn_onmousedown;
		document.captureEvents( Event.MOUSEUP );
		document.onmouseup = fn_onmouseup;
		document.captureEvents( Event.MOUSEMOVE );
		document.onmousemove = fn_onmousemove;
	}
}

