﻿var baseUrl = null;

function init () {
	
	baseUrl = $('base').attr('href');

	
		//
		// Adds "over"-class to list items. 
		// This hack enables hover effects on list items for IE6.
		//
	if (document.all&&document.getElementById) {
		var tabNavNode = document.getElementById("tabNav");
		if (tabNavNode != null) {
			addClassToListItems (tabNavNode);
		}
		var subTabNavNode = document.getElementById("subTabNav");
		if (subTabNavNode != null) {
			addClassToListItems (subTabNavNode);
		}		
	}

		//
		// If the variable infoBox isn't empty, we set its value to the innerHTML of the infoBox node.
		//
	if (document.getElementById("infoBox")) {	
		if (typeof(infoText) == "string" && infoText != "") {
			document.getElementById("infoBox").innerHTML = infoText;
		}
	}
	
		//
		// If the variable lastBreadcrumb is set, we append its value to the breadcrumbNav
		// and remove the "cur" class from the previous last item, so it gets a default link layout
		//
	if (document.getElementById("breadcrumbNav")) {		
		if (typeof(lastBreadcrumb) == "string" && lastBreadcrumb != "") {
			var breadcrumbNav = document.getElementById("breadcrumbNav");
			var navItems = breadcrumbNav.getElementsByTagName('a');
			var lastItem = navItems[navItems.length-1];
			lastItem.className = "";			
			breadcrumbNav.innerHTML = breadcrumbNav.innerHTML + "&nbsp;&gt;&nbsp;" + lastBreadcrumb;
		}			
	}
	
	
	
		//
		// This is a proof of concept, but makes no sense imho to use a hover event listener here
		//
	$('ul.homeTopLinks li ul').parent('li').hover(
		function() { $(this).children('ul').slideDown(); },
		function() { $(this).children('ul').slideUp(); }
	);
	
	/*
		//
		// all homeTopLinks list items with an additional ul within the li have a slide toggle on the a tag
		//
	$('ul.homeTopLinks li ul').prev('a').click(
		function() { $(this).next('ul').slideToggle(); return false; }
	);
	*/
	
		//
		// 
		//
	$('#fotothekLinks a').hover(
		function() { 
			$('#fotothekLinks a').removeClass('fotothekLinks-ro'); $(this).addClass('fotothekLinks-ro'); 
			$(this).parents('#fotothekBox').addClass($(this).attr('id'));
		},
		function() {
			$(this).removeClass('fotothekLinks-ro'); $(this).parents('#fotothekBox').removeClass($(this).attr('id'));
			
			$('#fotothekLinks a:first').addClass('fotothekLinks-ro'); $(this).parents('#fotothekBox').addClass('fotothekLink-visuelle');
		}
	);
	
		//
		// 
		//
	$('.homeNews').hover(
		function() { $(this).addClass('homeNews-ro'); },
		function() { $(this).removeClass('homeNews-ro'); }
	);
	
	$('.navigation-radio').click(
		function() { window.location.href = $('base').attr('href') + $(this).parents('a').attr('href'); }
	);
	
	$(document).keypress(function(e) {
		if (e.keyCode == 13) {
			$('.tx-newloginbox-pi1 form').submit();
		}
	});
	
}

	//
	// JS function adds css-class "over" to listitems. This is needed in IE for mouseover
	//
function addClassToListItems (parentNode) {
	var listitems = parentNode.getElementsByTagName('li')
	for (i=0; i<listitems.length; i++) {
		node = listitems[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
				this.className+=" over";
			}
  			node.onmouseout=function() {
  				this.className=this.className.replace(" over", "");
  			}
  	 	}
  	}
}


/*
The height and width of the total page (usually the body element).
This is a tricky one, some browsers require scrollHeight, others offsetHeight, 
but all browsers support both properties. 
Therefore I see which property has the larger value. 
This means the page height the script below gives is never smaller than the window height.
http://www.quirksmode.org/viewport/compatibility.html
*/
function getPageDimensions() {
	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;
	}
	return new Array(x,y);
}
