//vars
var scroll_faster_txt;
var back_to_page_txt;
var err_msg;
if(Lang=="DE"){
	scroll_faster_txt = 'Klicken Sie schneller zu blättern';
	back_to_page_txt = 'ZURÜCK ZUR SEITE';
	err_msg = 'Die erforderlichen Informationen unvollständig oder fehlerhaft:';
}else{//is en
	scroll_faster_txt = 'Click to scroll faster';
	back_to_page_txt = 'BACK TO PAGE';
	err_msg = 'The required information is incomplete or contains errors:';
}

// (C) www.dhtmlgoodies.com, October 2005
var expandFirstItemAutomatically = false;	// Expand first menu item automatically ?
var initMenuIdToExpand = pageid;	// Id of menu item that should be initially expanded. the id is defined in the <li> tag.
var expandMenuItemByUrl = false;	// Menu will automatically expand by url - i.e. if the href of the menu item is in the current location, it will expand


var initialMenuItemAlwaysExpanded = false;	// NOT IMPLEMENTED YET

var sh_slmenuObj;
var divToScroll = false;
var ulToScroll = false;	
var divCounter = 1;
var otherDivsToScroll = new Array();
var divToHide = false;
var parentDivToHide = new Array();
var ulToHide = false;
var offsetOpera = 0;
if(navigator.userAgent.indexOf('Opera')>=0)offsetOpera=1;	
var slideMenuHeightOfCurrentBox = 0;
var objectsToExpand = new Array();
var initExpandIndex = 0;
var alwaysExpanedItems = new Array();	
	
function popMenusToShow()
{
	var obj = divToScroll;
	var endArray = new Array();
	while(obj && obj.tagName!='BODY'){
		if(obj.tagName=='DIV' && obj.id.indexOf('slideDiv')>=0){
			var objFound = -1;
			for(var no=0;no<otherDivsToScroll.length;no++){
				if(otherDivsToScroll[no]==obj){
					objFound = no;		
				}					
			}	
			if(objFound>=0){
				otherDivsToScroll.splice(objFound,1);	
			}		
		}	
		obj = obj.parentNode;
	}	
}

function showSubMenu(e,inputObj)
{

	if(this && this.tagName)inputObj = this.parentNode;
	if(inputObj && inputObj.tagName=='LI'){
		divToScroll = inputObj.getElementsByTagName('DIV')[0];
		for(var no=0;no<otherDivsToScroll.length;no++){
			if(otherDivsToScroll[no]==divToScroll)return;
		}			
	}
	hidingInProcess = false;
	if(otherDivsToScroll.length>0){
		if(divToScroll){				
			if(otherDivsToScroll.length>0){
				popMenusToShow();
			}
			if(otherDivsToScroll.length>0){	
				autoHideMenus();
				hidingInProcess = true;
			}
		}	
	}		
	if(divToScroll && !hidingInProcess){
		divToScroll.style.display='';
		otherDivsToScroll.length = 0;
		otherDivToScroll = divToScroll.parentNode;
		otherDivsToScroll.push(divToScroll);	
		while(otherDivToScroll && otherDivToScroll.tagName!='BODY'){
			if(otherDivToScroll.tagName=='DIV' && otherDivToScroll.id.indexOf('slideDiv')>=0){
				otherDivsToScroll.push(otherDivToScroll);
									
			}
			otherDivToScroll = otherDivToScroll.parentNode;
		}			
		ulToScroll = divToScroll.getElementsByTagName('UL')[0];
		if(divToScroll.style.height.replace('px','')/1<=1)scrollDownSub();
	}	
	
	//return false;
}



