/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */

var GB_DONE = false;
var GB_HEIGHT = 240;
var GB_WIDTH = 320;

function GB_show(caption, url, height, width) {
  GB_HEIGHT = height || 240;
  GB_WIDTH = width || 320;
  if(!GB_DONE) {
    jQuery(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>"
        + "<img src='images/close.gif' alt='Close window'/></div>");
    jQuery("#GB_window img").click(GB_hide);
    jQuery("#GB_overlay").click(GB_hide);
    jQuery(window).resize(GB_position);
    GB_DONE = true;
  }

  jQuery("#GB_frame").remove();
  jQuery("#GB_window").append("<iframe id='GB_frame' src='"+url+"'></iframe>");

  jQuery("#GB_caption").html(caption);
  jQuery("#GB_overlay").show();
  GB_position();

  if(GB_ANIMATION)
    jQuery("#GB_window").slideDown("slow");
  else
    jQuery("#GB_window").show();
}

function GB_hide() {
  jQuery("#GB_window,#GB_overlay").hide();
}

function GB_position() {

  var viewportwidth;
  var viewportheight;
  
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  
  if (typeof window.innerWidth != 'undefined')
  {
       viewportwidth = window.innerWidth,
       viewportheight = window.innerHeight
  }
  
 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

  else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth !=
      'undefined' && document.documentElement.clientWidth != 0)
  {
        viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight
  }
  
  // older versions of IE
  
  else
  {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
  }
  
  jQuery("#GB_window").css({position: "fixed", width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
    left: ((viewportwidth - GB_WIDTH)/2)+"px", top: ((viewportheight - GB_HEIGHT)/2)+"px" });
  jQuery("#GB_frame").css({height: GB_HEIGHT - 32 +"px",
    left: ((viewportwidth - GB_WIDTH)/2)+"px", top: ((viewportheight - GB_HEIGHT)/2)+"px" });
}

