/* 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_ANIMATION = true;
var GB_HEIGHT = 549;
var GB_WIDTH = 688;

function GB_show(caption, url, height, width) {
	try {
  GB_HEIGHT = height || 550;
  GB_WIDTH = width || 690;
  if(!GB_DONE) {
    $("body")
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>"
        + "<a href='#' class='GB_close' alt='Close window'>close</a></div>");
	
	//replace png with a black bg and opacity - P Schweiger
	$('#GB_overlay').css('opacity','0.8');

	//hide the select so it doesn't show up - P Schweiger
	$('#form_enter select').hide();
	
	
	if ($.browser)
    $("#GB_window .GB_close").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' frameborder='0' src='"+url+"'></iframe>");

  $("#GB_caption").html(caption);
  // $("#GB_overlay").show(); MOD TO FADE-IN JEFF HAMPTON
  // MOD BY JEFF HAMPTON - Must re-apply PNGFix on IE6
  if ($.browser.msie && $.browser.version <= 6 && $(document).pngFix)
  	$(document).pngFix();
	
	//hide the select so it doesn't show up - P Schweiger
	$('select').hide();
	
  $("#GB_overlay").fadeIn("fast");
  GB_position();

  if(GB_ANIMATION)
    // $("#GB_window").slideDown("slow"); MOD TO FADE - SLIDE LOOKS BAD
    $("#GB_window").fadeIn("slow");
  else
    $("#GB_window").show();
	} catch(e) {
		alert( e );
	}
}

function GB_hide() {
  // $("#GB_window,#GB_overlay").hide(); MOD TO FADEOUT
  $("#GB_window,#GB_overlay").fadeOut("normal");
  // $("#GB_frame").get(0).src = 'blank.html';
  
  	//Restore the hidden select - P Schweiger
	$('select').show();

}

function GB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	$("#GB_window").css({width:GB_WIDTH+"px"
		,height:GB_HEIGHT+"px"
		,left: ((w - GB_WIDTH)/2)+"px"
		,top: ((h-GB_HEIGHT - 47)/2) +"px" // MOD by JH - CENTER-ISH Vertically
	 });
  $("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
}
