﻿function showDetail (srcElement, fileName)
{
	var params = 'FileName=' + fileName;
			
	xhr.sendRequest(srcElement, endShowDetail, 'imagedatabase.aspx', params, xhr.requestTypes.POST);	
}

function endShowDetail(xmlHttpRequest, srcElement)
{
	if (xmlHttpRequest == null)
		return;
	
	if (xmlHttpRequest.status == 0)
		return;
		
	if (xmlHttpRequest.status != 200 && xmlHttpRequest.status != 304)
		alert("AJAX error " + xmlHttpRequest.status);
		
	var data = xmlHttpRequest.responseXML;

	var images = data ? data.documentElement.getElementsByTagName("Image") : null;

	if (images && images.length)
	{		
		var information = images[0];
		
		var layout = parseInt(information.getAttribute('Width')) < parseInt(information.getAttribute('Height')) ? 'layout2' : 'layout1';

		var detailControl = document.getElementById('detailImageControl');	
	
		if (!detailControl)
		{
			detailControl = document.createElement('div');
			detailControl.id = 'detailImageControl';
			detailControl.style.display = 'none';
			document.body.appendChild(detailControl);
		}
		else
		{
			detailControl.style.display = 'none';	
			while (detailControl.hasChildNodes())
				detailControl.removeChild(detailControl.firstChild);
		}
		
		var width = 425;
		var heigth = 415;
				
		detailControl.style.top = offsetCalculator.absoluteTop(srcElement) + 'px';
		
		if (srcElement.className == 'Left')
			detailControl.style.left = offsetCalculator.absoluteLeft(srcElement) + 'px';
		else
			detailControl.style.left = (offsetCalculator.absoluteLeft(srcElement) - width + srcElement.offsetWidth) + 'px';
		
		var h1 = detailControl.appendChild(document.createElement('h1'));
		var image = h1.appendChild(document.createElement('img'));
		image.src = '/textimage.aspx?c=f8d20f&amp;bc=006599&amp;s=16&amp;x=' + information.getAttribute('Title');
		image.alt = information.getAttribute('Alt');
		
		image = detailControl.appendChild(document.createElement('img'));	
		image.src = information.getAttribute('FileName');
		
		if(layout == 'layout2')
		{
			image.style.styleFloat = image.style.cssFloat = 'left';			
			image.style.marginRight = '5px';
			width += 75;
			detailControl.style.width = width + 'px';
		}
		
		var p = detailControl.appendChild(document.createElement('p'));
		p.appendChild(document.createTextNode(information.getAttribute('Text')));
		
		p = detailControl.appendChild(document.createElement('p'));
		p.appendChild(document.createTextNode('Foto: ' + information.getAttribute('Photographer')));
		p.className = 'Photographer';
		
		p = detailControl.appendChild(document.createElement('p'));
		p.className = 'Close';		
		
		image = p.appendChild(document.createElement('img'));
		image.className = 'Button';
		image.onclick = new Function ("this.parentNode.parentNode.style.display = 'none'; return false;");		
		image.src = '/buttonimage.aspx?c=000&amp;bc=006599&amp;s=12&amp;x=Fenster schließen ›';
		image.alt = 'Fenster schließen ›';
		
		detailControl.style.width = width + 'px';
		//detailControl.style.heigth = heigth + 'px';
		
		detailControl.style.display = 'block';
	}
}
