var myBackgroundStyle;
var myElement;
var myTimeout;


function getMarker(element)
{
  return element.getElementsByTagName('div')[0];
}


function getMarkerInfo(element)
{
  editMarker = getMarker(element)
  divs = element.getElementsByTagName('div')
  for (var i = 0; i < divs.length; i++) {
    if (divs[i].getAttribute('class') == 'marker_middle') {
      return divs[i];
    }
  }
  return null;
}


function reallyHide()
{
  window.clearTimeout(myTimeout);
  if (myElement) {
    getMarker(myElement).style.display = "none";
    myElement.style.backgroundColor = myBackgroundStyle;
    myElement = null;
  }
}


function displayMarker(element, evt)
{
  window.clearTimeout(myTimeout);
  if (myElement != element) {
    if (myElement) {
      reallyHide(myElement);
    }
    
    myElement = element;
    myBackgroundStyle = element.style.backgroundColor;
    element.style.backgroundColor = "#ccc";

    editmarker = getMarker(element);
    editmarker.style.left = evt.clientX - 20 + "px";
    editmarker.style.top = evt.clientY + 5 + "px";
    editmarker.style.display = "block";
  } 
}


function hideMarker()
{
  window.clearTimeout(myTimeout);
  myTimeout = window.setTimeout('reallyHide();', 2000);
}


function showMarkerInfo(element)
{
  markerInfo = getMarkerInfo(element);
  if (markerInfo.style.display == 'none') {
    markerInfo.style.display='block';
  } else {
    markerInfo.style.display='none';
  }
}
