/* 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_WIDTH = 600;
var GB_HEIGHT = 500;

function GB_show(caption, url, width, height ) {
  GB_WIDTH = width || 600;
  GB_HEIGHT = height || 500;
  if(!GB_DONE) {
    $(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>"
        + "<img src='/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' src='"+url+"'></iframe>");

  $("#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_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  var t = (de&&de.scrollTop) || 0;
  $("#GB_window").css({width:GB_WIDTH+"px", height:GB_HEIGHT+"px", 
			left:((w - GB_WIDTH)/2)+"px", top:(t+30)+"px" });
  $("#GB_frame").css("height",(GB_HEIGHT+20) +"px");
}

var GB_ANIMATION = false; //true;
var GB_CX;
var GB_CY;
$(document).ready(function(){
$("a.greybox").click(function(){
var t = this.title || $(this).text() || this.href;
GB_CX = 560; GB_CY= 410;
var s_pos = t.indexOf( " size=" );
if ( s_pos > 0 )
{
	var s_size = t.substr( s_pos );
	t = t.substr( 0, s_pos );

	var x_pos = s_size.indexOf( "x" );
	if ( x_pos > 0 )
	{
		GB_CX = parseInt( s_size.substr( 6, x_pos -1 ) ) + 20;
		GB_CY = parseInt( s_size.substr( x_pos + 1 ) ) + 50;
	}
}
GB_show(t,this.href,GB_CX,GB_CY);
return false;
});
});
