// floatingwin.js Copyright (c) 2006-2009 by Visibility Works, Inc. - All Rights Reserved.
var titlebarid='titlebar';
var windowid='notice_window';

function floatingwininit()
{
	var tb = document.getElementById(titlebarid);
	tb.onmousedown = mouseDown;

	var mw = document.getElementById(windowid);
	mw.style.left = "370px";
	mw.style.top = "52px";

	if( floatingwin_chain ) {
		floatingwin_chain();
	}
}

var floatingwin_chain = window.onload;
window.onload = floatingwininit;

function mouseMoved(e)
{
        if (!e) var e = window.event;
		var obj = document.getElementById(windowid);

		movedX = e.clientX - downX;
		movedY = e.clientY - downY;
		obj.style.left = newX = Math.max( 0, objX + movedX ) + "px";
		obj.style.top = newY = Math.max( 0,  objY + movedY ) + "px";
		
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
}

function mouseUp(e)
{
        if (!e) var e = window.event;

		document.onmousemove = null;
		document.onmouseup = null;
		
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
}

function mouseDown(e)
{
        if (!e) var e = window.event;
		obj = (e.target) ? e.target : e.srcElement;
		if( obj.id != titlebarid ) { return; } 

		obj = document.getElementById(windowid);

		downX = e.clientX;
		downY = e.clientY;

		re = /(\d+)/;
		matches = re.exec( obj.style.left);
		objX = Number( matches[1] );
		matches = re.exec( obj.style.top );
		objY = Number( matches[1] );

		document.onmousemove = mouseMoved;
	    document.onmouseup = mouseUp;
		
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
}
