

var currentVisibleTab = null;
var currentVisibleFullContent = null;
var currentActiveTab = null;
var currentTabColor = null;

var mehrImg = null;
var schliessenImg = null;

var defaultTab = 'tab01';


function init() {
	currentActiveTab = document.getElementById(defaultTab);
	currentVisibleTab = document.getElementById('tab01Content');
	currentVisibleFullContent = document.getElementById('tab01FullContent');
	if(location.search != '') {
		var wertestring = location.search.slice(1);
		var paare = wertestring.split("&");
		var paar, name, wert;
		for (var i = 0; i < paare.length; i++) {
			paar = paare[i].split("=");
			name = paar[0];
			wert = paar[1];
			name = unescape(name).replace("+", " ");
			wert = unescape(wert).replace("+", " ");
			if(name == 'showTab' && wert != defaultTab) {
				toggleTab(document.getElementById(wert));
			}
			if(name == 'fulltext' && wert == 'opened') {
				toggleBottomSlider('open') ;
			}
			
	  }
	}
}


var wmtt = null; 
    
function updateWMTT(e) { 
	if (wmtt == null) { 
		wmtt = document.getElementById('tooltip'); 
	} 
	if (wmtt != null) {
		x = (document.all) ? window.event.x + wmtt.offsetParent.scrollLeft : e.pageX; 
		y = (document.all) ? window.event.y + wmtt.offsetParent.scrollTop  : e.pageY; 
		
		if(checkBrowserName('MSIE')) {
			var mainDiv = document.getElementById('MainDiv');
			
			pos = findPos(mainDiv);
			x += pos[0];
			y += pos[1]+80;
		}
		
        wmtt.style.left = (x - 30) + "px"; 
        wmtt.style.top   = (y + 20) + "px"; 
	} 
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}
	
	
document.onmousemove = updateWMTT;

    
function showWMTT(tabId) {
	if(wmtt == null)
		return;
	if(tabId == "tab01") 
		wmtt.firstChild.data = tooltipTab01;
	else if(tabId == "tab02") 
		wmtt.firstChild.data = tooltipTab02;
	else if(tabId == "tab03") 
		wmtt.firstChild.data = tooltipTab03;
	else if(tabId == "tab04") 
		wmtt.firstChild.data = tooltipTab04;
	else if(tabId == "tab05") 
		wmtt.firstChild.data = tooltipTab05;
	else if(tabId == "tab06") 
		wmtt.firstChild.data = tooltipTab06;
	else
		wmtt.firstChild.data = "Kein ToolTip verfuegbar.";
	wmtt.style.display = "block"; 
}

function hideWMTT() { 
	wmtt.style.display = "none"; 
}


function startGallery() {
		var myGallery = new gallery($('myGallery'), {
        timed: true,			/* Aktivieren des automatischen Bilderdurchlaufs. */
        showArrows: false,		/* Zeigt Pfeile zum manuellen Durchblättern der Bilder. */
        showCarousel: false,	/* Zeigt eine Minigalerie aller Bilder.  */
		embedLinks: false,		/* Ob ein Link aktiv ist oder nicht. */
        delay: 10000				/* Zeit bis nächster Bildwechsel in Millisekunden.*/
	});
}
window.addEvent('domready', startGallery);


function initReady(fn) { 
	// W3C-compliant browser 
	if (document.addEventListener) { 
		document.addEventListener("DOMContentLoaded", fn, false); 
	}               
	else { 
		document.onreadystatechange = function() { 
			readyState(fn) 
 		} 
	} 
}

// IE execute function 
function readyState(func) { 
	// DOM is ready 
	if (document.readyState == "interactive" 
		|| document.readyState == "complete") { 
		try { 
			func(); 
		}catch(e) {} 
    } 
}

window.onDomReady = initReady;

// execute as soon as DOM is loaded 
 window.onDomReady(init);
 //window.onDomReady(startGallery);

function toggleTab(tab) {
	if(currentVisibleTab != null) {
		currentVisibleTab.style.display = 'none';
		currentVisibleTab = null;
	}
	
	if(currentVisibleFullContent != null) {
		currentVisibleFullContent.style.display = 'none';
		currentVisibleFullContent = null;
	}

	if (currentActiveTab != null) {
		updateTabImg(currentActiveTab, tabPrefix + currentActiveTab.id + '_color.png');
		currentActiveTab = null;
	}
	
	currentVisibleTab = document.getElementById(tab.id + "Content");
	if(currentVisibleTab != null)
		currentVisibleTab.style.display = 'block';
	currentVisibleFullContent = document.getElementById(tab.id + "FullContent");
	if(currentVisibleFullContent != null) {
		currentVisibleFullContent.style.display = 'block';
	}

	currentActiveTab = tab;
	updateTabImg(currentActiveTab, tabPrefix + currentActiveTab.id + '_color_active.png');
}

function updateTabImg(tab, imgFile) {
	img = tab.getElementsByTagName('img') [0];
	if(img == null)
		return;
	img.src = 	img.src.substring(0, img.src.lastIndexOf('/')) + '/' + imgFile;
}

function highLightTab(tab, enter) {
	if(enter) {
		if(tab.id != currentActiveTab.id)
			updateTabImg(tab, tabPrefix + tab.id + '_color_active.png');
	} else {
		if(tab.id != currentActiveTab.id)
			updateTabImg(tab, tabPrefix + tab.id + '_color.png');
	}
	
}

function toggleBottomSlider(type) {
	if(mehrImg == null) {
		mehrImg = document.getElementById('bottomSliderButtonImg');
		src = mehrImg.src;
		schliessenImg = new Image();
		schliessenImg.src = mehrImg.src.substring(0, mehrImg.src.lastIndexOf('/'))+'/schliessen.jpg';
		mehrImg = new Image();
		mehrImg.src = src;
	}
	var slider = document.getElementById('bottomSlider');
	if ((type == 'close' || type == 'toggle') && slider.style.display == 'block') {
		slider.style.display = 'none';
		document.getElementById('bottomSliderButtonImg').src = mehrImg.src;
	} else if(type == 'open' || type == 'toggle') {
		slider.style.display = 'block';
		document.getElementById('bottomSliderButtonImg').src = schliessenImg.src;
	}
}

function getBottomSliderType() {
	var slider = document.getElementById('bottomSlider');
	if(slider.style.display == 'block')
		return 'opened';
	else
		return 'closed';
}

function openSite(file, tab) {
	var url = document.URL.substring(0, document.URL.lastIndexOf('/'));
	
	url = url + '/' + file;
	url = url + '?';
	if(tab != '')
		window.location.href = url + "showTab=" + tab + "&fulltext=" + getBottomSliderType();
	else 
		window.location.href = url + "fulltext=" + getBottomSliderType();

}

function checkBrowserName(name){  
   var agent = navigator.userAgent.toLowerCase();  
   if (agent.indexOf(name.toLowerCase())>-1) {  
     return true;  
   }  
   return false;  
 }  