function autoHideMenus()
{
	if(otherDivsToScroll.length>0){
		divToHide = otherDivsToScroll[otherDivsToScroll.length-1];
		parentDivToHide.length=0;
		var obj = divToHide.parentNode.parentNode.parentNode;
		while(obj && obj.tagName=='DIV'){			
			if(obj.id.indexOf('slideDiv')>=0)parentDivToHide.push(obj);
			obj = obj.parentNode.parentNode.parentNode;
		}
		var tmpHeight = (divToHide.style.height.replace('px','')/1 - slideMenuHeightOfCurrentBox);
		if(tmpHeight<0)tmpHeight=0;
		if(slideMenuHeightOfCurrentBox)divToHide.style.height = tmpHeight  + 'px';
		ulToHide = divToHide.getElementsByTagName('UL')[0];
		slideMenuHeightOfCurrentBox = ulToHide.offsetHeight;
		scrollUpMenu();		
	}else{
		slideMenuHeightOfCurrentBox = 0;
		showSubMenu();			
	}
}


function scrollUpMenu()
{

	var height = divToHide.offsetHeight;
	height-=15;
	if(height<0)height=0;
	divToHide.style.height = height + 'px';

	for(var no=0;no<parentDivToHide.length;no++){	
		parentDivToHide[no].style.height = parentDivToHide[no].getElementsByTagName('UL')[0].offsetHeight + 'px';
	}
	if(height>0){
		setTimeout('scrollUpMenu()',5);
	}else{
		divToHide.style.display='none';
		otherDivsToScroll.length = otherDivsToScroll.length-1;
		autoHideMenus();			
	}
}	

function scrollDownSub()
{
	if(divToScroll){			
		var height = divToScroll.offsetHeight/1;
		var offsetMove =Math.min(15,(ulToScroll.offsetHeight - height));
		height = height +offsetMove ;
		divToScroll.style.height = height + 'px';
		
		for(var no=1;no<otherDivsToScroll.length;no++){
			var tmpHeight = otherDivsToScroll[no].offsetHeight/1 + offsetMove;
			otherDivsToScroll[no].style.height = tmpHeight + 'px';
		}			
		if(height<ulToScroll.offsetHeight)setTimeout('scrollDownSub()',5); else {
			divToScroll = false;
			ulToScroll = false;
			if(objectsToExpand.length>0 && initExpandIndex<(objectsToExpand.length-1)){
				initExpandIndex++;
				
				showSubMenu(false,objectsToExpand[initExpandIndex]);
			}
		}
	}
}
	
function initSubItems(inputObj,currentDepth)
{		
	divCounter++;		
	var div = document.createElement('DIV');	// Creating new div		
	div.style.overflow = 'hidden';	
	div.style.position = 'relative';
	div.style.display='none';
	div.style.height = '1px';
	div.id = 'slideDiv' + divCounter;
	div.className = 'slideMenuDiv' + currentDepth;		
	inputObj.parentNode.appendChild(div);	// Appending DIV as child element of <LI> that is parent of input <UL>		
	div.appendChild(inputObj);	// Appending <UL> to the div
	var menuItem = inputObj.getElementsByTagName('LI')[0];
	while(menuItem){
		if(menuItem.tagName=='LI'){
			var aTag = menuItem.getElementsByTagName('A')[0];
			aTag.className='slMenuItem_depth'+currentDepth;	
			var subUl = menuItem.getElementsByTagName('UL');
			if(subUl.length>0){
				initSubItems(subUl[0],currentDepth+1);					
			}
			aTag.onclick = showSubMenu;				
		}			
		menuItem = menuItem.nextSibling;						
	}		
}

