/* 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, param2) {
  if ( param2 === undefined ) param2 = 0;


  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  
  
  $("#GB_overlay").remove();
  $("#GB_window").remove();
  $("#GB_caption").remove();

    $(document.body).append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div><img src='images/pix.gif' alt='Close window'/ width=120 height=35 id='closegryimg'></div>");
        
        
	if (param2 == 0)
	{   
	$("#GB_window img").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    }
    else
    {
	$("#GB_window img").click(GB_hide2);
    $("#GB_overlay").click(GB_hide2);    
    }
    $(window).resize(GB_position);

  $("#GB_frame").remove();
  $("#BoxFooter").remove();
  $("#GB_window").append("<div id='maniBody' align='center'><iframe id='GB_frame'  name='GB_frame' src='"+url+"' allowtransparency='true' scrolling='no' border='0' frameborder='0'></iframe></div><div id='BoxFooter'></div>");

  $("#GB_caption").html(caption);
  $("#GB_overlay").show();
  GB_position();

  if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();
}


function GB_hide() {
      $("#GB_window,#GB_overlay").hide();
}

function GB_hide2() {
		res = 1;
		$('.optionClass', GB_frame.document).each(function() {
			if (this.value == -1)
			{
				res = 0;
				alert ("All options must be selected.");
			}
		});
		if (res == 1) $("#GB_window,#GB_overlay").hide();  
}

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" ,
    top: (document.body.scrollTop+10)+"px" });
  $("#GB_overlay").css("height",Math.max(screen.height, document.body.scrollHeight) +"px");
  $("#GB_overlay").css("width",Math.max(screen.width, document.body.scrollWidth) +"px");
  $("#GB_frame").css("height",GB_HEIGHT - 100 +"px");
  $("#GB_frame").css("width",GB_WIDTH- 58 +"px");
}

function GB_resize(NewH, NewW)
{
  
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  $("#GB_window").css({width:NewW+"px",height:NewH+"px",
    left: ((w - NewW)/2)+"px" ,
    top: (document.body.scrollTop+10)+"px" });
  $("#GB_overlay").css("height",Math.max(screen.height, document.body.scrollHeight) +"px");
  $("#GB_overlay").css("width",Math.max(screen.width, document.body.scrollWidth) +"px");
  $("#GB_frame").css("height",NewH - 100 +"px");
  $("#GB_frame").css("width",NewW- 58 +"px");
  
}

function overridHide()
{
GB_hide = function ()
{
alert ("HI");
};
}
