

var black, white, iframe;
var menu_timeout = null;
var old_cemetery;


window.addEvent('domready', function() {
  black = document.createElement("DIV");
  black.id = "lightbox";
  black.className = "black_overlay";
  black.style.height = ( $('container').clientHeight + $('header').clientHeight + $('footer').clientHeight ) + "px";
  white = document.createElement("DIV");
  white.className = "white_content";
  white.id = "lightbox_insides";
  $('right').appendChild( black );
  $('right').appendChild( white );
  
  iframe = document.createElement("IFRAME");
  iframe.id = "lightbox_iframe";
  iframe.name = "lightbox_iframe";
  white.appendChild( iframe );
  
  if( $('cemetery_id') && $('cemetery_id').tagName.toString().toLowerCase() == "select" )
  {
    try {
      old_cemetery = $$('div[class$=cemetery_on]')[0];
    }
    catch(e) {
      old_cemetery = 0;
    };
    
    $('cemetery_id').addEvent('change', function() {
      if( this.selectedIndex == 0 )
        return;
      
      if( old_cemetery )
        old_cemetery.className = "cemetery_off";
      
      var cem = $('cemetery_' + this.options[ this.selectedIndex ].value );
      old_cemetery = cem;
      cem.className = "cemetery_on";
      cem.style.visibility = "hidden";
      setTimeout(function(){cem.style.visibility = "visible"}, 250);
    });
  }// end if()

  // Main nav pop-out menu:
  $('nav_death_records').addEvent('mouseover', function() {
    clearTimeout( menu_timeout );
    show_menu(this, $('cemetery_popup'));
  });
  $('nav_death_records').addEvent('mouseout', function() {
    menu_timeout = setTimeout(function() {
      hide_menu( $('cemetery_popup') );
    }, 1000);
  });

  $('cemetery_popup_a').addEvent('mouseover', function() {
    clearTimeout( menu_timeout );
  });
  $('cemetery_popup_a').addEvent('mouseout', function() {
  	menu_timeout = setTimeout(function() {
      hide_menu($('cemetery_popup'));
    }, 500);
  });

  $('obituary_popup_a').addEvent('mouseover', function() {
    clearTimeout( menu_timeout );
  });
  $('obituary_popup_a').addEvent('mouseout', function() {
  	menu_timeout = setTimeout(function() {
      hide_menu($('cemetery_popup'));
    }, 500);
  });

});


function show_lightbox()
{
  black.style.display = "block";
  white.style.display = "block";
  try {
    window.frames['lightbox_iframe'].document.body.innerHTML = "";
  }
  catch(e) {
    // Do nothing:
  }
  
  setTimeout(function() {
    $('lightbox_iframe').src = "/forms/lightbox.asp?record_type_id=" + record_type_id + "&state_id=" + state_id + "&county_id=" + county_id;
    $('lightbox_iframe').scrolling = "no";
    $('lightbox_iframe').frameBorder = "0";
  }, 10);
}// end show_lightbox()


function hide_lightbox()
{
  black.style.display = "none";
  white.style.display = "none";
}// end hide_lightbox()


function show_menu(who, menu)
{
  if( menu_timeout )
    clearTimeout(menu_timeout);

  menu.setStyle('display', 'block');
  var pos = who.getPosition(false);
  var size = who.getSize();
  var left = pos.x + size.x + 2;
  var top  = pos.y;
  menu.setPosition({ x: left, y: top });
}// end show_menu(who, menu)


function hide_menu(menu)
{
  menu.setStyle('display', 'none');
}// end hide_menu(menu)


