/* 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)
 * Updated by: Dan Holly Wells 1/5/09
 */

var GBS2_DONE = false;
var GBS2_HEIGHT = 400;
var GBS2_WIDTH = 400;
var GBS2_OPTIONS = {cssClass: "GBS2_default", modal: false};
var GBS2_ANIMATION = true;

function GBS2_show(caption, url, height, width, options) {
  options = options || GBS2_OPTIONS
  var cssClass = options.cssClass;
  var modal = options.modal;
  jQuery('html, body').animate({scrollTop:0}, 'fast'); 
  GBS2_HEIGHT = height || 400;
  GBS2_WIDTH = width || 400;  
  if(!GBS2_DONE) {
    close_link = '</div>';
    if(modal == true) {close_link = ''}
    jQuery("div#pageFrame")
      .append('<div id="GBS2_overlay" class="'+cssClass+'"></div><div id="GBS2_window" class="'+cssClass+'"><div id="GBS2_caption"></div>'
        + close_link);
    jQuery("#GBS2_window img").click(GBS2_hide);
    if (modal == false) {
      //jQuery("#GBS2_overlay").click(GBS2_hide);
    }
    jQuery(window).resize(GBS2_position);
    GBS2_DONE = true;
  }
  
  jQuery("#GBS2_frame").remove();
  jQuery("#GBS2_window").append("<iframe id='GBS2_frame' src='"+url+"' scrolling='no' frameBorder='0'></iframe>");

  jQuery("#GBS2_caption").html(caption);
  jQuery("#GBS2_overlay").css({height: 706+"px"});
  jQuery("#GBS2_overlay").css({width: 911+"px"});
  //jQuery("#GBS2_overlay").css({top: 261+"px"});
  //jQuery("#GBS2_overlay").css({left: 156+"px"});
  jQuery("#GBS2_overlay").show();
  GBS2_position();

  if(GBS2_ANIMATION)
    jQuery("#GBS2_window").slideDown("slow");
  else
    jQuery("#GBS2_window").show();
}


function GBS2_hide() {
  jQuery("#GBS2_window,#GBS2_overlay").hide();
}

function GBS2_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  jQuery("#GBS2_window").css({width:GBS2_WIDTH+"px",height:GBS2_HEIGHT+"px",
	left: 192+"px", top: 110+"px"});
	//left: ((w - GBS2_WIDTH)/2)+"px" });
  jQuery("#GBS2_frame").css("height",GBS2_HEIGHT +"px");
}
