/* 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;

function gb_show(caption, url, height, width) {
  gb_HEIGHT = height || 400;
  gb_WIDTH = width || 400;
  if(!gb_DONE) {
    $(document.body)
      .append('<div id="gb_overlay"></div><div id="gb_window"><div id="gb_a"></div>'
        + '<a href="#" title="Close window"><img style="border:none;" src="plugins/grey_box/close_mod.gif" alt="Close window"/></a></div>');
    $("#gb_window img").click(gb_hide);
    $("#gb_window img").hover(gb_hover);
    $("#gb_overlay").click(gb_hide);
    $(window).resize(gb_position);
	gb_DONE = true;
  }

  $("#gb_frame").remove();
  $("#gb_window").append("<iframe frameborder='0' id='gb_frame' src='"+url+"'></iframe>");

  $("#gb_a").html(caption);
  $("#gb_overlay").show();
  gb_position();

  if(gb_ANIMATION)
    $("#gb_window").slideDown("slow");
  else
    $("#gb_window").show();
}

function gb_hover() {
	$("#gb_window img").mouseover(function () {
		$("#gb_window img").attr("src", "plugins/grey_box/close_mod_hov.gif")
	});
	$("#gb_window img").mouseout(function () {
		$("#gb_window img").attr("src", "plugins/grey_box/close_mod.gif")
	});
}
function gb_hide() {
  $("#gb_window,#gb_overlay").hide();
  return false;
}

function gb_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  $("#gb_window").css({width:gb_WIDTH+"px",height:gb_HEIGHT+"px",
    left: ((w - gb_WIDTH)/2)+"px" });
  
  $("#gb_frame").css("height",gb_HEIGHT - 32 +"px");
  $("#gb_frame").css("width",gb_WIDTH - 4 +"px");
}

