/* 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 = 500;
  GB_WIDTH = 700;
  
  if(!GB_DONE) {
    $(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>"
        + "<div id='GB_loading'style='text-align: center;'><div style='height: 30px;'></div><img src='" + baseUrl + "images/loading.gif' /></div></div>");
    $(window).resize(GB_position);
    GB_DONE = true;
  }
  $("#GB_loading").show();
  $("#GB_frame").remove();
  $("#GB_window").append("<iframe id='GB_frame' src='' style='margin: 0px; padding: 0px; display: none;'></iframe>");
  $("#GB_frame").attr('src', url);
  $("#GB_caption").html('<b>' + caption + '</b>&nbsp;(* Champs obligatoires)');
  $("#GB_overlay").show();
  GB_position();

  $("#GB_window").show();
}

function GB_hide(reload) {
	if(reload)
		window.location = window.location;
	else
		$("#GB_window,#GB_overlay").hide();
}

function GB_position(width, height) {
	GB_HEIGHT = height || GB_HEIGHT;
	GB_WIDTH = width || GB_WIDTH;
	
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	
	$("#GB_window").css({width:GB_WIDTH+"px",height:(GB_HEIGHT - 20)+"px",
	left: ((w - GB_WIDTH)/2)+"px" });
	$("#GB_frame").css("height",(GB_HEIGHT - 38) +"px");
}

