// -------------------------------------------------------------------------------//
// SHOW LIGHTBOX															      //
// -------------------------------------------------------------------------------//
var bodyID;
var holder;
var overlay;
var box;
var boxContent;
var contentHolderWidth;
var contentHolderHeight;
var contentInnerHeight;
var offsetMarginTop;
var offsetMarginLeft;
var newContentHolderWidth;
var newContentHolderHeight;
	
function displayLightbox(message) {
	if(navigator.userAgent.indexOf("MSIE 6") > 0 || navigator.userAgent.indexOf("MSIE 7") > 0)jQueryDetection('head').append('<link rel="stylesheet" href="http://www.i-studentgroup.com/includes/libs/css/i-studentgroup/lightbox-msie6.css" type="text/css" id="stylesheet" />');	
	if(document.body.style.display == "none") document.body.style.display = "block";
	holder = document.createElement('div');
	overlay = document.createElement('div');
	box = document.createElement('div');
	boxContent = document.createElement('div');
	bodyID = document.getElementsByTagName("body")[0];
	holder.setAttribute('id','lightbox');
	overlay.setAttribute('id','overlay');
	overlay.setAttribute('onclick','jQueryDetection("#lightbox").fadeOut("slow");');
	box.setAttribute('id','box');
	boxContent.setAttribute('id','boxContent');
	bodyID.insertBefore(holder, bodyID.firstChild);
	holder.appendChild(overlay);
	holder.appendChild(box);
	box.innerHTML = '<div id="hover" onclick=\'jQueryDetection("#lightbox").fadeOut("slow");\'><img width="30" height="30" onmouseover="this.style.cursor = \'pointer\';this.style.cursor=\'hand\'" alt="Lightbox Close Button" class="lightbox-close" src="http://www.i-studentgroup.com/includes/libs/images/close-button.png" /><img width="30" height="30" onmouseover="this.style.cursor = \'pointer\';this.style.cursor=\'hand\'" alt="Lightbox Close Button" class="lightbox-close-over" src="http://www.i-studentgroup.com/includes/libs/images/close-button-over.png" /></div>';
	box.appendChild(boxContent);
	boxContent.innerHTML = message;
	jQueryDetection("#lightbox").fadeIn("slow");
	box.style.marginTop = (-1*(box.offsetHeight/2))+"px";
	box.style.marginLeft = (-1*(box.offsetWidth/2))+"px";
	if(navigator.userAgent.indexOf("MSIE 6") > 0) pngfix();
}

function swapLightboxContent(newContent,fixedHeight){
	if(document.body.style.display == "none") document.body.style.display = "block";
	var contentHolder = jQueryDetection("#box");
	jQueryDetection("#box").css("height","auto");
	contentInnerHeight = contentHolder.height();
	 
	contentHolderWidth = jQueryDetection("#box").outerWidth();
	contentHolderHeight = jQueryDetection("#box").outerHeight();
	
	jQueryDetection("#box").append("<div id='newBoxContent'>"+newContent+"</div>");
	jQueryDetection("#boxContent").hide();
	
	newContentHolderWidth = jQueryDetection("#box").width();
	newContentHolderHeight = fixedHeight != null ? fixedHeight : jQueryDetection("#box").height();
	offsetMarginLeft = ((jQueryDetection("#box").outerWidth()/2)*-1)+"px";
	offsetMarginTop = ((jQueryDetection("#box").outerHeight()/2)*-1)+"px";
	jQueryDetection("#boxContent").show();
	jQueryDetection("#newBoxContent").hide();
	
	var animateObj = {
		width: newContentHolderWidth,
		height: newContentHolderHeight,
		marginTop: offsetMarginTop,
		marginLeft: offsetMarginLeft		
	}
				
	jQueryDetection("#boxContent").fadeOut("slow",
		function(){
			jQueryDetection("#box").css("height",contentInnerHeight);
			jQueryDetection("#box").animate(animateObj, "slow",
				function(){
					jQueryDetection("#newBoxContent").fadeIn("slow",
						function(){
							jQueryDetection("#boxContent").attr("id","oldContent");
							jQueryDetection("#newBoxContent").attr("id","boxContent");
							jQueryDetection("#oldContent").remove();
						}
					);
				}
			).css("overflow","visible");
		}
	);
}

function fitLightboxToContent(){
	if(document.body.style.display == "none") document.body.style.display = "block";
	var boxWidth = jQueryDetection("#boxContent").outerWidth();
	
	var origBoxHeight = jQueryDetection("#box").height();
	jQueryDetection("#box").css("height","auto");
	var newBoxHeight = jQueryDetection("#box").height();
	var leftMargin = ((jQueryDetection("#box").outerWidth()/2)*-1)+"px";
	var topMargin = ((jQueryDetection("#box").outerHeight()/2)*-1)+"px";
	jQueryDetection("#box").css("height",origBoxHeight);
	
	
	var animateObj = {
		width: boxWidth,
		height: newBoxHeight,
		marginLeft: leftMargin,
		marginTop: topMargin
	}
	
	jQueryDetection("#box").animate(animateObj, "slow", function(){jQueryDetection("#box").css("height","auto");}).css("overflow","visible");
}
