function loadImage(url)
{
	var img = new Image();
	img.onload = onImgLoad;
	img.src = url;
}

function onImgLoad()
{
	//var imgLayer = document.getElementById("imageInline");
	//img.src = url;

	document.getElementById("loading").style.display = "none";
	var l = document.getElementById("imageContainer");
	l.style.width = this.width;
	l.style.height = this.height;
	var pImg = document.getElementById("pImage");
	pImg.src = this.src;
	previewToCenter();
	l.style.display = "block";
}

function openImage(url)
{
	//previewToCenter();
	loadToCenter();
	document.getElementById("overlay").style.display = "block";
	document.getElementById("overlay").style.width = getWindowWidth();
	document.getElementById("overlay").style.height = getWindowHeight();
	document.getElementById("imageContainer").style.display = "none";
	document.getElementById("loading").style.display = "block";
	loadImage(url);
}

function closeImage()
{
	document.getElementById("imageContainer").style.display = "none";
	document.getElementById("loading").style.display = "none";
	document.getElementById("overlay").style.display = "none";
}

function getWindowWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else
	{
		//for IE
		return document.body.clientWidth;
	}
}

function getWindowHeight()
{
	if (window.innerWidth)
	{
		return window.innerHeight;
	}
	else
	{
		//for IE
		return document.body.clientHeight;
	}
}

function loadToCenter()
{
	var l = document.getElementById("loading");
	l.style.left = Math.round(getWindowWidth()/2 - parseInt(l.style.width)/2);
	l.style.top = Math.round(getWindowHeight()/2 - parseInt(l.style.height)/2);
}

function imageContainerToCenter()
{
	var l = document.getElementById("imageContainer");
	l.style.left = Math.round(getWindowWidth()/2 - parseInt(l.style.width)/2);
	l.style.top = Math.round(getWindowHeight()/2 - parseInt(l.style.height)/2);
}

function previewToCenter()
{
	loadToCenter();
	imageContainerToCenter();
}