function initSlideDownMenu()
{
	sh_slmenuObj = document.getElementById('sh_slidedown_menu');
	sh_slmenuObj.style.visibility='visible';
	var mainUl = sh_slmenuObj.getElementsByTagName('UL')[0];		
	var mainMenuItem = mainUl.getElementsByTagName('LI')[0];
	mainItemCounter = 1;
	while(mainMenuItem){			
		if(mainMenuItem.tagName=='LI'){
			var aTag = mainMenuItem.getElementsByTagName('A')[0];
			aTag.className='slMenuItem_depth1';	
			var subUl = mainMenuItem.getElementsByTagName('UL');
			if(subUl.length>0){
				mainMenuItem.id = 'mainMenuItem' + mainItemCounter;
				initSubItems(subUl[0],2);
				aTag.onclick = showSubMenu;
				mainItemCounter++;
			}				
		}			
		mainMenuItem = mainMenuItem.nextSibling;	
	}		
	
	if(location.search.indexOf('mainMenuItemToSlide')>=0){
		var items = location.search.split('&');
		for(var no=0;no<items.length;no++){
			if(items[no].indexOf('mainMenuItemToSlide')>=0){
				values = items[no].split('=');
				showSubMenu(false,document.getElementById('mainMenuItem' + values[1]));	
				initMenuIdToExpand = false;				
			}
		}			
	}else if(expandFirstItemAutomatically>0){
		if(document.getElementById('mainMenuItem' + expandFirstItemAutomatically)){
			showSubMenu(false,document.getElementById('mainMenuItem' + expandFirstItemAutomatically));
			initMenuIdToExpand = false;
		}
	}

	if(expandMenuItemByUrl)
	{
		var aTags = sh_slmenuObj.getElementsByTagName('A');
		for(var no=0;no<aTags.length;no++){
			var hrefToCheckOn = aTags[no].href;				
			if(location.href.indexOf(hrefToCheckOn)>=0 && hrefToCheckOn.indexOf('#')<hrefToCheckOn.length-1){
				initMenuIdToExpand = false;
				var obj = aTags[no].parentNode;
				while(obj && obj.id!='sh_slidedown_menu'){
					if(obj.tagName=='LI'){							
						var subUl = obj.getElementsByTagName('UL');
						if(initialMenuItemAlwaysExpanded)alwaysExpanedItems[obj.parentNode] = true;
						if(subUl.length>0){								
							objectsToExpand.unshift(obj);
						}
					}
					obj = obj.parentNode;	
				}
				showSubMenu(false,objectsToExpand[0]);
				break;					
			}			
		}
	}
			
	if(initMenuIdToExpand)
	{
		objectsToExpand = new Array();
		var obj = document.getElementById(initMenuIdToExpand)
		while(obj && obj.id!='sh_slidedown_menu'){
			if(obj.tagName=='LI'){
				var subUl = obj.getElementsByTagName('UL');
				if(initialMenuItemAlwaysExpanded)alwaysExpanedItems[obj.parentNode] = true;
				if(subUl.length>0){						
					objectsToExpand.unshift(obj);
				}
			}
			obj = obj.parentNode;	
		}
		
		showSubMenu(false,objectsToExpand[0]);

	}		
}
	
currentFullImage = 0;// set what the main image in the popup currently is
	
	function showPreview(imageArrayPos){
		
		preciewArrayCount = pageImages.length;
		
		currentFullImage = imageArrayPos;// set what the main image in the popup currently is
		
		document.fullImage.src=pageImages[imageArrayPos];
		
		backHTML = '<a href="#" onClick="SwapImg(\'backImg\'); return false;">'+'<img src="'+pathToImg+'prev_arrow.png" name="imgBack" id="imgBack"> Previous'+'</a>';
		
		closeHTML = '<a href="#" onClick="showPage(); return false;">Close</a>';

		forwardHTML = '<a href="#" onClick="SwapImg(\'forwardImg\'); return false;">'+'Next <img src="'+pathToImg+'next_arrow.png" name="imgForward" id="imgForward">'+'</a>';
		
		if(preciewArrayCount<=1){
			fullHTML = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="10">&nbsp;</td><td width="180" align="left">&nbsp;</td><td width="500" align="center">'+closeHTML+'</td><td width="180" align="right">&nbsp;</td><td width="10">&nbsp;</td></tr></table>';
		}else{
			fullHTML = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="10">&nbsp;</td><td width="180" align="left">'+'</td><td width="500" align="center">'+backHTML+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+closeHTML+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+forwardHTML+'</td><td width="180" align="right">'+'</td><td width="10">&nbsp;</td></tr></table>';
		}
		
		document.getElementById('galleryImageNav').innerHTML = fullHTML;
		
		document.getElementById('centre-column').style.left= '-370px';
		document.getElementById('MainImage').style.left= '-2000px';
		countG = 0-(880-240);
		showGallery();
		scroll(0,0);
	}
	function SwapImg(Type){
		
		arrayCount = pageImages.length - 1;
		
		if(Type == 'forwardImg'){
			moveToArrayElement = currentFullImage + 1;
			if(moveToArrayElement>arrayCount){
				moveToArrayElement = 0;
			}
		}else{
			moveToArrayElement = currentFullImage - 1;
			if(moveToArrayElement<0){
				moveToArrayElement = arrayCount;
			}
		}
		currentFullImage = moveToArrayElement;
		document.fullImage.src=pageImages[moveToArrayElement];
		
	}
	
	var countG = 0-(880-240);
	
