﻿var ns = 0;
var ng = 0;
var menuvis='A';
var submenuvis='A';
var doc = document;
var currentHeight=0;
var timer;
var spin = null;
var elem = null;

if (document.layers) {ns=1;}
if (document.getElementById) {ng=1;}

function startElement(){
	
	elem = doc.getElementsByName("startElement")[0].value;
	menuup(elem);
	clearTimeout(start);
	spin = setInterval(function(){carrousel(elem);},6000);
	
	
}
function smoothSlideUp(elem,maxHeight,currentHeight) {
	if(currentHeight >= 24) {
		doc.getElementById(elem).style.visibility='visible';
	}
	if(currentHeight < maxHeight) {
		currentHeight=currentHeight+5;
		
		doc.getElementById(elem).style.height=currentHeight +'px';
		if(ns) {
		doc[elem].height=currentHeight +'px';
		}
		//setTimeout(smoothSlideUp(elem,maxHeight,currentHeight),100);
		var up=setTimeout(function(){smoothSlideUp(elem,maxHeight,currentHeight);},2);
		//smoothSlideUp(elem,maxHeight,currentHeight);
		
	} else
		{
			clearTimeout(up);
			return true;
		}
	
}

function smoothSlideDown(elem,minHeight,currentHeight) {
	if(currentHeight > minHeight) {
		currentHeight=currentHeight-5;
		
		doc.getElementById(elem).style.height=currentHeight +'px';
		if(ns) {
		doc[elem].height=currentHeight +'px';
		}
		var down=setTimeout(function(){smoothSlideDown(elem,minHeight,currentHeight);},2);
		//smoothSlideDown(elem,minHeight,currentHeight);
	} else
		{
			clearTimeout(down);
			return true;
		}
	
}


function menuup(nrstr) {

var mnew = nrstr.substr(0,1);
var submnew = nrstr.substr(1,1);
var agent = navigator.appVersion;
var agentver=agent.substring(17,25);

// Call ajax function to renew elements



//Block for capture the awsome ie6, beware ironic zone
if (agentver=='MSIE 6.0') {
doc.getElementById('menu_AA').style.position='absolute';
doc.getElementById('menu_BA').style.position='absolute';
doc.getElementById('menu_CA').style.position='absolute';
doc.getElementById('menu_DA').style.position='absolute';
doc.getElementById('menu_EA').style.position='absolute';
doc.getElementById('menu_FA').style.position='absolute';
doc.getElementById('menu_'+nrstr).style.position='relative';
}
clearInterval(spin);
//alert(agent);
	if(ns) {
		if (mnew != menuvis){
		smoothSlideDown('menu_'+menuvis+submenuvis,0,110);
		doc['menu_'+menuvis+submenuvis].visibility='hidden';
		doc['menu_'+menuvis+'A'].visibility='hidden';
	}
	
	if(submenuvis != 'A') {
		smoothSlideDown('menu_'+menuvis+submenuvis,0,110);
		doc['menu_'+menuvis+submenuvis].visibility='hidden';
	}
	smoothSlideUp('menu_'+nrstr,110,0);
	doc['menu_'+nrstr].visibility='visible';
	}
	
	if(spin==null || doc.getElementById('menu_'+menuvis+'A').style.height=='110px'){
	smoothSlideUp('menu_'+nrstr,110,0);
	doc.getElementById('image_'+nrstr).style.visibility='visible';
	var testlink = doc.getElementById('anker_'+nrstr).href;
	doc.getElementById('link_'+nrstr).href=testlink;
	var arrow = doc.getElementById('arrow_'+nrstr).src;
	var arrow_array = arrow.split("/");
	//alert(arrow_array[6]);
	if(arrow_array[6]=="arrow_hl.gif" || arrow_array[6]=="arrow_right_hl.gif"){
			doc.getElementById('arrow_'+nrstr).src="/tipdoo/img/startpage_elemente/arrow_right_hl.gif";} else {
			doc.getElementById('arrow_'+nrstr).src="/tipdoo/img/startpage_elemente/arrow_right.gif";}
	
	}
	
	if(ng) {
		
		if(mnew != menuvis && doc.getElementById('menu_'+menuvis+'A').style.height=='110px') {
			smoothSlideDown('menu_'+menuvis+submenuvis,0,110);
			//doc.getElementById('menu_'+menuvis+submenuvis).style.height='0px';
			//doc.getElementById('menu_'+menuvis+submenuvis).style.visibility='hidden';
			//smoothSlideDown('menu_'+menuvis+submenuvis,0,110);
			//doc.getElementById('menu_'+menuvis+'A').style.height='0px';
			doc.getElementById('menu_'+menuvis+'A').style.visibility='hidden';
			//doc.getElementById('image_'+menuvis+submenuvis).style.visibility='collapse';
			doc.getElementById('image_'+menuvis+'A').style.visibility='hidden';
			var arrowright=doc.getElementById('arrow_'+menuvis+'A').src;
			var arrowr_array = arrowright.split("/");
			if(arrowr_array[6]=="arrow_right_hl.gif"){
			doc.getElementById('arrow_'+menuvis+'A').src="/tipdoo/img/startpage_elemente/arrow_hl.gif";} else {
			doc.getElementById('arrow_'+menuvis+'A').src="/tipdoo/img/startpage_elemente/arrow.gif";}
			doc.getElementById('link_'+nrstr).href="#";
		}
		if(submenuvis != 'A') {
			doc.getElementById('menu_'+menuvis+submenuvis).style.visibility='hidden';
			doc.getElementById('image_'+menuvis+submenuvis).style.visibility='hidden';
			doc.getElementById('arrow_'+menuvis+submenuvis).src="/tipdoo/img/startpage_elemente/arrow.gif";
		}
		
		
	}
	
	if (nrstr=='FA') {
	showElements();
}
	menuvis = mnew;
  submenuvis = submnew;
  var neuel = mnew+submnew;
  if(spin!=null){
  	spin = setInterval(function(){carrousel(neuel);},6000);
  }
  
}

function carrousel(elem)	{
	var tst=elem;
	clearInterval(spin);
		switch (tst){
			
		case 'AA':	
		spin = setInterval(function(){carrousel(elem);},6000);
		menuup('BA');
		elem='BA';
		break;
		
		case 'BA':
		spin = setInterval(function(){carrousel(elem);},6000);
		menuup('CA');
		elem='CA';
		break;
		
		case 'CA':
		spin = setInterval(function(){carrousel(elem);},6000);
		menuup('DA');
		elem='DA';
		break;
		
		case 'DA':
		spin = setInterval(function(){carrousel(elem);},6000);
		menuup('EA');
		elem='EA';
		break;
		
		case 'EA':
		spin = setInterval(function(){carrousel(elem);},6000);
		menuup('FA');
		elem='FA';
		break;
		
		case 'FA':
		spin = setInterval(function(){carrousel(elem);},6000);
		menuup('AA');
		elem='AA';
		break;
		
	}
		
}

