// floating window frame
function fwloadpos(wndname) {
	eval("ssssFloatWindow"+wndname+".style.pixelLeft = getCookie(\"fw"+wndname+"left\");");
	eval("ssssFloatWindow"+wndname+".style.pixelTop = getCookie(\"fw"+wndname+"top\");");
}
function fwsavepos(wndname) {
	eval("setCookie(\"fw"+wndname+"left\", ssssFloatWindow"+wndname+".style.pixelLeft);");
	eval("setCookie(\"fw"+wndname+"top\", ssssFloatWindow"+wndname+".style.pixelTop);");
}

function ssFloatWindow(id, title) {
	this.id = id;
	this.name = title;
	document.write("<div id=ssssFloatWindow"+id+" style='position:absolute;display:none;cursor:default' " +
		"onselectstart='myonselectstart()' oncontextmenu='myoncontextmenu()'> " +
		"<table border=1 bordercolordark=#FFFFFF bordercolorlight=#444444 cellspacing=0 cellpadding=0>" +
		"<tr><td id="+id+"_title class=fwindowtitle align=center onmousedown=\"startMove(document.getElementById('.ssssFloatWindow"+id+"')\" onmousemove=movIng(event) onmouseup=stopMove(\""+id+"\")>"+title+"</td></tr>" +
		"<tr><td id="+id+"_body class=fwindowbody align=center></td></tr>" +
		"</table></div>");
	fwloadpos(id);
}

ssFloatWindow.prototype.setTitle = function(titleHTML) { this.title = titleHTML; document.getElementById(this.id+"_title").innerHTML = titleHTML; };
ssFloatWindow.prototype.setBody = function(bodyHTML) { document.getElementById(this.id+"_body").innerHTML = bodyHTML; };

ssFloatWindow.prototype.show = function() { document.getElementById('ssssFloatWindow'+this.id).style.display = ''; };
ssFloatWindow.prototype.hide = function() { document.getElementById('ssssFloatWindow'+this.id).style.display = 'none'; };

ssFloatWindow.prototype.moveTo = function(x, y) {
	document.getElementById('obj'+this.id).style.left = x;
	document.getElementById('obj'+this.id).style.top = y;
};
ssFloatWindow.prototype.HTML = function() {
	return document.getElementById('ssssFloatWindow'+this.id);
}

var moveinfo = null;

function MoveInfo()
{
}

