/*
	Windowthing Webscript V0.1
	
	Ein Framework für browserbasierte Webanwendungen.

	Script erstellt von Alexander Christmann.
	Darf verwendet werden, so fern es
	unveraendert bleibt. Die Farbwerte in den Variablen
	sind von dieser Regel ausgenommen.
	
	(vorerst, bis hier ein richtiger Header steht.)
*/
var currentArticle = 0;
var currentSubcontent = 0;

var lightBorder = '1px dotted #b3b3b3';
var noBorder = '0px solid #000';

var selectedColor = '#b3b3b3';
var noColor = '';

function openWindow(it) {
	if (it) {
		if (it.style.display!='block') {
			it.style.display='block';
		}
	}
}

function closeWindow(it) {
	if (it) {
		if (it.style.display=='block') {
			it.style.display='none';
		}
	}
}

function blowWindow(it) {
	if (it) {
       it.style.color = selectedColor;
	}
}

function suckWindow(it) {
	if (it) {
	     it.style.color = noColor;
	}
}

function allArticles() {
	articles = new Array();
	them = document.getElementsByTagName("div");
	for (i = 0; i < them.length; i ++) {
		id = them[i].getAttribute('id');
		if (id) {
			if (id.substr(0,7) == 'artikel'
			||	them[i].getAttribute('class') == 'contentWindow') {
				articles.push(them[i]);
			}
		}
	}
	
	return articles;
}

function allNavs() {
	navs = new Array();
	them = document.getElementsByTagName("a");
	for (i = 0; i < them.length;	 i ++) {
		id = them[i].getAttribute('id');
		if (id != null) {
			if (id.substr(0,3) == 'nav'
			||	!them[i].getAttribute('class') == 'menuItemLink') {
				navs.push(them[i]);
			}
		}
	}
	
	return navs;
}	

function allSubNavs() {
	subnavs = new Array();
	hs = document.getElementsByTagName("h1");
	for (i = 0; i < hs.length; i ++) {
		if (hs[i].getAttribute('class') == 'subnav') {
			subnavs.push(hs[i]);
		}
	}

	return subnavs;
}

function allSubContents() {
	subcontents = new Array();
	ps = document.getElementsByTagName("p");
	
	for (i = 0; i < ps.length; i ++) {
		if (ps[i].getAttribute('class') == 'subcontent' 
		||	ps[i].className == 'subcontent') {
			subcontents.push(ps[i]);
		}
	}

	return subcontents;
}

function getNavElement(name) {
	those = allNavs();
	for (i = 0; i < those.length; i ++) {
		if (those[i].getAttribute('id') == 'nav'+name) {
			return those[i];
		}
	}
	return 0;
}

function getArticleElement(name) {
	those = allArticles();
	for (i = 0; i < those.length; i ++) {
		if (those[i].getAttribute('id') == 'artikel'+name) {
			return those[i];
		}
	}
	return 0;
}

function getSubNavElement(name) {
	those = allSubNavs();
	for (i = 0; i < those.length; i ++) {
		if (those[i].getAttribute('id') == 'subnav'+name) {
			return those[i];
		}
	}
	return 0;
}

function getSubContentElement(name) {
	those = allSubContents();
	for (i = 0; i < those.length; i ++) {
		if (those[i].getAttribute('id') == 'subcontent'+name) {
			return those[i];
		}
	}
	return 0;
}

var animatedArticle;
var animatedArticleDestHeight = 0;
var animatedArticleHeight = 0;

function openArticle(name) {
	those = allArticles();
	for (i = 0; i < those.length; i ++) {
		closeWindow(those[i]);
	}
	
	those = allNavs();
	for (i = 0; i < those.length; i ++) {
		suckWindow(those[i]);
	}

	animatedArticle = getArticleElement(name);
	openWindow(animatedArticle);
	animatedArticleDestHeight = animatedArticle.offsetHeight;
	animatedArticleSpeed = 100;
	animatedArticleHeight = 0;
	
//	window.setInterval('animateArticle();', 10);
	blowWindow(getNavElement(name));
	currentArticle = name;
}

function animateArticle() {
	if (animatedArticle) {
		if (animatedArticleHeight < animatedArticleDestHeight) {
			animatedArticle.style.height = animatedArticleHeight + "px";
			animatedArticleHeight += animatedArticleSpeed;
			animatedArticleSpeed /= 2;
			if (animatedArticleSpeed < 2) {
				animatedArticleSpeed = 2;
			}
		} else {
			animatedArticle = null;
		}
	}	
}

function openSubcontent(name) {
	those = allSubContents();
	for (i = 0; i < those.length; i ++) {
		closeWindow(those[i]);
	}
	
	openWindow(getSubContentElement(name));
	currentSubcontent = name;
}

function offSideNav () {

  document.getElementById("leftMenu").style.visibility= "collapse";
  document.getElementById("appPortfolioControll").style.marginLeft= "3em";
  document.getElementById("onOffButtonDiv2").style.display= "block";
  document.getElementById("onOffButtonDiv").style.display= "none";
}

function onSideNav () {

  document.getElementById("leftMenu").style.visibility= "visible";
  document.getElementById("appPortfolioControll").style.marginLeft= "12.7em";
  document.getElementById("onOffButtonDiv").style.display= "block";
  document.getElementById("onOffButtonDiv2").style.display= "none";
}


