/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * Modified by Nate Tanner
 * License: LGPL (read more in LGPL.txt)
 */

var GB_DONE = false;
var GB_HEIGHT = 99;
var GB_WIDTH = 99;

function GB_show(caption, url, height, width) {
  GB_HEIGHT = height || 99;
  GB_WIDTH = width || 99;
  if(!GB_DONE) {
    $(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>"
        + "<img src='/scripts/greybox/close.gif' alt='Close window'/></div>");
    $("#GB_window img").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    $(window).resize(GB_position);
 
    GB_DONE = true;
  }

  $("#GB_frame").remove();
  $("#GB_window").append("<iframe id='GB_frame' style='display:none' src='"+url+"'></iframe>");
  /* added style display none to hide elements showing then disapearing and displaying the container when all the appropriate elememts have turned off. */

  $("#GB_caption").html(caption);
  $("#GB_overlay").show();
  GB_position();

/* Shift the contents of the frame left and up to hide the navigation elements of the page */ 
var myFrame = $('#GB_frame');
myFrame.load(function(){
myFrame.contents().find('#wrapper').css({"margin":"0 0 0 -180px","background-position":"0 0", "border":"none"});
myFrame.contents().find('#header').css({"display":"none"});
myFrame.contents().find('#footer').css({"display":"none"});
myFrame.contents().find('#breadcrumb').css({"display":"none"});
myFrame.contents().find('body').css({"background":"#FFF"});
myFrame.css({"display":"block"});
/*myFrame.contents().find('#wrapper').css({"background-position":"0 0"});*/
}); 

  if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();
}

function GB_hide() {
  $("#GB_window,#GB_overlay").hide();
}

function GB_position() {
  var de = document.documentElement;
  var docw = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  $("#GB_window").css({'width':'803px','height':'90%','left': '5%'});
  var wh = $("#GB_window").height();
    var ww = $("#GB_window").width();
	$("#GB_frame").css("height",wh - 20 +"px");
  $("#GB_window").css({'left': ((docw - ww)/2)+'px'});
}
