//
// Copyright 2006 Oskar Eisemuth - Internetdienste Eisemuth 
//

function beh_step_addbeh()
{
	if (document.all) {
		var elel = document.all;
	} else { 
		var elel = document.getElementsByTagName('*');
	}
	var i = elel.length;
	var ele;
	var re = new RegExp('(^|\\s)beh-steps(\\S*)(\\s|$)');
	while (i--)
	{
        var ele = elel[i];
        if (ele.className && re.test(ele.className)) 
		{
			var ret = re.exec(ele.className);
			
			ret = ret[2].split(':');
			beh_step_addbeh2(ele.id, ret[1]);
		}
	}
}
function beh_step_addbeh2(container, prefix, disable) 
{
	if(document.getElementById) 
	{
		var cont = document.getElementById(container);
		var links = cont.getElementsByTagName('a');
		var j=1;
		var schrittid;
		
		cont.schrittaktiv = '';
		while (schritt = document.getElementById(prefix+j))
		{
			var i;
			for (i=0;i<links.length;i++)
			{
				var ahref = links[i].href.match(/#(\w.+)/)[1];
				if (ahref == (prefix+j)) {
					links[i].onclick = beh_step_navclick;
					links[i].schrittshow = prefix+j;
					links[i].schrittcontainer = container;
				}
			}
			if (location.hash && (location.hash == '#'+prefix+j)) {
				cont.schrittaktiv = prefix+j;
			}
			schritt.className = schritt.className.replace(/\s*stephidden/,'') + ' stephidden';
			j++;
		}
		if (cont.schrittaktiv == '') {
			cont.schrittaktiv = prefix+1;
		}
		var ele = document.getElementById(cont.schrittaktiv);
		ele.className = ele.className.replace(/\s*stephidden/,'')	
	}
}

function beh_step_navclick()
{
	var cont = document.getElementById(this.schrittcontainer);
	var next = document.getElementById(this.schrittshow);
	var prev = document.getElementById(cont.schrittaktiv);
	if (this.schrittshow == cont.schrittaktiv) return false;
	prev.className += ' stephidden';
	cont.schrittaktiv = this.schrittshow;
	next.className = next.className.replace(/\s*stephidden/,'');
	beh_step_historyHash = '#'+cont.schrittaktiv;
	window.location.hash = beh_step_historyHash;
	return false;
}
function beh_step_history() {
	if ( window.location.hash != beh_step_historyHash )
	{
		beh_step_historyHash = window.location.hash;
		beh_step_addbeh();
	}
	window.setTimeout("beh_step_history()", 1000);
}

function beh_step_load() {
	// we got already fired
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	beh_step_historyHash = window.location.hash;
	window.setTimeout("beh_step_history()", 1000);
	beh_step_addbeh();
}

function beh_step_init() {
	if (document.addEventListener) {
    	document.addEventListener("DOMContentLoaded", beh_step_load, null);
	}
	if (typeof window.onload != 'function') {
		window.onload = beh_step_load;
	} else {
		var oldfn = window.onload;
		window.onload = function() {
			oldfn();
			beh_step_load();
		}
	}
}
beh_step_init();


