/* 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 = 400;
var GB_WIDTH = 400;
var jqueryLib = jQuery.noConflict();
function GB_show(caption, url, height, width) {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    jqueryLib(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>"
        + "<img src='close.gif' alt='Close window'/></div>");
    jqueryLib("#GB_window img").click(GB_hide);
    jqueryLib("#GB_overlay").click(GB_hide);
    jqueryLib(window).resize(GB_position);
    GB_DONE = true;
  }

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

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

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

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

function GB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  jqueryLib("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
    left: ((w - GB_WIDTH)/2)+"px" });
  jqueryLib("#GB_frame").css("height",GB_HEIGHT - 22 +"px");
  jqueryLib("#GB_frame").css("width",GB_WIDTH +"px");
  jqueryLib("#GB_frame").css("margin","0 auto");
  jqueryLib("#GB_frame").css("padding"," 0 0px");
  jqueryLib("#GB_frame").css("text-align","center");
  jqueryLib("#GB_frame").css("border","none");
        
}
