/* 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, IFscroling) {
  
  if($.browser.msie) 
  {
    closetop = 20;
  }
  else
  {
 	closetop = 38;
  }


 IFscroling = IFscroling|| 'no';
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;



  $("#GB_frame").remove();
  $("#GB_IMGBOX").remove(); 
  $("#GB_caption2").remove(); 
  $("#GB_caption").remove(); 
  $("#GB_window").remove();
  $("#GB_overlay").remove();
  
    $(document.body).append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_close' style='top:"+closetop+"px;'></div>" + "</div>");
    $("#GB_close").click(GB_hide);
    $(window).resize(GB_position);


  $("#GB_window").append("<div id='GB_caption'></div><div id='maniBody' align='center'><iframe id='GB_frame' src='"+url+"' allowtransparency='true' scrolling='"+IFscroling+"' border='0' frameborder='0'></iframe></div>");
  $("#GB_caption").html(caption);
  $("#GB_overlay").show();
  GB_position();

  if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();
}

function GB_ImageBox(caption,ImgNum, url, height, width) {
  GB_HEIGHT = Math.floor(height)+84;
  GB_WIDTH = Math.floor(width)+15;
  
  if($.browser.msie) 
  {
    prevPadding = 65; 
    topPadding = 42;
    closetop = 50;
    rightPadd = 0;
  }
  else
  {
 	prevPadding = 85;
    topPadding = 60;
 	closetop = 38;
 	rightPadd = 43;

  }
  
    
  $("#GB_caption").remove();
  $("#GB_caption2").remove();
  $("#GB_frame").remove();
  $("#maniBody").remove();
  $("#GB_window").remove();
  $("#GB_overlay").remove();

  $(document.body).append("<div id='GB_overlay'></div><div id='GB_window'><p id='GB_close' style='top:"+closetop+"px;'></p><p id='GB_caption'></p>" + "</div>");
  $("#GB_close").click(GB_hide);
  $("#GB_overlay").click(GB_hide);
  $(window).resize(GB_position);
  
  $("#GB_window").append("<div id='GB_caption2'></div><div id='maniBody' align='center' style='border:0px;'><img id='GB_IMGBOX' src='"+url+"' width='"+width+"' height='"+height+"' border='0' onclick='NextImg("+ImgNum+")'><div style='position:relative;left:-"+(width-prevPadding)+"px;top:"+(height-topPadding)+"px;'><img src='greybox/img_prev.png' onclick='PrevImg("+ImgNum+")'></div><div style='position:relative;float:right;left:"+rightPadd+"px;top:"+(height-topPadding)+"px;margin-right:1px;'><img src='greybox/img_next.png' onclick='NextImg("+ImgNum+")'></div></div>");

  $("#GB_caption2").html(caption);
  $("#GB_overlay").show();
  GB_position();

  if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();
}

function NextImg(imgNum)
{
	var totalImgs = $(".thumViewer", "#AlbumImgs").length;
	//alert (imgNum);
	var nextIdNum = imgNum + 1;
	if (nextIdNum >= totalImgs) nextIdNum =0;
 	$(".thumViewer", "#AlbumImgs")[nextIdNum].onclick();
}

function PrevImg(imgNum)
{
	var totalImgs = $(".thumViewer", "#AlbumImgs").length;
	//alert (imgNum);
	var nextIdNum = imgNum - 1;
	if (nextIdNum < 0) nextIdNum =totalImgs-1;
 	$(".thumViewer", "#AlbumImgs")[nextIdNum].onclick();
}

function GB_hide() {
  $("#GB_frame").remove();
  $("#GB_window,#GB_overlay").hide();
}

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: ((w - GB_WIDTH)/2)+"px" ,
    top: (document.body.scrollTop+10)+"px" });
  $("#GB_overlay").css("height",Math.max(screen.height, document.body.scrollHeight) +"px");
  $("#GB_overlay").css("width",Math.max(screen.width, document.body.scrollWidth)-20 +"px");
  $("#GB_frame").css("height",GB_HEIGHT - 100 +"px");
  $("#GB_frame").css("width",GB_WIDTH- 58 +"px");
}

function GB_resize(NewH, NewW)
{
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  $("#GB_window").css({width:NewW+"px",height:NewH+"px",
    left: ((w - NewW)/2)+"px" ,
    top: (document.body.scrollTop+10)+"px" });
  $("#GB_overlay").css("height",Math.max(screen.height, document.body.scrollHeight) +"px");
  $("#GB_overlay").css("width",Math.max(screen.width, document.body.scrollWidth)-20 +"px");
  $("#GB_frame").css("height",NewH - 100 +"px");
  $("#GB_frame").css("width",NewW- 58 +"px");
}