/*	function showGallery(){
		
		document.getElementById('ImageGallery').style.left = countG+'px';
		
		width = 240;	
		
		if(countG < (width-60)){
			countG = countG+14;
			setTimeout(showGallery,2);
		}else if(countG < (width-30)){
			countG = countG+6;
			setTimeout(showGallery,2);
		}else if(countG < width){
			countG = countG+2;
			setTimeout(showGallery,2);
		}
		
	}

	function showPage() {
		countG = 0-(880-240);
		document.getElementById('ImageGallery').style.left= '-2000px';
		count2 = 0-mainContentWidth;
		SetImage('load',880);	
	}
	//window.onload = initSlideShow;
// SCROLLING layer script

var timeout;
var delay = 10;

function recScroll(elementId, direction, speed) { 
  clearTimeout(timeout);
  var intElemScrollTop = window.document.getElementById(elementId).scrollTop;
  if (direction == 'down') {
    window.document.getElementById(elementId).scrollTop = intElemScrollTop + speed;
  } else {
    window.document.getElementById(elementId).scrollTop = intElemScrollTop - speed;
  }
  if (intElemScrollTop != window.document.getElementById(elementId).scrollTop ) {
    timeout=setTimeout("recScroll('"+elementId+"', '"+direction+"', "+speed+");",delay);
  } else {
    recScrollLimit(elementId,direction);
  }
}
function recScrollStop() {
  clearTimeout(timeout);
}
function recScrollLimit(elementId, direction) {
  //alert("You can't keep scrolling "+elementId+" "+direction+".");
}

function recScrollBy(elementId, direction, pixels, speed) { 
  clearTimeout(timeout);
  if (pixels > 0) {
    var intElemScrollTop = window.document.getElementById(elementId).scrollTop;
    if (direction == 'down') {
      window.document.getElementById(elementId).scrollTop = intElemScrollTop + speed;
    } else {
      window.document.getElementById(elementId).scrollTop = intElemScrollTop - speed;
    }
    pixels = pixels - speed;
    timeout=setTimeout("recScrollBy('"+elementId+"', '"+direction+"', "+pixels+", "+speed+");",delay);
  }
}	  */

function scrollWheel(event){
  var delta = 0;
  var pixelsPerEvent = 40;
  var elementId = 'MainText';

  // Delta is a multiple of 120 (except for Mozilla where it is a multiple of 3)
  // In Opera and Mozilla the delta is negative compared to IE.
  if (!event) // Get the event for IE.
    event = window.event;
  if (event.wheelDelta) { // IE/Opera. 
    delta = event.wheelDelta/120;
    if (window.opera)
      delta = -delta;
  } else if (event.detail) { // Mozilla
    // I'm not going to divide by 3 since Mozilla's scrolling is so slow.
     delta = -event.detail;
  }

  /* Act if delta != 0 */
  if (delta) {
    if (delta < 0) {
      direction = 'down';
      delta = -delta;
    } else {
      direction = 'up';
    }
    pixels = pixelsPerEvent * delta;
    speed = delta * 5;
    //alert("Scrolling "+elementId+" "+direction+" by "+pixels); /* for debugging */
    recScrollBy(elementId,direction,delta,speed);
  }
}

