//Common Settings
var LightboxHTMLWidth = 550;
var LightboxHTMLHeight = 450;

var LightboxImageWidth = 550;
var LightboxImageHeight = 450;

var LightboxHeight = LightboxHTMLHeight;
var LightboxWidth = LightboxHTMLWidth;

function ___getPageSize(){
	var xScroll,yScroll;
	if(window.innerHeight&&window.scrollMaxY){
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}else if(document.body.scrollHeight>document.body.offsetHeight){
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}

	var windowWidth,windowHeight;
	if(self.innerHeight){
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}else{
			windowWidth=self.innerWidth;
		}
		
		windowHeight=self.innerHeight;
	}else if(document.documentElement&&document.documentElement.clientHeight){
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}else if(document.body){
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	
	
	if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
	if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

//Create Lightbox
document.write('<div id="xi-fader"></div>');
document.write('<div id="xi-lightbox"><table border="0" cellspacing="0" cellpadding="0" align="center" id="xi-lightbox-window"><tr><td>');
document.write('<a href="javascript:CloseLightbox();" style="position:relative; float:left; margin-left:-5px; margin-top:-5px; margin-bottom: -40px;"><img src="js/images/closecircle.png" width="30" height="30" border="0"></a></td></tr><tr><td>');
document.write('<div id="xi-lightbox-frame" style="height:'+LightboxHTMLHeight+'; width: '+LightboxHTMLWidth+'"></div>');
document.write('</td></tr></table></div>');


//Framework Functions
$(document).ready(function(){

var arrPageSizes=___getPageSize();
$('#xi-fader').css({width:arrPageSizes[0],height:arrPageSizes[1]});
$("#xi-fader").animate({opacity: 0}, 1);
$("#xi-lightbox").animate({opacity: 0}, 1);

xiTimer();

//HTML Lightbox
$(".lightbox-html").click(function () {
	CreateLightbox('HTML');
		$("#xi-lightbox-frame").load(this.href);
	ShowLightbox();
	return false;
});

//Image Lightbox
$("a.lightbox-image").click(function () {	 
	CreateLightbox('Image');
		var lightboximage = document.getElementById("lightbox-picture");
		lightboximage.src=this.href;
	ShowLightbox();
	return false;
});

});

//On Change window size
$(window).resize(function(){
	var arrPageSizes=___getPageSize();
	$('#xi-fader').css({width:arrPageSizes[0],height:arrPageSizes[1]});
});

//Show/Hide Divs
function display_div(div_id)
{
	$("#"+div_id).fadeIn(200);
}
function hide_div(div_id)
{
	$("#"+div_id).fadeOut(200);
}
//=====================Static Funcitons
//Align Lightbox
function LightBoxAlign()
{
	var CurrentPosH=document.body.scrollTop;
	document.getElementById('xi-fader').style.top = document.body.scrollTop;
	document.getElementById('xi-lightbox').style.top = document.body.clientHeight/2+document.body.scrollTop;
	document.getElementById('xi-lightbox').style.marginTop=((LightboxHTMLHeight+20)/2)*(-1);
}

function CreateLightbox(LightboxType)
{
	if(LightboxType == 'Image'){
		LightboxHeight = LightboxImageHeight;
		LightboxWidth = LightboxImageWidth;	
		document.getElementById("xi-lightbox-frame").style.overflow="hidden";
	}
	else{
		LightboxHeight = LightboxHTMLHeight;
		LightboxWidth = LightboxHTMLWidth;	
		document.getElementById("xi-lightbox-frame").style.overflow="hidden";
	}
	$("#xi-lightbox-frame").width(LightboxWidth);
	$("#xi-lightbox-frame").height(LightboxHeight);	
	LightBoxAlign();	
	document.getElementById('xi-fader').style.display="block";
	document.getElementById('xi-lightbox').style.display="block";
	var container = document.getElementById("xi-lightbox-frame");
	container.innerHTML = '<img src="images/spacer.gif" id="lightbox-picture" border="0" style="background-image:url(js/images/loading.gif); background-position: center; background-repeat:no-repeat; background-color:#000000;" width="100%"/>';
}
function ShowLightbox()
{
	$("#xi-fader").animate({opacity: 0.7}, 200, function(){
	$("#xi-lightbox").animate({opacity: 1}, 500)});	 
}

//CloseLightbox
function CloseLightbox()
{
	$("#xi-lightbox").animate({opacity: 0}, 500, function(){
	$("#xi-fader").animate({opacity: 0}, 500, function(){
			document.getElementById('xi-fader').style.display="none";
			document.getElementById('xi-lightbox').style.display="none";
		});
	})
}
//Timed Ecents (miliseconds)
function xiTimer()
{
	LightBoxAlign()
	Timer=setTimeout("xiTimer()",10);
}