//****************************************************************************************
//  Helper routines for floating windows
//****************************************************************************************

var isMozilla;
var DivID = "";
var objDiv = null;
var hover_over = false;

function displayFloatingDiv(divId, titleId, title, width, height, left, top, rclass)
{
	DivID = divId;

    document.getElementById(divId).style.width = width + 'px';
    document.getElementById(divId).style.height = height + 'px';
    document.getElementById(divId).style.left = left + 'px';
    document.getElementById(divId).style.top = top + 'px';

	document.getElementById(divId).className = rclass;
	document.getElementById(divId).style.visibility = "visible";

	document.getElementById(titleId).innerHTML = title;
}

function hideFloatingDiv(divId, rclass)
{
	var el = document.getElementById(divId);
	// el may not be on the form -  there is a better way
	if ( el )
	{
		el.className = rclass;
		el.style.visibility='hidden';
	}

	DivID = "";
	objDiv = null;
	hover_over = false;
}

function getScrollXY()
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
    	//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    	//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    	//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function mouse_up(e)
{
    objDiv = null;
}

function mouse_down(e)
{
    if (hover_over)
    {
    	if ( DivID != "")
    	{
	        if (isMozilla) {
	            objDiv = document.getElementById(DivID);
	            X = e.layerX;
	            Y = e.layerY;
	            return false;
	        }
	        else {
	            objDiv = document.getElementById(DivID);
	            objDiv = objDiv.style;
	            X = event.offsetX;
	            Y = event.offsetY;
	        }
        }
    }
}

function mouse_move(e)
{
    if (objDiv) {
        if (isMozilla) {
            objDiv.style.top = (e.pageY-Y) + 'px';
            objDiv.style.left = (e.pageX-X) + 'px';
            return false;
        }
        else
        {
            var XYScroll = getScrollXY();
            objDiv.pixelLeft = event.clientX-X + XYScroll[0];
            objDiv.pixelTop = event.clientY-Y + XYScroll[1];
            return false;
        }
    }
}

function moveWin_Init()
{
    // check browser
    isMozilla = (document.all) ? 0 : 1;

    if (isMozilla)
    {
        document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
    }

    document.onmousedown = mouse_down;
    document.onmousemove = mouse_move;
    document.onmouseup = mouse_up;
}


function displayFavWindow(windowId, favWindowId, width, height)
{
	var content_width = width - 20;
	var content_height = height - 45;

	var centerY = getScreenCenterY();
	var centerX = getScreenCenterX();
	var l = centerX - Math.round(width/2);
	var t = centerY - Math.round(height/2);

	hideFloatingDiv('map_window', 'mapWindowOff');
	displayFloatingDiv(windowId, 'favTitle', 'Favorite Listings', width, height, l, t, 'favWindowOn');
}

