//============================================================
// Masterplan JavaScript
//============================================================

//    ________________________________________________________________
//   |/              Web Application Development
//   |\nowmad        http://www.knowmad.com/
//    /ervices Inc   Copyright (c) 2004 - 2005
//    ________________________________________________________________


// UPDATE THIS LIST AS NEW DIV'S ARE ADDED IF hide() FUNCTION IS BEING USED
var aElements = new Array( 'village', 'resort', 'chapel', 'townhomes' );

var speed = 500; // wait time
var t; // timer object

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var isIE = document.all?true:false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!isIE) document.captureEvents(Event.MOUSEMOVE);

function show(obj, x, y) {
  //alert("show\nobj = " + obj + "\nx = " + x + "\ny = " + y);
  clearTimer();
  if (document.getElementById) {
    //if (document.getElementById(obj).style.visibility != 'visible') {
      if (x) {
        //alert("x is set to " + x);
        t = setTimeout('show_info("' + obj + '", "' + x + '", ' + y + ')', speed);
      }
      else {
        t = setTimeout('show_info("' + obj + '")', speed);
      }
    //}
  }
}


function show_info(obj, x, y) {
  if (document.getElementById) { // DOM3 = IE5, NS6
    var panel = document.getElementById(obj);
    //alert ("panel = " + panel);

    // Hide any other windows
    //hide();

    // Set the z-index - uses Walter Zorn's Drag & Drop library
    //dd.elements(obj).maximizeZ();
    //alert ('zIndex = ' + panel.style.zindex);
    maketop(obj);

    // Bail out if object is already on screen
    if (panel.style.visibility == 'visible') return;

    // Make the panel visible
    var scrollTop = document.documentElement.scrollTop;
    //alert("scrollTop = " + scrollTop);

    // Position the object
    if (x) {
      if (y == null || y.NaN) y = 0;
      switch (x) {
      case 'topleft':
        // Position the image at the top left of page
        x = 10;
        if (scrollTop <= 25) {
          y = y + 25;
        }
        y = y + 5;
        //alert (" x = " + x);
        panel.style.left = x + 'px';
        //alert (" y = " + y);
        panel.style.top = y + scrollTop + 'px';
        break;

      case 'topright':
        // Position the image at the top right of page
        //alert ("X = " + x + "\nY = " + y + "\navailWidth = " + screen.availWidth + "\navailHeight= " + screen.availHeight);
        y = 0;
        if (scrollTop <= 25) {
          y = 25;
        }
        y = y + 5;
        //x = screen.availWidth - popX;
        x = winW - popX;
        panel.style.left = x + 'px';
        panel.style.top = y + scrollTop + 'px';
        break;

      case 'bottomright':
        // Position the image at the bottom right of page
        //y = screen.availHeight - popY;
        y = winH - popY;
        //x = screen.availWidth - popX;
        x = winW - popX;
        //alert ("X = " + x + "\nY = " + y + "\navailTop = " + screen.availTop + "\navailLeft = " + screen.availLeft);
        //alert ("X = " + x + "\nY = " + y + "\navailWidth = " + screen.availWidth + "\navailHeight= " + screen.availHeight);
        panel.style.left = x + 'px';
        panel.style.top = y + scrollTop + 'px';
        break;

      default:
        //alert ("x,y are set.\nX = " + x + "\nY = " + y);
        //alert ("BEFORE\nX = " + mouseX  + "\nY = " + mouseY + "\nscrollTop = " + document.documentElement.scrollTop + "\n P.top = " + panel.style.top + "\nP.left = " + panel.style.left);
        panel.style.left = x + 'px';
        // panel.style.top = y + scrollTop + 'px';
        panel.style.top = y + 'px';
      }
    }
    else {
      //alert ("BEFORE\nX = " + mouseX  + "\nY = " + mouseY + "\nscrollTop = " + document.documentElement.scrollTop + "\n P.top = " + panel.style.top + "\nP.left = " + panel.style.left);
      panel.style.left = mouseX + 'px';
      panel.style.top = mouseY  + scrollTop + 'px';
    }

    // Show the object
    panel.style.visibility = 'visible';
    //alert ("X = " + mouseX  + "\nY = " + mouseY + "\nP.left = " + panel.style.left + "\n P.top = " + panel.style.top );
  }
  else {
    alert("Sorry, this browser version is not supported.");
    //if (document.layers) { // Netscape 4
    //  document.visibility = 'visible';
    //}
    //else { // IE 4
    //  alert("Sorry, this browser version is not supported.");
    //  document.all.style.visibility = 'visible';
    //}
  }
}


function clearTimer() {
  clearTimeout(t);
}


// If obj is defined, close it. Else hide all div's.
// META: All elements must be defined in the aElements array
function hide(obj) {
  clearTimer();
  if (document.getElementById) { // DOM3 = IE5, NS6
    if (obj) {
      document.getElementById(obj).style.visibility = 'hidden';
    }
    else {
      for(i=0; i < aElements.length; i++) {
        var elem = aElements[i];
        //alert(elem);
        document.getElementById(elem).style.visibility = 'hidden';
      }
    }
  }
  else {
    alert("Sorry, this browser version is not supported.");
    //if (document.layers) { // Netscape 4
    //  document.fact_field.visibility = 'hidden';
    //}
    //else { // IE 4
    //  document.all.fact_field.style.visibility = 'hidden';
    //}
  }
}



//============================================================
//Capturing The Mouse Position in IE4-6 & NS4-6
//(C) 2000 www.CodeLifter.com
//Free for all users, but leave in this  header
//============================================================

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Variables to hold mouse x-y pos.s
var mouseX = 0
var mouseY = 0

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
  if (isIE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.documentElement.scrollLeft;
    mouseY = event.clientY + document.documentElement.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}
  return true
}


