/*
	@description: display a bigger version of the images that are used as a thumbnail in articles
	@author:		k.kuplen@netconomy.net
*/


function displayBigImage(popupImgSrc, imgWidth, imgHeight, srcObject) {

	// image div that is filled with the image src
	var displayElement = document.getElementById("popupImage");
	
	// div element to be filled with text belonging to the image
	var displayTextElement = document.getElementById("popupImageText")
		
	// empty previous texts;
	for (var i=0; i < displayTextElement.childNodes.length; i++) {
		displayTextElement.removeChild(displayTextElement.childNodes[i])
	}
		
	// browser-dependent finding of the element that holds the text 
	// this id done by climbing trough the DOM Tree
	var currtxt ;
	var myText = ""
	if(document.all) {
		if (srcObject.parentNode.nodeName.toUpperCase() == "DIV") {
			currtxt = srcObject.parentNode.nextSibling.cloneNode(true);
		} else 	if (srcObject.parentNode.parentNode.nodeName.toUpperCase() == "DIV") {
			currtxt = srcObject.parentNode.parentNode.nextSibling.cloneNode(true);		
		}
	} else {
		if (srcObject.parentNode.nodeName.toUpperCase() == "DIV") {
			currtxt = srcObject.parentNode.nextSibling;
		} else if (srcObject.parentNode.parentNode.nodeName.toUpperCase() == "DIV") {
			currtxt = srcObject.parentNode.parentNode.nextSibling;
		}
	}

	
	// setting styles attributes for the image
	displayElement.src = popupImgSrc;
	displayElement.style.width = imgWidth;
	displayElement.style.height = imgHeight;
	
	// browser depending gathering of position data
	if(document.all) {
		// offsetLeft has to be added together in internet explorer
		var ieTop = srcObject.offsetTop + srcObject.parentNode.parentNode.offsetTop ;
		displayElement.parentNode.style.top  = ieTop   + "px";
		displayElement.parentNode.style.left = (540  - imgWidth) + "px";
	} else if (document.getElementById) {
		displayElement.parentNode.style.top  = Math.round(srcObject.offsetTop / 2 ) + "px";
		displayElement.parentNode.style.left = ( 540  - imgWidth)  + "px";
	}
	
	// styles for the text div
	displayTextElement.style.width = (imgWidth -10) + "px";			
	
	// check if there is text to display
	
	var tmpContainer = document.createElement("div")
	tmpContainer.innerHTML = currtxt.innerHTML;
	
	displayTextElement.appendChild(tmpContainer);
	
	var textHeight = 0;
	var tmpText = displayTextElement.innerHTML;
	
	// getting rid of included html code
	tmpText = tmpText.replace(/<(\/)*[^>]+>/g, ""); 
	
	// check if its a valid text to display - that is other things than whitespace
	if (tmpText.replace(/\s/g,"") == "" ) {
		tmpText = ""
	} else {
		tmpText = tmpText.replace(/\r|\n|\t/g, ""); // strip unneeded whitespace
	}
	
	// guess a matching height based on the length of the text 
	if (tmpText.length > 0) {
		textHeight = ( (Math.ceil(tmpText.length / 30) * 11)  + 10  );
		//client.userCssTextsize: undefined

		
	}
	
	displayTextElement.style.height =  textHeight + "px"
	
	if (textHeight == 0) {
		// no text -  no padding
		displayTextElement.style.paddingBottom = "0px";
		displayTextElement.style.paddingTop = "0px";
		displayTextElement.style.margin = "0px";
	} else {
		// no text -> create some whitespace
		displayTextElement.style.paddingBottom = "5px";
		displayTextElement.style.paddingTop = "5px";
	}
	
	// display the div that contains the image and the text
	displayElement.parentNode.style.display = "block";
	
}


function hideBigImage() {
	document.getElementById("articleBigImageDisplay").style.display="none";
}

