/*
Lightbox for images
(c) 2008-2009 xul.fr
GPL license
*/


// height of current view for all browsers but IE

function viewHeight()
{
	if(window.innerHeight)return(window.innerHeight);
	if(document.documentElement && document.documentElement.clientHeight)
	return(document.documentElement.clientHeight);
	if(document.body) return(document.body.clientHeight);
	return 50;
}


function openbox(url)
{
	var box = document.getElementById('box');
	var filter =  document.getElementById('filter');
	document.getElementById('filter').style.display='block';

	var title = document.getElementById('boxtitle');
	//title.innerHTML = url;

	var content = document.getElementById('boxcontent');
	content.style.padding="0";

	ajax(url,'boxcontent');

	//	content.innerHTML = "...dynamic content...";
	//	content.innerHTML = url;
	//	content.innerHTML = "<img src=" + url + " />";

	if(navigator.appName.substring(0, 3) == "Mic")  // for IE
	{
		box.style.display='block';
		    x = document.documentElement.scrollTop + document.body.scrollTop +
		    box.offsetHeight / 4;
		//manually set top offset
		x=10;
		box.style.top = x + "px";
//		filter.style.top = document.documentElement.scrollTop + document.body.scrollTop;
	}
	else
	{
		box.style.display='block';
		    var top =  (viewHeight() - box.offsetHeight ) / 2;
		//manually set top offset
		top=10;
		box.style.top = top + 'px';
//		box.style.position='fixed'; // fixed does not work on IE
//		filter.style.position='fixed';
	}

}

/**
 * Opens box with explicitely inserted content (only shows lightbox with content in "boxcontent")
 * @param boxContent
 * @return
 */
function openboxBlank()
{
	var box = document.getElementById('box');
	var filter =  document.getElementById('filter');
	document.getElementById('filter').style.display='block';

	if(navigator.appName.substring(0, 3) == "Mic")  // for IE
	{
		box.style.display='block';
		    x = document.documentElement.scrollTop + document.body.scrollTop +
		    box.offsetHeight / 4;
		//manually set top offset
		x=10;
		box.style.top = x + "px";
//		filter.style.top = document.documentElement.scrollTop + document.body.scrollTop;
	}
	else
	{
		box.style.display='block';
		    var top =  (viewHeight() - box.offsetHeight ) / 2;
		//manually set top offset
		top=10;
		box.style.top = top + 'px';
//		box.style.position='fixed'; // fixed does not work on IE
//		filter.style.position='fixed';
	}

}

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){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function closebox()
{
	document.getElementById('box').style.display='none';
	document.getElementById('filter').style.display='none';
}

