/* 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 QV_DONE = false;
var QV_HEIGHT = 420;
var QV_WIDTH = 780;

function QV_show(caption, url, height, width) {
  QV_HEIGHT = height || 420;
  QV_WIDTH = width || 780;
  if(!QV_DONE) {
    jQuery(document.body)
      .append("<div id='QV_overlay'></div><div id='QV_window'>"
        + "</div>");
    jQuery("#QV_window p").click(QV_hide);
    jQuery("#QV_overlay").click(QV_hide);
    jQuery(window).resize(QV_position);
    QV_DONE = true;
  }

  jQuery("#QV_frame").remove();
  jQuery("#QV_window").append("<iframe frameborder='no' scrolling='no' id='QV_frame' src='"+url+"'></iframe>");

  jQuery("#QV_caption").html(caption);
  var docHeight = jQuery(document).height();
  jQuery("#QV_overlay").css({height: docHeight+"px"});
  jQuery("#QV_overlay").show();
  QV_position();

  jQuery("#QV_window").show();
}

function QV_hide() {
  jQuery("#QV_window,#QV_overlay").hide();
  //top.location.reload();
}

function QV_position() {
  var scrollTop = jQuery(window).scrollTop();
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  jQuery("#QV_window").css({width:QV_WIDTH+"px",height:QV_HEIGHT+"px",
    left: ((w - QV_WIDTH)/2)+"px" , top:122+scrollTop+"px"});
  jQuery("#QV_frame").css("height",QV_HEIGHT +"px");
  jQuery("#QV_frame").css("width",QV_WIDTH +"px");
}