var DOM = false;
var overDowns = false;
var staticDowns = false;
var tagDowns = 'downloads';

	
if (document.getElementById) {
  DOM = true;
}


// constructor
function Download(file, descript) {
	this.file = file;
	this.descript = descript;
}


// 
function createDownNode(download) {
	var nodeD = document.getElementById(tagDowns);
	var li = document.createElement("li");
	var a = document.createElement("a");
	var lName = document.createTextNode(' ' + download.descript);
	var img = document.createElement("img");

	nodeD.appendChild(li);
	li.appendChild(a);
	li.setAttribute("onmouseover", "expandDowns();");
	li.setAttribute("onmouseout", "collapseDowns();");
	li.setAttribute("onmousedown", "changeDownsStatic();");
	//li.className = "submenu";
	a.appendChild(img);
	a.appendChild(lName);
	a.setAttribute("href", pathDownloads + download.file);
	a.style.fontWeight = "normal";
	img.setAttribute("src", pdfSymbolSrc);
	img.setAttribute("width", pdfSymbolSize);
	img.setAttribute("height", pdfSymbolSize);
	img.setAttribute("border", 0);
}


function expandDowns() {
	if (!staticDowns) {
		if (document.getElementById(tagDowns).childNodes.length < 2) {
			for (var i=0; i < downloadList.length; i++) {
				createDownNode(downloadList[i]);
			}
		}
		overDowns = true;
		openNodeImg(false);
	}
}


function collapseDowns() {
	if (!staticDowns) {
		overDowns = false;
		window.setTimeout("deleteDownChilds()", 200);
	}
}


function deleteDownChilds() {
	var nodeD = document.getElementById(tagDowns);
	if (!overDowns) {
		while (nodeD.hasChildNodes()) {
			nodeD.removeChild(nodeD.firstChild);
		}
		openNodeImg(true);
	}
}


function openNodeImg(reverse) {
	var nodeD = document.getElementById(tagDowns);
	var nodeS = document.getElementById("nodeStatus");
	if (reverse) {
		nodeS.innerHTML = '+';
		nodeD.style.borderWidth = '0px';
	} else {
		nodeS.innerHTML = '&ndash;';
		nodeD.style.borderWidth = '1px';
	}
}


function changeDownsStatic() {
	expandDowns();
	staticDowns = !staticDowns;
	collapseDowns();
}


function dynamicDownloads(DOM) {
	var downloads = '';

	if (DOM) {
		downloads = 
			'<ul id="downarea" name="downarea">' + 
			'	<li onmouseover="expandDowns();" onmouseout="collapseDowns();" onmousedown="changeDownsStatic();">' +  
			'		&nbsp;<span id="nodeStatus" name="nodeStatus">+<\/span>&nbsp;Aktuelle Downloads' + 
			'	<\/li>' + 
			'	<ul id="downloads" name="downloads"><\/ul>' + 
			'<\/ul>';
	} else {
		var noDomList = ''; 
		for (var i=0; i < downloadList.length; i++) {
			noDomList += 
				'\t\t\t<li>' + 
				'\t\t\t\t<a href="'+pathDownloads+downloadList[i].file+'">' + 
				'\t\t\t\t\t<img src="'+pdfSymbolSrc+'" width="'+pdfSymbolSrc+'" height="'+pdfSymbolSrc+'" ' + 
									'border="0" \/>&nbsp;' + downloadList[i].descript + 
				'\t\t\t\t<\/a>' + 
				'\t\t\t<\/li>';
		}
		downloads = 
			'	<ul id="nodom_downarea" name="nodom_downarea">' + 
			'		<li>Aktuelle Downloads<\/li>' + 
			'		<ul id="nodom_downloads" name="nodom_downloads">' + 
						noDomList + 
			'		<\/ul>' + 
			'	<\/ul>';
	}
	document.write(downloads);
}

