function browserCorrect() {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		correct = true;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		correct = false;
	}
	else if (document.body) // other Explorers
	{
		correct = false;
	}

	return correct;
}

function innerDimensions() {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	var vector = new Object();
	vector.x = x;
	vector.y = y;

	return vector;
}

function scrollDimensions() {
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
 	var vector = new Object();
	vector.x = x;
	vector.y = y;

	return vector;
}

function pageDimensions() {
	var x,y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	if (test1 > test2) // all but Explorer Mac
	{
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}
	else // Explorer Mac;
     	//would also work in Explorer 6 Strict, Mozilla and Safari
	{
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}

 	var vector = new Object();
	vector.x = x;
	vector.y = y;

	return vector;
}

function reposition(width) {
	
	var pageDims   = pageDimensions();
	var scrollDims = scrollDimensions();
	var innerDims  = innerDimensions();
	
	var correct = browserCorrect();
	
	var item_height = document.getElementById("bottomMenu").offsetHeight;
	//var item_height = 28;
	
	if (innerDims.x - correct*16 >= width ) {
		y = innerDims.y + scrollDims.y - item_height;	
	}
	else
	{
		y = innerDims.y + scrollDims.y - item_height - correct*16;	

	}

	//document.getElementById("bottomMenu").style.width = "100%"; 	
	document.getElementById("bottomMenu").style.position = "absolute"; 
	document.getElementById("bottomMenu").style.top = "" + y;
}//alert("Hello");

// JavaScript Document



//---------------- ab hier!!!!!!! ----------------------------


var mainContent;
var menuItem;

// 1. openFrame instead of naked iframe-html
function openFrame() {
	mainContent = self.location.href; //the URI of the iframe	
	if (self.name != "main") {
		self.location.href = "index.php?id=1";
		self.name = "init" + encodeURI(mainContent);
	}else {
		parent.name = encodeURI(mainContent);
		
	}	
	
}

// 2. "jump" to the right iframe after that
function initialize() {
	
	if (self.name.indexOf("init") == 0) {
		filename = decodeURI(self.name.slice(4));
		main.location.href = filename;
		menuItem = getItem(filename); // the chapter the iframe belongs to, detected by the titlelogo-image-name
	

		//alert(menuItem + "__" + self.name);
	
		// tell the flashmenu where to jump
		window.document.klMenu.SetVariable("update",menuItem);
		window.document.klMenu.SetVariable("debug",menuItem);
		window.document.klMenu.TCallLabel("/", "Update");
	}
 }



//vorerst!!!

function getItem(url) {
	//einzelteile = url.split(".");
	//filename = einzelteile[einzelteile.length -2];
	filename = url;
	//alert(url); 
	return(filename.charAt(filename.length - 1) - 2);
}


function fillIframe(args) {

	// id=parseInt(args)+2;
	
	
	switch (parseInt(args)) {
		case 0:
			//id = 42; aktuelles
		//default = veranstaltungen
			//gehe zur Startseite;
			self.location.href = "index.php?id=77";
			break;
		case 1:
		//persoenliches
			id = 3;
			break;
		
		case 2:
		//gemeinsam lernen
			id = 4;
			break;
		case 3:
		//veranstaltungen
			id = 5;
			break;
		case 4:
		//trainerausbildung
			id = 6;
			break;
		case 5:
		//tiersitter-service
			id = 7;
			break;
		case 6:
		//wissenswertes
			id = 8;
			break;
		case 7:
		//forum
			id = 9;
			break;
		case 8:
		//kontakt
			id = 2;
			break;
		
		default:
		//default = veranstaltungen
			id = 5;
			break;
	
	}
	
	main.location.href = "index.php?id="+id;
	self.name = "";
}


// Scrolling Tools

var contentTopBegin;
var contentHeight;
var contentTop;
//var windowHeight;

var topFix = 108;
var heightFix = 362;



function getMeasures(element) {

	if (document.all && document.all[element].offsetTop) {
		now = document.all[element].offsetTop;
		contentHeight = document.all[element].offsetHeight;
		//windowHeight = document.body.offsetHeight;
		//alert("MS " + now);		
	} else if (document.getElementById) {
		now = document.getElementById(element).offsetTop;
		contentHeight = document.getElementById(element).offsetHeight;
		//windowHeight = window.innerHeight;
		//alert("DOM " + now);		
	}

	//alert(windowHeight);
	contentTopBegin = now;
	return now;
}



function scrollerDisplay() {
	if (contentTop == undefined) {
		contentTop = getMeasures("framecontent");
	}
	
	
	if (contentHeight > heightFix) {
		document.getElementById("scroller").style.visibility = "visible";
	}

}

var isScrolling;

function startScroll(direction) {
	if (direction > 0) {
		isScrolling = window.setInterval("scroll('framecontent',1)",50);		scroll("framecontent",1)
	}else {
		isScrolling = window.setInterval("scroll('framecontent',-1)",50);
	}	
	return true;
}

function stopScroll() {
	window.clearInterval(isScrolling);
	isScrolling = 0;
	return true;
}

function scroll(element,direction) {
	
	if (contentTop == undefined) {
		contentTop = getMeasures(element);
	}
	
	now = contentTop;	
	
	if (direction > 0) {
		if (now > topFix + heightFix - contentHeight) {
		now = String(parseInt(now) - 12);
		}
	}else{
		if (now < topFix) {
			now = String(parseInt(now) + 12);
		}
	}

	document.getElementById(element).style.width = "764px"; 	
	document.getElementById(element).style.position = "absolute";
	document.getElementById(element).style.top = now + "px";
	
	contentTop = now;
	return true;

}