// whether or not a floating window is currently showing
var floatingShowing = false;



//------------------------------------------------------------------------------
// floatingToggle()
//
// Toggles the display of a floating window
function floatingToggle(div, show)
{
  // get the floating window and background
  var floatingbg = document.getElementById('floating-bg');
  var floating = document.getElementById(div);
  
  // make sure the window and background exist
  if (floating && floatingbg)
  {
    // show or hide the window
    if (show == true && !floatingShowing)
    {
      floatingbg.style.visibility = 'visible';
      floating.style.visibility = 'visible';
      floatingShowing = true;
    }
    else
    {
      floatingbg.style.visibility = 'hidden';
      floating.style.visibility = 'hidden';
      floatingShowing = false;
    }
  }
}



//------------------------------------------------------------------------------
// floatingAlert()
//
// Displays an alert in a generic floating window.
//
// pre:
// - page has a generic floating window <div id="floating-box">
// - floating window has elements <h1 id="floating-title"> and 
//   <p id="floating-content">
// post:
// - displays the floating window with the given title and message
// - if no window available, display an alert box
function floatingAlert(title, message)
{
  var genericWindow = document.getElementById('floating-box')
  
  // make sure the window exists
  if (genericWindow)
  {
    // set the content of the alert
    document.getElementById('floating-title').innerHTML = title;
    document.getElementById('floating-content').innerHTML = message;
    
    // display the alert
    floatingToggle('floating-box', true);
  }
  else
  {
    // window doesn't exist
    alert(message);
  }
}



//------------------------------------------------------------------------------
// floatingImage()
//
// Displays an image with the given filename in a generic floating window.
//
// pre:
// - page has a generic floating window <div id="floating-image-window">
// - floating window has <h1 id="floating-image-title"> and
//   <img id="floating-image">
// - PATH is set
// post:
// - displays the floating window with the given image
// - if no window available, do nothing
function floatingImage(filename, title)
{
  var genericWindow = document.getElementById('floating-image-window')
  
  // set the window title
  document.getElementById('floating-image-title').innerHTML = title;
  
  var img = document.getElementById('floating-image');
  
  // set the image source and alt text
  img.src = PATH + 'images/uploads/' + filename;
  img.alt = title;
  
  // display the alert
  floatingToggle('floating-image-window', true);
}
