/* 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) {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    $jqnc(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>"
        + "<img src='/images/icons/close.gif' alt='Close window'/></div>");
    $jqnc("#GB_window img").click(GB_hide);
    $jqnc("#GB_overlay").click(GB_hide);
    $jqnc(window).resize(GB_position);
    GB_DONE = true;
  }

  $jqnc("#loginBox").remove();
  $jqnc("#GB_window").append("<div id=\"loginBox\" style=\"margin-left: 80px;\"><span style=\"font-size: 18px; font-weight: bold;\">Login</span><br /><br /><form name=\"loginForm\" id=\"loginForm\" action=\"\" method=\"post\"><div class=\"group\"><div class=\"label\">E-mail:</div><div class=\"input\"><input type=\"text\" name=\"email\" id=\"email\" value=\"\" class=\"formText\" /></div></div><div class=\"group\"><div class=\"label\">Password:</div><div class=\"input\"><input type=\"password\" name=\"password\" id=\"password\" value=\"\" class=\"formText\" /></div></div><div class=\"group\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Login\" class=\"formSubmit\" /></div></form></div>");

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

  if(GB_ANIMATION)
    $jqnc("#GB_window").slideDown("fast");
  else
    $jqnc("#GB_window").show();
  
  $jqnc("#email").focus();
}

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

function GB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  $jqnc("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
    left: ((w - GB_WIDTH)/2)+"px" });
  $jqnc("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
}