function startMove(mo, e, detach)
{
	e = e || window.event;
	if (e.preventDefault) {
		e.preventDefault();
	}
	var o = e_getSrc(e);

	mo = mo || o;
	if (typeof mo == 'string') {
		mo = document.getElementById(mo);
	}

	if (mo.tagName == "A" || o.tagName == 'A') {
		return;
	}
	if (!mo.style || (e.button || e.which) != 1) {
		return;
	}

	if (!mo.moveInfo) {
		mo.moveInfo = new MoveInfo();
		var mi = mo.moveInfo;
		mi.target = mo;
		if (!mo.style.position) {
			mi.canToggle = true;
		}
		if (detach) {
			mi.pos = GetAbsolutePosition(mo);
		}
		else {
			mi.pos = { left: mo.offsetLeft, top: mo.offsetTop };
		}
		mi.origpos = { left: mi.pos.left, top: mi.pos.top };
	}
	var mi = mo.moveInfo;
	mi.started = false;
	mi.capture = null;
	mi.x = e.screenX;
	mi.y = e.screenY;
	mi.detach = detach;
	moveinfo = mi;
}
SS.listen(document, 'mousemove', function(e) {
	e = e || window.event;

	var mi = moveinfo;
	if (!mi || mi.stopping) return;
	var mo = mi.target;

	if (mi.started) {
		var x, y, b = SS.getBody();
		var ex = e.screenX;
		var ey = e.screenY;
		if (mi.canToggle && mo.style.position != 'absolute') {
			MoveToggleOut(mi, true);
		}

		x = mo.offsetLeft;
		y = mo.offsetTop;

		x = x + ex - mi.x;
		y = y + ey - mi.y;
		mi.x = ex;
		mi.y = ey;
		try {
			var bw = (b.clientWidth||b.offsetWidth) - mo.offsetWidth - 20;
			var minx = b.scrollLeft + Math.min(0, bw);
			var maxx = b.scrollLeft + Math.max(0, bw);
			if (!isNaN(minx) && !isNaN(maxx)) x = Math.min(Math.max(x, minx), maxx);
		} catch(e){}
		try {
			var bh = (b.clientHeight||b.offsetHeight) - mo.offsetHeight - 20;
			var miny = b.scrollTop  + Math.min(0, bh);
			var maxy = b.scrollTop  + Math.max(0, bh);
			if (!isNaN(miny) && !isNaN(maxy)) y = Math.min(Math.max(y, miny), maxy);
		} catch(e){}
		mo.style.left = x + 'px';
		mo.style.top  = y + 'px';
	}
	else if (!mi.started) {
		if (Math.abs(mi.x - e.screenX) > 5 || Math.abs(mi.y - e.screenY) > 5) {
			mi.started = true;
			mi.capture = e_getSrc(e);
			if (mi.capture.setCapture) {
				mi.capture.setCapture();
			}
		}
	}
	return false;
});
function MoveToggleIn(mi)
{
	var mo = mi.target;
	mi.pos.left = mo.offsetLeft;
	mi.pos.top  = mo.offsetTop;

	if (mi.parentNode) {
		mo.parentNode.removeChild(mo);
		if (mi.nextSibling) {
			mi.parentNode.insertBefore(mo, mi.nextSibling);
			mi.nextSibling = null;
		}
		else {
			mi.parentNode.appendChild(mo);
		}
		mi.parentNode = null;
	}
	if (mi.substImg && mi.substImg.parentNode) {
		mi.substImg.parentNode.removeChild(mi.substImg);
	}
	mo.style.position = '';
}
function MoveToggleOut(mi, reset)
{
	var mo = mi.target;

	if (mo.nodeName == 'IMG') {
		if (!mi.substImg) {
			//var img = document.createElement('IMG');
			var img = mo.cloneNode(true);
			img.src = imgurl + '/!/spacer.gif';
			img.onmousedown = null;
			img.width = mo.width;
			img.height = mo.height;
			mi.substImg = img;
		}
		mo.parentNode.insertBefore(mi.substImg, mo);
	}
	if (mi.detach && !mi.parentNode) {
		mi.parentNode = mo.parentNode;
		mi.nextSibling = mo.nextSibling;
		mo.parentNode.removeChild(mo);
		SS.getBody().appendChild(mo);
	}

	mo.style.position = 'absolute';
	mo.style.left = (reset ? mi.origpos.left : mi.pos.left) + 'px';
	mo.style.top  = (reset ? mi.origpos.top  : mi.pos.top ) + 'px';
}
SS.listen(document, 'mouseup', function() {
	var mi = moveinfo;
	if (mi) {
		if (mi.started) {
			mi.stopping = true;
			setTimeout(function() {
				if (!moveinfo) {
					return;
				}
				if (moveinfo.capture && moveinfo.capture.releaseCapture) {
					moveinfo.capture.releaseCapture();
				}
				moveinfo.stopping = false;
				moveinfo = null;
			}, 1)
			return;
		}

		if (mi.canToggle) {
			var mo = mi.target;
			if (mo.style.position == 'absolute') {
				MoveToggleIn(mi);
			}
			else {
				MoveToggleOut(mi);
			}
		}
		moveinfo = null;
	}
});
SS.listen(document, 'dragstart', function() {
	if (moveinfo) {
		return false;
	}
});
SS.listen(document, 'click', function() {
	if (moveinfo && moveinfo.stopping) {
		return false;
	}
});

function GetAbsolutePosition(o)
{
	var ie = is.ie;

	var l = o.offsetLeft;
	var t = o.offsetTop;
	var p = o.offsetParent;

	while (p) {
		if (ie && p.tagName == "TD") {
			l += p.clientLeft;
			t += p.clientTop;
		}

		l += p.offsetLeft;
		t += p.offsetTop;
		p = p.offsetParent;
	}

	return {left: l, top: t};
}

scriptscomplete['floatwindow'] = true;

