var flashContainer = 0;

function findPos(obj) {
	
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}


function removeBlock(elementID){
	
	$('myBodd').removeBlock($(elementID));
}


function buildTab(posx,posy,tabName,containerName, contentText, tabText){
//builds side tab if a text named yyyymmdd.txt is present in the content directory
	
	var d = document.createElement("div");
	d.className = "nznlTab";
	d.id = tabName;
	
	d.style.position = "absolute";
	d.style.top = posx + "px";
	d.style.left = (posy - 11) + "px";
	
	var t = document.createElement("img");
	t.src = "_img/nznl_tab-" + tabText + ".gif";
	t.border = "0";
	t.height = "45";
	t.width = "11";
	var a = document.createElement("a");
	a.title = "Click here to expand the text block. Click again to close";
	

	var i = 0;
	a.onclick = function(){
		if (i == 0){
		buildBlock((posx - 9),posy,containerName,contentText);
		}
		
		i += 1;
		
		if(i % 2 == 1){	
		Effect.SlideRightIntoView(containerName);
		if(flashContainer == 1)	{
			$('contentContainer').style.visibility = "hidden";
		}
		}else{
		Effect.SlideRightOutOfView(containerName);
		if(flashContainer == 1)	{
			setTimeout("$('contentContainer').style.visibility = \"visible\"",1000);
		}
		
		}
		};
	a.appendChild(t);
	d.appendChild(a);


	$('myBodd').appendChild(d);
	
	
	
}




function buildBlock(posx,posy,containerName,contentText){
//Builds a text block; depends on prototype

	if(!$(containerName)){
		
		
		var d = document.createElement("div");
		d.className = "contentText";
		d.id = containerName;
		d.style.position = "absolute";
		d.style.top = posx + "px";
		d.style.left = posy + "px";
		
		
		var textContainer = document.createElement("div");
		textContainer.className = "myTextContainer";
		
		d.appendChild(textContainer);
		textContainer.innerHTML = contentText.gsub(/\|/,'<br />');//change the pipe character into an HTML break
		$('myBodd').appendChild(d);
		
		
	}else{
		
		$('myBodd').removeChild($(containerName));
	}
	
}

function buildFlashHTML(myFile, xpos, ypos) {
if(!$('flashContainer')){	
	var a = document.createElement("div");
	a.id = "flashContainer";
	a.className = "flashContainer";
	
	a.style.top = ypos + "px";
	a.style.left = xpos + "px";
	
	var closeLinkContainer = document.createElement("div");
	closeLinkContainer.className = "closeLinkContainer";
	
	var closeLink = document.createElement("a");
	closeLink.href="javascript:buildFlashHTML()";
	closeLink.title = "Close";
	
	var i = document.createElement("img");
	i.src = "_img/icon_close.gif";
	i.border = "0";
	closeLink.appendChild(i);	
	closeLinkContainer.appendChild(closeLink);
	a.appendChild(closeLinkContainer);

	$('myBodd').appendChild(a);
	
	var ufoShell = document.createElement("div");
	ufoShell.id = "ufoShell";
	$("flashContainer").appendChild(ufoShell);
	
	var FO = { movie:"geert/swf/" + myFile + ".swf", width:"841", height:"594", majorversion:"8", build:"0", xi:"false" };
	UFO.create(FO, "ufoShell");
	
	
	}else{
		$('myBodd').removeChild($('flashContainer'));
	}
}