/* Initialization code. */
/* Mozilla browsers use DOMMouseScroll which listens for scrolling _anywhere_ on the window */
//if (window.addEventListener)
  //window.addEventListener('DOMMouseScroll', scrollWheel, false);
  /* document.getElementById('thumbnails').addEventListener('DOMMouseScroll', scrollWheel, false); */

/* The following will listen for scrolling _anywhere_ in the window */
/* It is therefore preferable to assign this as an event for the area you wish to scroll */
/* e.g. <DIV ID="thumbnails" onmousewheel="wheel()"> */
//window.onmousewheel = document.onmousewheel = scrollWheel;


/*function insertScroll(){
	document.getElementById('scrollButtons').innerHTML=writeScrollButtons();
	//alert('insert scroll called');
} */

/*function writeScrollButtons(){
	if (parseInt(document.getElementById('MainText').offsetHeight) < parseInt(document.getElementById('MainText').scrollHeight)) {
     	ScrollText = '<div id="scrollHolder">  <a href="#" onmousedown="recScroll(\'MainText\',\'up\',5);" onmouseup="recScroll(\'MainText\',\'up\',1);" onmouseover="recScroll(\'MainText\',\'up\',1);MM_swapImage(\'arrowUp\',\'\',\''+pathToImg+'arrow_up_over.png\',0);" onmouseout="recScrollStop();MM_swapImgRestore();" onclick="return false;"><img src="'+pathToImg+'arrow_up.png" title="'+scroll_faster_txt+'" width="40" height="16" style="padding:5px" id="arrowUp" name="arrowUp"></a><a href="#" onmousedown="recScroll(\'MainText\',\'down\',5);" onmouseup="recScroll(\'MainText\',\'down\',1);" onmouseover="recScroll(\'MainText\',\'down\',1);MM_swapImage(\'arrowDown\',\'\',\''+pathToImg+'arrow_down_over.png\',0);" onmouseout="recScrollStop();MM_swapImgRestore();" onclick="return false;"><img src="'+pathToImg+'arrow_down.png" title="'+scroll_faster_txt+'" width="40" height="16" style="padding:5px" id="arrowDown" name="arrowDown"></a></div>';
	}else{
		ScrollText = '<div id="scrollTextAlt" style="height:30px;"></div>';
	}
	return ScrollText;
}*/



// SLIDE out the main boxes
function SetClass(Type){
	
	if(Type==1){
		document.getElementById('FullImage').className='FullImageHover';
	}else{
		document.getElementById('FullImage').className='FullImage';
	}

}


var count4;

var runInit4='yes';

