/* 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_HEIGHT = 400;
var GB_WIDTH = 400;

function GB_show(caption, url, width, height, type) {
	
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;

    $(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'></div>");
    $("#GB_window img").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    $(window).resize(GB_position);


  $("#GB_frame").remove();

  if(type == 'image')
  {
  	$("#GB_window").append("<img id='GB_frame' src='"+url+"' />");
  	//$("#GB_window").append("<iframe id='GB_frame' src='"+url+"'></iframe>");
  }
  else
  {
  	$("#GB_window").append("<iframe id='GB_frame' src='"+url+"'></iframe>");
  }

  $("#GB_frame").click(GB_hide);

  $("#GB_caption").html(caption);
  $("#GB_overlay").css("height", $(document).height().toString() +"px");
  $("#GB_overlay").show();
  GB_position();

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

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

function GB_position() 
{
	var top = (($(window).height() - GB_HEIGHT)/ 2) + $(document).scrollTop();
	if(top <= $(document).scrollTop()){ top = $(document).scrollTop() + 20}

	var w = $(window).width()
	var h = $(window).height()
	
	var win_height = parseInt(GB_HEIGHT);
		win_height = win_height.toString()
		
	var win_width = parseInt(GB_WIDTH)+6;
		win_width = win_width.toString()
  
	var frame_height = parseInt(GB_HEIGHT);
	frame_height = frame_height.toString()
	
	$("#GB_window").css({
		width: win_width+"px",
		height: win_height +"px",
		left: ((w - GB_WIDTH)/2)+"px",
		top: top.toString()+"px"
	});
  $("#GB_frame").css({
  		height: frame_height+"px"
});

}
