/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Modified by: James Laver - http://www.jameslaver.com/
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL
 */

var GB_HEIGHT = 400;
var GB_WIDTH = 400;

function GB_show(caption, mode, content, height, width, prev, next, method) {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  $(document.body)
    .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>");
  $("#GB_window img").click(GB_hide);
  $("#GB_overlay").click(GB_hide);
  $(window).resize(GB_position);
  $("#GB_frame, #GB_prev, #GB_next, #GB_close").remove();
  GBwin = $(document.createElement('img'));
  GBwin.attr('id','GB_close').attr('src','/img/close.gif').attr('alt','Close window').click(function(){GB_hide();});
  $('#GB_window').append(GBwin);
  //Added stick-me-in content support
  var gbframe;
  if(mode=='url')
  {
    gbframe = $(document.createElement('div'));
    gbframe.attr('id','GB_frame')
    $.get(content, function(data)
    {
      gbframe.html(data);
    });
  }
  else
  {
    gbframe = $(document.createElement('div'));
    gbframe.attr('id','GB_frame').html(content);
  }
  $("#GB_window").append(gbframe);
	gbfooter = $(document.createElement('div'));
	gbfooter.attr('id','GB_footer').html(content);  
  $("#GB_window").append(gbframe);	
  if (prev){
    var prevElem = $(document.createElement('img'));
	  prevElem.attr("src","/img/prevBtnWhite.jpg").attr("id","GB_prev").attr("style","cursor:pointer").click(function(){GB_hide(); method(prev);});	  
    $('#GB_window').append(prevElem);
  }
  if (next){
	  var nextElem = $(document.createElement('img'));
	  nextElem.attr("src","/img/nextBtnWhite.jpg").attr("id","GB_next").attr("style","cursor:pointer").click(function(){GB_hide(); method(next);});	  
    $('#GB_window').append(nextElem);
  }
  $("#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").remove();
}

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:((document.body.clientWidth-898)/2)+149+"px" });
}
