var contentHeight	= 100000000;
if(navigator.appName == "Microsoft Internet Explorer")
	var pageHeight	= document.documentElement.clientHeight;
else
	var pageHeight	= window.innerHeight;
var xmlhttp;
var start		= 0;
var active		= false;
var num			= 18;

function putImages()
{
	if(xmlhttp.readyState == 4 && xmlhttp.responseText)
	{
		var t = xmlhttp.responseText.split(";");
		
		var n=0;
		for(var i=0;i<t.length;++i)
		{
			if(t[i] != "")
			{
				document.getElementById("container").innerHTML += t[i];
				++n;
			}
		}
		
		if(n == num)	//Weniger als "num", also muss ich am Ende sein
			active = false;
		document.getElementById('loading').style.display = 'none';
	}
}

function scroll()
{
	if(!active)
	{
		if(navigator.appName == "Microsoft Internet Explorer")
			scrollPosition = document.documentElement.scrollTop;
		else
			scrollPosition = window.pageYOffset;
	
		if((contentHeight - pageHeight - scrollPosition) < 1000)
		{
			active = true;
			
			document.getElementById('loading').style.display = 'block';
		
			if(!xmlhttp)
			{
				if(window.XMLHttpRequest)
					xmlhttp = new XMLHttpRequest();
				else if(window.ActiveXObject)
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				else
					alert ("Bummer! Your browser does not support XMLHTTP!");
			}

			var url = "get.php5?start="+start+"&num="+num;

			xmlhttp.open("GET", url, true);
			xmlhttp.send();

			start += num;
			xmlhttp.onreadystatechange = putImages;
			contentHeight += (num / 6) * 160;
		}
	}
}

function img_in(id)
{
	var p = document.getElementById('img_'+id);
	var e = document.getElementById('exif_'+id);

	//e.style.top = (getH(p) - 22) + 'px';
	e.style.width = (p.width - 20) + 'px';
	e.style.display = 'block';
}

function img_out(id)
{
	var e = document.getElementById('exif_'+id);

	e.style.display = 'none';
}

function getH(e)
{
	var tp = e.offsetHeight;

	if(e.offsetParent)
	{
		do
		{
			tp += e.offsetTop;
		} while(e = e.offsetParent);
	}

	return tp;
}

function getL(e)
{
	var tp = e.offsetWidth;

	if(e.offsetParent)
	{
		do
		{
			tp += e.offsetLeft;
		} while(e = e.offsetParent);
	}

	return tp;
}

function cover()
{
	var t = document.getElementsByTagName('*');
	for(var i=0;i<t.length;++i)
	{
		if(t[i].className && t[i].className == 'cover')
		{
			var b = t[i].id.split("_");
			
			var p = document.getElementById('img_'+b[1]);
			var e = document.getElementById('cover_'+b[1]);
	
			e.style.top = (getH(p) - p.height + 2) + 'px';
			e.style.width = p.width + 'px';
			e.style.height = p.height + 'px';
			e.style.left = (getL(p) - p.width + 2) + 'px';
		}
	}
}

