/* 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;
var GB_footer_type = 'white';

function GB_show(caption, url, height, width, footer_type) {

	try {
  GB_HEIGHT = parseInt(height) || 400;
  GB_WIDTH = width || 400;
  GB_footer_type = footer_type || 'white';
	  $("#GB_window").remove();

$("body")
      .append("<div id='GB_overlay'></div><div id='GB_window' class='"+GB_footer_type+"'><div id='GB_caption'><div class='GB_close' onclick=\"parent.parent.GB_hide();\"></div></div><div id='GB_content'>"
        + "</div><div id='GB_"+GB_footer_type+"_footer_left'><div id='GB_footer_right'></div></div></div>");
    $(".GB_close").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    // $(window).resize(GB_position);

  $("#GB_frame").remove();
  $("#GB_content").html('');
	$.get(url, function(data) {
	  $("#GB_content").append(data)
	});

  //$("#GB_overlay").show();
  GB_position();

  if(GB_ANIMATION)
    $("#GB_window").slideDown("fast");
  else
    $("#GB_window").show();
	} catch(e) {	
	}
}

function GB_hide() {
  $("#GB_window").remove();
  $("#GB_overlay").remove();
}

function GB_position() {
	
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var myOverflow = '';
	if(parseInt(getWinVisibleHeight()*0.9) < GB_HEIGHT){
		$("#GB_window").css({width:GB_WIDTH+"px",height:parseInt(getWinVisibleHeight()*0.9)+"px",	left: ((w - GB_WIDTH)/3)+"px", overflow:'auto'});
		$("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
	} else {
		if (GB_footer_type == 'blue') {
			$("#GB_window").css({width:GB_WIDTH+"px",height:getWinVisibleHeight()*0.95+"px", top:10+"px", left: ((w - GB_WIDTH)/3)+"px"});
			$("#GB_frame").css("height",500 +"px");
		} else {
			$("#GB_window").css({width:GB_WIDTH+"px",height:(getWinVisibleHeight()*0.9)+"px", left: ((w - GB_WIDTH)/3)+"px"});
			$("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
		}
	};
}
