var swappedBackground = new Array();
var swappedColor = new Array();
var toggledSub = new Array();
var active='content1';
var inactive='content2';

document.observe('dom:loaded', function () { 
	var size = getPageSize();
	var u = $$('li.subnavili');
	for (i=0;i<u.length;i++){
		u[i].hide();
		}
	$('content2').hide();
	if (size[1] < 730) {
		$('content').style.height = '500px';
		$('content1').style.height = '440px';
		$('content2').style.height = '440px';
		}
	else {
		$('content').style.height = size[1] - 230 +'px'; 
		$('content1').style.height = size[1] - 290 +'px'; 
		$('content2').style.height = size[1] - 290 +'px'; 
		}
	});
	
Event.observe(document.onresize ? document : window, "resize", function() {
	var size = getPageSize();
	if (size[1] < 730) {
		$('content').style.height = '500px';
		$('content1').style.height = '440px';
		$('content2').style.height = '440px';
		}
	else {
		$('content').style.height = size[1] - 230 +'px';
		$('content1').style.height = size[1] - 290 +'px';
		$('content2').style.height = size[1] - 290 +'px';
		}
	});  

function getPageSize (){
     var xScroll, yScroll;
		
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
		} 
	else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
		} 
	else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
		}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
			} 
		else {
			windowWidth = self.innerWidth;
			}
		windowHeight = self.innerHeight;
		} 
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
		} 
	else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
		}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
		} 
	else { 
		pageHeight = yScroll;
		}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
		} 
	else {
		pageWidth = windowWidth;
		}

		return [windowWidth,windowHeight];
//		return [pageWidth,pageHeight];
	}

function swapBackground(id, backgoundcolor,color)
	{
	var el = $(id);
	if (el)
		{
		swappedBackground[id] = el.style.background;
		el.style.background = backgoundcolor;
		swappedColor[id] = el.style.color;
		el.style.color = color;
		}
	}

function swapBackgroundBack(id)
	{
	if (typeof(swappedBackground[id]) != 'undefined')
		{
		var el = $(id);
		if (el)
			{
			el.style.background = swappedBackground[id];
			el.style.color = swappedColor[id];
			}
		}
	}

function loadContent(id) {
	var url = 'index.php';
	var par = 'id='+id+'&type=1';
	var acttemp = active;
	
	new Ajax.Request(url, {
 		method: 'get',	
 		parameters: par,
  		onSuccess: function(transport) {			
  			$(inactive).innerHTML = transport.responseText;
  			var e = $$('li.aktiv');
  			for (i=0;i<e.length;i++) {
  				e[i].className = 'inaktiv';
  				e[i].style.background = '#ECECF5';
  				swappedBackground[e[i].identify()] = '#ECECF5';
  				}
  			var eum = $$('li.umaktiv');
  			for (i=0;i<eum.length;i++) {
  				eum[i].className = 'uminaktiv';
  				eum[i].style.background = '#ECECF5';
  				swappedBackground[eum[i].identify()] = '#ECECF5';
  				}
  			$('menu'+id).className = 'aktiv';
  			$('menu'+id).style.background = '#8F8BA8';
  			swappedBackground['menu'+id] = '#8F8BA8';
  			new Effect.Parallel([
  				new Effect.Appear($(inactive),{sync:true}),
  				new Effect.Fade($(active),{sync:true})
  				],{duration: 0.01});
  			active = inactive;
  			inactive = acttemp;
  			$(inactive).style.position = 'absolute';
  			$(active).style.position = 'relative';
  			document.title = $('link'+id).innerHTML;
  			}
		});	
	
	}
	
function loadContentUM(id) {
	var url = 'index.php';
	var par = 'id='+id+'&type=1';
	var acttemp = active;
	new Ajax.Request(url, {
 		method: 'get',
 		parameters: par,
  		onSuccess: function(transport) {
  			$(inactive).innerHTML = transport.responseText;
  			var e = $$('li.aktiv');
  			for (i=0;i<e.length;i++) {
  				e[i].className = 'inaktiv';
  				e[i].style.background = '#ECECF5';
  				swappedBackground[e[i].identify()] = '#ECECF5';
  				}
  			var eum = $$('li.umaktiv');
  			for (i=0;i<eum.length;i++) {
  				eum[i].className = 'uminaktiv';
  				eum[i].style.background = '#ECECF5';
  				swappedBackground[eum[i].identify()] = '#ECECF5';
  				}
  			$('menu'+id).className = 'umaktiv';
  			$('menu'+id).style.background = '#8F8BA8';
  			swappedBackground['menu'+id] = '#8F8BA8';
  			new Effect.Parallel([
  				new Effect.Appear($(inactive),{sync:true}),
  				new Effect.Fade($(active),{sync:true})
  				],{duration: 0.01});
  			active = inactive;
  			inactive = acttemp;
  			$(inactive).style.position = 'absolute';
  			$(active).style.position = 'relative';
  			document.title = $('link'+id).innerHTML;
  			}
		});	
	}
	
function toggleSubnavi(subid) {
	var el = $(subid);
	if (el)
		{
		if ((typeof(toggledSub[subid]) == 'undefined')||(!toggledSub[subid])){
			toggledSub[subid] = true;
			new Effect.SlideDown(subid,{duration: 0.3});
			}
		else {
			toggledSub[subid] = false;
			new Effect.SlideUp(subid,{duration: 0.3});
			}
		}	
	}
