var tidligerey		= 0;
var tidligerefull	= '';

function klikbar() {
	var elementer = document.getElementsByTagName('img');
	
	for(i=0;i<elementer.length;i++) {
		if (elementer[i].getAttribute('src').indexOf('_thumb.') > 0) {
			var thumb = elementer[i];
			
			thumb.setAttribute('alt','Vis billedet i stort');

			if (thumb.attachEvent)		setTimeout("document.getElementsByTagName('img')[" + i + "].attachEvent('onclick',function(e) { var func = klikbar_show(document.getElementsByTagName('img')[" + i + "].getAttribute('src')); if (!func) { if (e && e.preventDefault) e.preventDefault(); } return func; })",200);
			if (thumb.addEventListener)	setTimeout("document.getElementsByTagName('img')[" + i + "].addEventListener('click',function(e) { var func = klikbar_show(document.getElementsByTagName('img')[" + i + "].getAttribute('src')); if (!func) { if (e && e.preventDefault) e.preventDefault(); } return func; },false)",200);
		}
	}
}

function klikbar_show(url) {
	url = str_replace('_thumb.','_full.',url);
	
	klikbar_background(url);
	
	var container = document.createElement('div');
		container.setAttribute('id','image_container');
		
		container.style['position']			= 'absolute';
		container.style['left']				= '0px';
		container.style['top']				= getBody().scrollTop + 20 + 'px';
		container.style['width']			= '100%';
		container.style['textAlign']		= 'center';
		container.style['backgroundColor']	= 'transparent';
		
		var content = document.createElement('span');
			content.style['margin']				= '0px auto';
			content.style['backgroundColor']	= '#FFFFFF';
			
			var image = document.createElement('img');
				image.setAttribute('src',url);
				image.setAttribute('alt','Tryk for at lukke billedet');
				
				image.style['cursor']		= 'hand';
				
				image.onclick = klikbar_remove;
				
				content.appendChild(image);
			
			container.appendChild(content);
			
		document.body.appendChild(container);
		
	//setTimeout('klikbar_tilpas()',20);
}

function klikbar_remove() {
	//window.scrollTo(0,tidligerey);
	document.body.removeChild(document.getElementById('image_background'));
	document.body.removeChild(document.getElementById('image_container'));
}

function klikbar_background(url) {
	if (url == '') url = tidligerefull;
	
	tidligerey = getBody().scrollTop;
	
	var background = document.createElement('div');
		background.setAttribute('id','image_background');
		
		background.style['position']		= 'absolute';
		background.style['left']			= '0px';
		background.style['top']				= '0px';
		background.style['backgroundColor']	= '#000000';
		background.style['width']			= ((document.documentElement)? document.documentElement.scrollWidth : document.body.scrollWidth) + 'px';
		background.style['height']			= ((document.documentElement)? document.documentElement.scrollHeight : document.body.scrollHeight * 10) + 'px';
		background.style['filter']			= 'alpha(opacity=30)';
		background.style['opacity']			= '.3';
		
		background.onclick					= klikbar_remove;
		
	document.body.appendChild(background);
}

function klikbar_tilpas() {
	document.getElementById('image_background').style['width']	= document.body.scrollWidth + 'px';
	document.getElementById('image_background').style['height']	= document.body.scrollHeight * 2 + 25 + 'px';
}