// JavaScript Document

/*
pageWidth()
pageHeight()
posLeft()
posRight()
posTop()
posBottom()
*/

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}
                    
					
					
function scrollbarWidth() {
	// Scrollbalken im Body ausschalten
	document.body.style.overflow = 'hidden';
	var width = document.body.clientWidth;
	// Scrollbalken
	document.body.style.overflow = 'scroll';
	width -= document.body.clientWidth;
	// Der IE im Standardmode

	if(!width) width = document.body.offsetWidth-document.body.clientWidth;
	// ursprüngliche Einstellungen wiederherstellen
	document.body.style.overflow = '';
	return width;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}



function hasHorizontalScrollbar(elem_id)
{
   //elem = document.getElementById(elem_id);
   //elem=document.body;
   //if (pageHeight() < getScrollY())
   // alert("The element has a vertical scrollbar!");
   //else
   return true;
}

var w=0;
var h=0;
function backgroundThread() {
	if (w==0 && h==0) {
		//w=pageWidth()-scrollbarWidth();
		w=pageWidth()-20;
		h=pageHeight();
		document.getElementById("o_bg").style.width=w+"px";
		document.getElementById("o_bg").style.height=h+"px";
	}
	else {
		tmpw=pageWidth()-20;
		tmph=pageHeight();
		
		if (w!=tmpw || h!=tmph) {
			w=tmpw;
			h=tmph;
			document.getElementById("o_bg").style.width=w+"px";
			document.getElementById("o_bg").style.height=h+"px";
		}
	}
}
window.setInterval("backgroundThread();",800);

function showBg() {
	Effect.Appear('o_bg',{ duration: 0.5, to: 0.6 });
}
function hideBg() {
	Effect.Fade('o_bg',{ duration: 0.5});
}

function showContentBook() {
	Effect.Appear('o_book',{ duration: 0.5, to: 1.0 });
}
function hideContentBook() {
	Effect.Fade('o_book',{ duration: 0.5});
}

function showContentPanel(section) {
	loadContent(section,true);
	showBg();
	window.setTimeout("showContentBook();",200);
}

function hideContentPanel() {
	hideContentBook();
	window.setTimeout("hideBg();",200);
}

function loadContent(section,reloadMenu) {
	if (transitionBlocked) return;
	showLoadingBar(reloadMenu);
	window.setTimeout("loadContentContinueToLoad('"+section+"',"+reloadMenu+");",550);
}
function loadContentContinueToLoad(section,reloadMenu) {
	new Ajax.Updater('o_content_body', 'ajax_responder.php?loc='+section,{
  			method: 'get',
  			encoding: 'utf-8',
			
  			onComplete: function(){
    			showContentBody()
  			}

  	});
	
	if (reloadMenu) {
		new Ajax.Updater('o_menu', 'ajax_responder_menu.php?loc='+section,{
  			method: 'get',
  			encoding: 'utf-8',
			
  			onComplete: function(){
    			showContentBody()
  			}

  		});
	}
}

var transitionBlocked=false;
var reloadMenuSwitch=false;
var resultCounter=0;

function showLoadingBar(reloadMenu) {
	if (transitionBlocked) return;
	//alert("hiding body and showing loader");
	//document.getElementById("o_content_body").style.display='none';
	//document.getElementById("o_loading").style.display='block';
	transitionBlocked=true;
	reloadMenuSwitch=reloadMenu;
	resultCounter=0;
	Effect.Fade('o_content_body',{ duration: 0.5});
	if (reloadMenu) Effect.BlindUp('o_menu',{ duration: 0.5});
	window.setTimeout("helper_showLoader();",550);
}
function helper_showLoader() {
	Effect.Appear('o_loading',{ duration: 0.5, to: 1.0 });
	window.setTimeout("helper_enableTransition();",550);
}
function helper_enableTransition() {
	transitionBlocked=false;
}

function delayTimeoutHandler() {
	if (transitionBlocked==false) {
		showContentBody();
	}
	else {
		window.setTimeout("delayTimeoutHandler();",100);
	}
}

function showContentBody() {
	resultCounter++;
	if (reloadMenuSwitch && resultCounter<2) return;
	if (transitionBlocked) {
		window.setTimeout("delayTimeoutHandler();",100);
		return;
	}
	transitionBlocked=true;
	//alert("showing body and hiding loader");
	Effect.Fade('o_loading',{ duration: 0.5});
	if (reloadMenuSwitch) Effect.BlindDown('o_menu',{ duration: 0.5});
	window.setTimeout("helper_showContentBody();",550);
	//document.getElementById("o_loading").style.display='none';
	//document.getElementById("o_content_body").style.display='block';
}
function helper_showContentBody() {
	Effect.Appear('o_content_body',{ duration: 0.5, to: 1.0 });
	window.setTimeout("helper_enableTransition();",550);
}