function SetImage(Type,imgWidth){

	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
    	myWidth = window.innerWidth;
   		myHeight = window.innerHeight;
  	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
    	myHeight = document.documentElement.clientHeight;
  	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
  	}

	ImageWidth = myWidth - (240 + mainContentWidth) + 3;
	
	//alert(ImageWidth+' - '+imgWidth);
	
	if(ImageWidth>0){
		//InnerText = '<a href="#" id="FullImage" style="float:right" onClick="showPreview(0); return false;"><img src="'+pathToImg+'view_full_image_'+Lang+'.png"></a>';
		InnerText = '';
		if(imgWidth>=ImageWidth){
			document.getElementById('MainImage').innerHTML = InnerText;
		}
		document.getElementById('MainImage').style.width = ImageWidth+'px'; //set how much available space there is for the img
	}else{
		document.getElementById('MainImage').innerHTML = '';	
	}
	
	DivHeight = (myHeight - 607)/2;
	
	if((myHeight - 607)<0){
		document.getElementById('ContentSpcr').style.height = '0px';
		if(navigator.appName == "Netscape"){
			ImageWidth=ImageWidth-17; // if netscape acount for js not knowing about scroll bars
			document.getElementById('MainImage').style.width = ImageWidth+'px'; //set how much available space there is for the img
		}
	}else{
		document.getElementById('ContentSpcr').style.height = DivHeight+'px';
		setsession('spcrHeight',DivHeight);
	}
	
	
	count4 = 0-ImageWidth;
	
	
	if(ImageWidth>0){
		if(Type=='load'){
	
			document.getElementById('left-column').style.left = '0px';	
			init2();
			if(bgImg=='yes'){
				init4();
				//setTimeout(init4,500);
				runInit4='no';
			}
	
		}else if(Type=='load'){
	
			document.getElementById('left-column').style.left = '0px';	
			init3();
			if(bgImg=='yes'){
				init4();
				//setTimeout(init4,500);
				runInit4='no';
			}
	
		}else if(Type=='Siteload'){
		
			init1();
			init2();
			init3();
			init4();
			//setTimeout(init4,500);
			runInit4='no';
		
		}else if(Type=='resize'){
			if(runInit4=='yes'){
				if(bgImg=='yes'){
					init4();
					//setTimeout(init4,500);
					runInit4='no';
				}
			}
		}
		checkThis = 240 + mainContentWidth;
		if(ImageWidth>checkThis){
			if(runInit4=='yes'){
				if(bgImg=='yes'){
					init4();
					//setTimeout(init4,500);
					runInit4='no';
				}
			}
		}
		
	}else{
		document.getElementById('left-column').style.left = '0px';
		document.getElementById('centre-column').style.left = '240px';
		document.getElementById('third-column').style.left = '480px';
		runInit4='yes';
	}
}

var count1 = -240;
	
function init1() {
	
	document.getElementById('left-column').style.left = count1+'px';
	
	width = 0;	
	
	if(count1 < (width-30)){
		count1 = count1+14;
		setTimeout(init1,2);
	}else if(count1 < (width-15)){
		count1 = count1+6;
		setTimeout(init1,2);
	}else if(count1 < width){
		count1 = count1+2;
		setTimeout(init1,2);
	}
}

var count2 = 0-mainContentWidth;
	
function init2() {
	
	if(countG<(1-(880-240))){
	
		document.getElementById('centre-column').style.left = count2+'px';
		
		width = 209;	
		
		if(count2 < (width-60)){
			count2 = count2+14;
			setTimeout(init2,2);
		}else if(count2 < (width-30)){
			count2 = count2+6;
			setTimeout(init2,2);
		}else if(count2 < width){
			count2 = count2+2;
			setTimeout(init2,2);
		}
	
	}
}

var count3 = 0-mainContentWidth;
	
function init3() {
	
	if(countG<(1-(880-960))){
	
		document.getElementById('third-column').style.left = count3+'px';
		
		width = 592;	
		
		if(count3 < (width-660)){
			count3 = count3+14;
			setTimeout(init3,2);
		}else if(count3 < (width-60)){
			count3 = count3+6;
			setTimeout(init3,2);
		}else if(count3 < width){
			count3 = count3+2;
			setTimeout(init3,2);
		}
	
	}
}
	
function init4() {
	
	if(countG<(1-(880-240))){
	
		document.getElementById('MainImage').style.left = count4+'px';
		
		width = 253+mainContentWidth;	
		
		
		if(count4 < (width-1700)){
			count4 = count4+14;
			setTimeout(init4,2);
		}else if(count4 < (width-90)){
			count4 = count4+6;
			setTimeout(init4,2);
		}else if(count4 < width){
			count4 = count4+2;
			setTimeout(init4,2);
		}
	}
}

