// site navigation
var Navi = (function ()
{
	function getText(obj) 
	{
		var l, Text;
		Text = obj.textContent || obj.firstChild.data;
		l    = Text.split("'");
		Text = (l.length > 1) ? l[0] + l[l.length - 1] : l[0];
		return Text;
	}
		
	function createNavis(list) 
	{
		var i,
		    l     = list.length,
		    doc   = document,
		    datei = window.location.href + "#",
		    fragN = doc.createDocumentFragment(),
		    fragL = doc.createDocumentFragment();
		
		for (i = 0; i < l; i++) {
			fragN.appendChild(
				Code.createCustomElement(
					"a", getText(list[i]), { href : datei + list[i].id }
				)
			);
			doc.getElementById("Navigation").appendChild(fragN);
			fragL.appendChild(
				Code.createCustomElement(
					"link", "", { rel : "bookmark", href : datei + list[i].id, title : getText(list[i]) }
				)
			);
			doc.getElementsByTagName("head")[0].appendChild(fragL);
		}
	}

	return {
		init : function () 
		{
			createNavis(Code.getElementsByClassName("hook", "a"));
		}
	};
})();
// image popup
var Popup = (function () 
{
	var Bilder = [];
	
	function pop() 
	{
		var i, B;
		for (i = Bilder.length; i--;) {
			B = Bilder[i];
			if (B.id === this.id) {
				window.open(B.src, B.titel, B.props);
			}
		}
	}
		
	return {
		load : function (ID, QLL, TTL, HOCH, BREIT) 
		{
			var obj = { 
				id    : ID, 
				src   : QLL, 
				titel : TTL, 
				props : "height=" + HOCH + ",width=" + BREIT + ",menubar=no,resizable=yes,scrollbars=yes,location=no" 
			};
			Bilder.push(obj);
		},
		
		init : function () 
		{
			var i, z, doc = document;
			for (i = Bilder.length; i--;) {
				z = doc.getElementById(Bilder[i].id);	
				if (z) {
					z.style.cursor = "pointer";
					Events.add(z, "click", pop);
				}
			}
		}
	};
})();
// Suckerfish Dropdown IE fix
var SFIE = function () 
{
	var m_over, m_out, sfEls;
	m_over = function () 
	{
		this.className += " over";
	};
	m_out = function () {
		this.className = this.className.replace(new RegExp(" over\\b"), "");
	};
	sfEls = document.getElementById("SFDD").getElementsByTagName("li");
	sfEls.addEventForEach("mouseover", m_over);
	sfEls.addEventForeach("mouseout",  m_out);
	document.getElementById("NJPS").style.visibility = "visible";
};

/* if (!window.addEventListener) {
	Events.loading(SFIE); 
} */
// form validation
var Form1 = (function () 
{
	function checkMail() 
	{
		var RE = /^[\w.%+\-]+@[\w.\-]+\.[a-z]{2,4}$/;
		if (!this.value) {
			this.style.border = "2px solid red";
			alert(Form1.emptyMail);
			return false;
		} 
		else if (RE.test(this.value) === false) {
			this.style.color  = "red";
			this.style.border = "2px solid red";
			alert(Form1.invalidMail);
			return false;
		}
		return true;
	}
	
	return {	
		emptyMail : "Bitte Emailadresse eingeben",
		invalidMail : "Ungültige Emailadresse",
		mailID : "anmelden2",
		check : function () 
		{
			var mf = document.getElementById(Form1.mailID);
			if (mf) {
				return checkMail.call(mf);
			}
			return true;
		}
	};
})();
// AJAX Article Request
var Artikel = (function () 
{
	function writeToDoc(paket, ident) 
	{
		var i, l,
		    base = document.getElementById(ident),
			bq   = document.createElement("blockquote"),
		    xml  = new WDDX(paket),
		    doc  = xml.deserialize();
		
		bq.appendElement("h5", doc.shift(), false);
		for (i = 0, l = doc.length; i < l; i++) {
			bq.appendElement(doc[i].name, doc[i].content, doc[i].attributes);
		}
		base.appendChild(bq);
	}

	function changeAnker(ident) 
	{
		var anker = document.getElementById("a" + ident);
		anker.parentNode.removeChild(anker);	
		addAnker(ident, "c");
	}

	function addAnker(ident, prefix) 
	{
		var anker = document.getElementById(ident).appendElement("a", "Artikeltext entfernen", { id : prefix + ident });
		function fn_removeArtikel() 
		{ 
			removeArtikel(ident); 
		}
		anker.addEvent("click", fn_removeArtikel);
		anker.style.cursor = "pointer";
		anker.style.color = "#0080FF";
	}

	function removeArtikel(ident) 
	{
		var Link, div = document.getElementById(ident);
		while (div.firstChild) {
			div.removeChild(div.firstChild);
		}
		Link = div.appendElement("a", "Artikeltext anschauen", { id : "a" + ident });
		Link.style.cursor = "pointer";
		Link.style.color = "#0080FF";
		doRequest.call(Link);
	}
	
	function doRequest() 
	{
		var art = new Ajax(Artikel.url);
		art.answer = function (xml, id) 
		{
			changeAnker(id);
			writeToDoc(xml, id);
			addAnker(id, "b");
		};
		this.removeAttribute("href");
		this.style.cursor = "pointer";
		this.style.color = "#0080FF";
		art.create(this.parentNode.id);
		function go() 
		{
			var sbm = {};
			sbm[Artikel.qry] = this.parentNode.id;
			art.submit(sbm);
		}
		this.addEvent("click", go);
	}

	return {
		url : "article.php",
		qry : "AOD",
		init : function () 
		{
			Code.getElementsByClassName("cfa").applyForEach(doRequest);
		}
	};
})();


