/* 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_MODAL = 0;

function GB_show(caption, url, height, width, modal) {
GB_HEIGHT = height || 400;
GB_WIDTH = width || 400;
GB_MODAL = modal || 0;
if(!GB_DONE) {
	$(document.body).append("<div id='GB_overlay'></div><div id='GB_window'><img src='/images/overlay/close.png' alt='Close Window' class='closeWindow'/></div>");
	
	var bodyHeight = $("body").height() + 50;
	$("#GB_overlay").height(bodyHeight);
	
	$("#GB_window img").click(GB_hide);
	if (GB_MODAL == 0) {
		$("#GB_overlay").click(GB_hide);
	}
	$(window).resize(GB_position);
	
	GB_DONE = true;
}

$("#GB_frame").remove();
$("#GB_window").append("<iframe id='GB_frame' src='"+url+"' frameborder='0'></iframe>");

$("#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").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" 
	});
$("#GB_frame").css("height",GB_HEIGHT - 40 +"px");
}
function GB_resize(height, width) {
var de = document.documentElement;
var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
$("#GB_window").css(
	{
	width:width+"px",
	height:height+"px",
	left: ((w - width)/2)+"px" 
	});
$("#GB_frame").css("height",height - 40 +"px");
}

var GB_ANIMATION = true;
var RandSeed = 0
function createRandomString(p) {
var curdate = new Date();
return curdate.getTime() % Math.pow(2,p);
}
function getCacheString() {
randomString = createRandomString(16).toString() + "_" + createRandomString(32).toString() + "_" + createRandomString(24).toString() + "_" + createRandomString(48).toString();
return randomString;
}
$(document).ready(function(){
	$("a.overlay").click(function(){
	var t = "<img src='/images/nav/logo.png' class='windowTitle'/>";
	var loc = this.href + "?c=" + getCacheString();
	GB_show(t,loc,375,600,1);
	return false;
	});
});
