﻿window.onresize = new Function("fixScroll(); resizeScroll();");

// R.L. (17.08.2011)
function queryString(pName) {
	var tempURL = window.location.search.substring(1);
	var tempParameters = tempURL.split("&");

	for (i=0;i<tempParameters.length;i++){
		var tempParameter = tempParameters[i].split("=");

		if (tempParameter[0] == pName) return String(tempParameter[1]);}

	return '';}
// R.L. (17.08.2011) -->

var mAnimate = -1;
function initSubNavigation(Animate) {
	Animate = Animate ? Animate : mAnimate == -1;

	var links = document.getElementsByTagName('a');
	var navoverlay = document.getElementById('navoverlay');
	var subnav = document.getElementById('subnavigation');
	var active;
	for(var i=0;i<links.length;i++) {
		if(links[i].className == "mainactive") {
			active = links[i];
			break;
		}
	}
	if(active == null) {
		return;
	}
	var linknum = active.id;
	var bgurl
	linknum = linknum.replace('mainnav','');
	bgurl = '/images/hauptnavigation_over_0' + linknum + '.png';
	navoverlay.style.top = parseInt(getStyle(active,"top")) - 3 + 'px';
	navoverlay.style.display = 'block';
	if(Animate) {
		subnav.style.width = '0px';	
		subnav.style.display = 'block';
		subnav.style.backgroundImage = "url('" + bgurl + "')";
		showNavAnimation(subnav);
	} else {
		subnav.style.display = 'block';
		subnav.style.backgroundImage = "url('" + bgurl + "')";
	}
}

function checkNews() {
	if(document.location != 'index.html') {
		fixAbsolutePosition();
	}
}

function initNews() {
	var news = document.getElementById('newswrapper');
	news.style.marginTop = (news.scrollHeight * -1) + 'px';
	news.style.height = news.scrollHeight + 'px';
	showNews(document.getElementById('newsbutton'));}	

function fixAbsolutePosition() {
	document.getElementById('newswrapper').style.position = 'absolute';
}

function showNavAnimation(obj) {
	$(obj).animate(
		{ width: '1003px' }, {
			duration: 800,
			easing: 'easeOutCubic' 
		});
}

function showNewsAnimation(news, newsbutton) {
	$(news).animate(
		{ marginTop: '0px' }, {
			duration: 1000,
			easing: 'easeOutBack'
	});
	$(newsbutton).animate(
		{ top: news.scrollHeight + 'px' }, {
			duration: 1000,
			easing: 'easeOutBack'
	});
	
}
function hideNewsAnimation(news, newsbutton) {
	var margTop = news.scrollHeight * -1;
	$(news).animate(
		{ marginTop: margTop + 'px' }, {
			duration: 1000,
			easing: 'easeOutBack' 
	});
	$(newsbutton).animate(
		{ top: '0px' }, {
			duration: 1000,
			easing: 'easeOutBack' 
	});
	
}

// R.L. (04.08.2011)
function showContentBoxAnimation(obj) {
	$(obj).animate(
		{ 	height: obj.scrollHeight
		},
		{
			duration: 400,
			easing: 'easeOutExpo'		
		}	
	);
}

function hideContentBoxAnimation(obj) {
	$(obj).animate(
		{ 	borderTopWidth: '0px',
			borderBottomWidth: '0px',
			height: '0px'
		},
		{
			duration: 400,
			easing: 'easeOutExpo'	
		}	
	);
}

function hideNews(obj) {
	obj.onclick = new Function("showNews(this);");
	obj.src = '/images/button_news_01.png';
	hideNewsAnimation(document.getElementById('newswrapper'), document.getElementById('newsbuttonwrapper'));
	resizeScroll();
}

function showNews(obj) {
	obj.onclick = new Function("hideNews(this);");
	obj.src = '/images/button_news_02.png';
	showNewsAnimation(document.getElementById('newswrapper'), document.getElementById('newsbuttonwrapper'));
	resizeScroll();
}

// R.L. (15.08.2011)
function showContentBoxTitle(obj) {
	obj.onclick = new Function("hideContentBoxTitle(this);");
	obj.innerHTML = obj.innerHTML.replace('pfeil_01.png', 'pfeil_02.png');

	setTimeout('minimizeAllContentBoxes("' + obj.id + '");', 10);

	var exdiv = obj.parentNode;
	var divs = exdiv.getElementsByTagName('div');
	var exdivwrapper;
	for(var i=0;i<divs.length;i++) {
		if(divs[i].className == "expandabledivwrapper") {
			exdivwrapper = divs[i];
			break;
		}
	}	
	showContentBoxAnimation(exdivwrapper);}

function hideContentBoxTitle(obj) {
	obj.onclick = new Function("showContentBoxTitle(this);");
	obj.innerHTML = obj.innerHTML.replace('pfeil_02.png', 'pfeil_01.png');

	var exdiv = obj.parentNode;
	var divs = exdiv.getElementsByTagName('div');
	var exdivwrapper;
	for(var i=0;i<divs.length;i++) {
		if(divs[i].className == "expandabledivwrapper") {
			exdivwrapper = divs[i];
			break;
		}
	}	
	hideContentBoxAnimation(exdivwrapper);}

function minimizeAllContentBoxes(uID) {
	var divs = document.getElementsByTagName('div');
	for(var i=0;i<divs.length;i++) {
		if(divs[i].className == 'expandabledivwrapper' && parseInt(divs[i].style.height) > 0) {
			if(divs[i].parentNode.getElementsByTagName('h1')[0].id != uID)
				hideContentBoxTitle(divs[i].parentNode.getElementsByTagName('h1')[0]);}}}

function fixScroll() {
	var wrap = document.getElementById('scrollwrapper');
	var width = document.documentElement.offsetWidth;
	if(wrap != null) {
		wrap.style.width = (width - 60) + 'px';
	}
}

function getStyle(x,styleProp)
{
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function changeImage(elem, imgurl) {
	var img = elem.getElementsByTagName('img')[0];
	if(img != null) {
		img.src = imgurl;
	}
}

function mitarbeiterSwitchActive(elem) {
	var mitarbeiter = (elem.parentElement) ? elem.parentElement : elem.parentNode;
	var divs = mitarbeiter.getElementsByTagName('div');
	var contentwide;
	for(var i=0;i<divs.length;i++) {
		if(divs[i].className == "contentwide") {
			contentwide = divs[i];
			break;
		}
	}
	if(contentwide == null) {
		return;
	}
	
	mitarbeiterCollapseAll();	
	
	contentwide.style.display = 'block';
	var mitarbeiter = (contentwide.parentElement) ? contentwide.parentElement : contentwide.parentNode;
	$(mitarbeiter).animate( 
		{
			width: '288px'
		},
		{
			duration: 475
			//easing: 'easeOutExpo'
		}
	);
}

function mitarbeiterCollapseAll() {
	var divs = document.getElementById('team').getElementsByTagName('div');
	var mitarbeiter = new Array();
	var count = 0;
	for(var i=0;i<divs.length;i++) {
		if(divs[i].className == 'mitarbeiter') {
			mitarbeiter[count] = divs[i];
			count++;
		}
	}
	for(var i=0;i<mitarbeiter.length;i++) {
		$(mitarbeiter[i]).animate( 
			{
				width: '48px'
			},
			{
				duration: 400
			}
		);
		var childdivs = mitarbeiter[i].getElementsByTagName('div');
		for(var j=0;j<childdivs.length;j++) {
			if(childdivs[j].className == 'contentwide') {
				childdivs[j].style.display = 'none';
				break;
			}
		}
	}
}

function initReferenzBilder() {
	var content = document.getElementById('referenceviewercontent');
	var children = content.getElementsByTagName('img');
	var width = children.length * 375;
	content.style.width = width + 'px';

	// R.L. (24.08.2011): Transparent Arrows
	var min = (content.getElementsByTagName('img').length -1) * 375 * -1;
	var tempTotal = (min / 375 * -1);
	setReferenzNavigation(0, Math.round(tempTotal));}

// R.L. (11.08.2011)
var mBlocked = false;
var mReferenceElementWidth = 375;

function navigateToReferenz(pImage){
	if((pImage) && (!isNaN(pImage.title))){
		var tempContent = document.getElementById('referenceviewercontent');
		var tempMin = (tempContent.getElementsByTagName('img').length - 1) * mReferenceElementWidth * - 1;
		var tempCurrent = !isNaN(parseInt(tempContent.style.left)) ? (parseInt(tempContent.style.left)) * -1 / mReferenceElementWidth : 0;
		var tempTo = parseInt(pImage.title);
		var tempTotal = (tempMin / 375 * -1);

		if(tempTo != tempCurrent){
			mBlocked = true;
			var tempMove = ((tempCurrent * mReferenceElementWidth) + ((tempTo - tempCurrent) * mReferenceElementWidth)) * - 1 + 'px';

			$(tempContent).animate( 
				{
					left: tempMove
				},
				{
					duration: 1000,
					easing: 'easeOutBack',
					complete: function()
					{
						mBlocked = false;
						setReferenzenBilderStatus(Math.round(tempTo));
						setReferenzLink(Math.round(tempTo));
						setReferenzNavigation(Math.round(tempTo), tempTotal);
					}
				}
			);}}}

function moveReferenzBilder(direction) {
	if(!mBlocked){
		mBlocked = true;

		var content = document.getElementById('referenceviewercontent');
		var min = (content.getElementsByTagName('img').length -1) * 375 * -1;
		var tempLeft = parseInt(content.style.left);
		var left = (!isNaN(tempLeft)) ? tempLeft : 0;

		left = (direction == 'back') ? left + 375 : left - 375;
		left = (left > 0) ? 0 : left;
		var target = (left < min) ? min : left
		var num = target * -1 / 375;
		var tempTotal = (min / 375 * -1);


		// R.L. (11.08.2011)
		setReferenzenBilderStatus(Math.round(num));
		setReferenzLink(Math.round(num));
		setReferenzNavigation(Math.round(num), Math.round(tempTotal));
	
		target = target + 'px';
		$(content ).animate( 
			{
				left: target
			},
			{
				duration: 1200,
				easing: 'easeOutBack',
				complete: function()
				{
					mBlocked = false
				}
			}
		);}}

function setReferenzenBilderStatus(num) {
	var images = document.getElementById('referencestatus').getElementsByTagName('img');
	for(var i=0;i<images.length;i++) {
		if(i == num) {
			images[i].src = '/images/kreis_on_referenzen_detail.png';
		} else {
			images[i].src = '/images/kreis_referenzen_detail.png';
		}
	}
}

// R.L. (24.08.2011)
function setReferenzNavigation(pNumber, pTotal){
	var tempLeft = document.getElementById('referenceleft');
	var tempRight = document.getElementById('referenceright');

	if(tempLeft && pNumber == 0) tempLeft.className = 'transparent50';
	if(tempLeft && pNumber > 0) tempLeft.className = '';

	if(tempRight && pNumber == pTotal) tempRight.className = 'transparent50';
	if(tempRight && pNumber < pTotal) tempRight.className = '';}


// R.L. (09.08.2011, 11.08.2011)
// R.L. (09.08.2011, 17.08.2011): Linebreak after 19.
var mLineAmount = 19;
function setupImages(pCount){
	mLinkList = mLinkList.split(';');
	pCount = pCount ? pCount : 3;

	var tempCIElement = document.getElementById('clientURLImage');
	var tempCDElement = document.getElementById('referencestatus');

	if(tempCIElement && tempCDElement){
		var tempCIImages = tempCIElement.getElementsByTagName('img');
		var tempDEImages = tempCDElement.getElementsByTagName('img');

		var tempCount = tempCIImages.length;
		for(var i = 1; i < (tempCount - pCount + 1); i++){
			if(tempCIImages[tempCIImages.length - 1])
				tempCIElement.removeChild(tempCIImages[tempCIImages.length - 1]);}

		var tempCount = tempDEImages.length;
		for(var j = 0; j < tempCount; j++){
			tempDEImages[j].onclick = function(){navigateToReferenz(this);}
			tempDEImages[j].title = j;}

		for(var j = 1; j < (tempCount - pCount + 1); j++){
			if(tempDEImages[tempDEImages.length - 1])
				tempCDElement.removeChild(tempDEImages[tempDEImages.length - 1]);}

		if(tempDEImages.length > mLineAmount){
			var tempInsert = document.createElement('br');
			tempCDElement.insertBefore(tempInsert, tempDEImages[mLineAmount]);
			tempDEImages[mLineAmount].style.marginLeft = ((20 * mLineAmount) - 20 * (tempDEImages.length - mLineAmount) + 7) + 'px';}}}

// R.L. (10.08.2011, 12.08.2011)
// R.L. (18.08.2011): Angepasst (Höhe flexibel nach Elementen berechnen).
var mContentHeight = 0;
function resizeScroll(){
	resizeScroll2();
	return false;

	if (mContentHeight == 0) mContentHeight = document.getElementById('contenthome') ? document.getElementById('contenthome').offsetHeight : 432;

	var tempContentHeight = mContentHeight; // 432;
	var tempContent = document.getElementById('contenthome');
	var tempNews = document.getElementById('newswrapper');
	var tempNewsHeight = tempNews ? parseInt(tempNews.style.marginTop) * -1 : 0;
	var tempKioskHeight = document.getElementById('kioskHome') ? document.getElementById('kioskHome').offsetHeight : 0;

	if(tempContent){
		tempContent.style.height = (document.body.offsetHeight - tempContent.offsetTop - 120) + 'px';

		var tempNewsHeight = ((tempContent.offsetHeight - tempNewsHeight) >= tempContentHeight) ? tempNewsHeight : (tempContent.offsetHeight - tempNewsHeight);
		var tempNewsHeight = isNaN(tempNewsHeight) ? 0 : tempNewsHeight;
		var tempHeight = (parseInt(tempContent.style.height) - tempNewsHeight) >= tempContentHeight ? (parseInt(tempContent.style.height) - tempNewsHeight) : tempContentHeight;

		tempContent.style.height = tempHeight + 'px';}}

// Copied (http://james.padolsey.com/javascript/get-document-height-cross-browser/)
function getDocHeight() {
    var D = document;

    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );}

// R.L. (18.08.2011): Angepasst (Höhe flexibel nach Elementen berechnen).
function resizeScroll2(){
	var tempContent =  document.getElementById('contenthome');
	var tempContentInner =  document.getElementById('contentHomeInner');
	var tempFooter = document.getElementById('Footer');
	var tempNews = document.getElementById('newswrapper');
	var tempNewsMargin = isNaN(parseInt(tempNews.style.marginTop)) ? 0 : parseInt(tempNews.style.marginTop) * -1;

	if(tempContent && tempFooter){
		var tempHeightDifference = document.body.offsetHeight - tempContent.offsetTop - tempFooter.offsetHeight + (tempNewsMargin <= 0 ? tempNews.offsetHeight : 0);
		var tempHeightMin = tempContentInner.offsetHeight + tempFooter.offsetHeight;
		var tempHeightAddition = (getDocHeight() - tempFooter.offsetTop - tempNewsMargin - 40);
		var tempHeightAddition = tempHeightAddition > 0 ? tempHeightAddition : (getDocHeight() - tempFooter.offsetTop - 40);

		tempHeightDifference = tempHeightDifference < tempHeightMin ? tempContentInner.offsetHeight + tempHeightAddition : tempHeightDifference;
		tempContent.style.height = tempHeightDifference + 'px';}}

// R.L. (11.08.2011)
function setReferenzLink(pIndex){
	pIndex = pIndex ? pIndex + 1: 1;

	var tempLink = document.getElementById('clientURL');
	var tempLinkImage = document.getElementById('clientURLImage');

	if((tempLink) && (mLinkList[0])){
		for(i = 0;i < mLinkList.length; i++){
			if(mLinkList[i].split('#')[0] == pIndex){
				tempLink.href = mLinkList[i].split('#')[1];
				tempLink.innerHTML = mLinkList[i].split('#')[1].replace('http://', '');
				break;}}

		if(tempLinkImage) tempLinkImage.href = tempLink.href;}}

// R.L. (12.08.2011)
function setupFacebook(pReplace){
	pReplace = pReplace ? pReplace : 'YOUR_URL';
	var tempElement = document.getElementById('fbButton');

	if(tempElement) tempElement.setAttribute('href', this.location);}


// R.L. (19.08.2011)
Array.prototype.shuffle = function arrayShuffle(){
	var tmp, rand;

	for(var i =0; i < this.length; i++){
		rand = Math.floor(Math.random() * this.length);
		tmp = this[i]; 
		this[i] = this[rand]; 
		this[rand] = tmp;}}

function shuffleArray(pArray){
	if(pArray){
		var tempArray = new Array(pArray.length);
		var tempCopy = new Array(pArray.length);

		for(i = 0; i < pArray.length; i++){
			tempCopy[i] = pArray[i];
			tempArray[i] = pArray[i].title;};

		tempArray.shuffle();

		for(j = 0; j < pArray.length; j++){
			var tempIndex = tempArray[j];
			pArray[j].src = tempCopy[tempIndex - 1].src
			pArray[j].title = tempCopy[tempIndex - 1].title;}}};

// R.L. (15.08.2011)
var mKioskDuration = 4000;
var mKioskInterval = null;

function setupKioskReference(pImageHeight){
	var tempContainer = document.getElementById('kioskSliderFalse');

	if(tempContainer){
		var tempImages = tempContainer.getElementsByTagName('img');

		var tempCount = tempImages.length;
		for(var i = 1; i < tempCount; i++){
			if(tempImages[tempImages.length - 1].src.search('0000-0000-0000') >= 0){
				tempContainer.removeChild(tempImages[tempImages.length - 1]);}}

		// R.L. (19.08.2011): Identify items.
		var tempImages = tempContainer.getElementsByTagName('img');
		var tempCount = tempImages.length;
		for(var i = 0; i < tempCount; i++)
			tempImages[i].title = (i + 1);

		// R.L. (19.08.2011): Sort
		shuffleArray(tempImages);

		if((tempImages) && (tempImages.length > 1)){
			pImageHeight = pImageHeight ? pImageHeight : 75;
			//tempContainer.style.top = ((pImageHeight * (tempImages.length - 1)) * -1) + 'px';
			tempContainer.style.top = '0px';

			// R.L. (17.08.2011): First Link & Reveresed flow direction.
			if((mKioskLinkList) && (typeof mKioskLinkList == 'string')){
				mKioskLinkList = mKioskLinkList.split(';');

				if(mKioskLinkList && mKioskLinkList[0]){
					var tempElement = document.getElementById('kioskReferenceLinkFalse');
					if(tempElement){
						tempElement.href = mKioskLinkList[parseInt(tempImages[0].title) - 1].split('#')[1];}}}


			window.setInterval("slideKioskReference(" + tempImages.length + ", " + pImageHeight + ")", mKioskDuration);}}}

// R.L. (17.08.2011): Reveresed flow direction.
function slideKioskReference(pLength, pImageHeight){
	var tempContainer = document.getElementById('kioskSliderFalse');
	var tempNumber = (parseInt(tempContainer.style.top) * -1) / pImageHeight;

	if((tempContainer) && (parseInt(tempContainer.style.top) * -1 < (pLength - 1) * pImageHeight)){
		var tempTop = (parseInt(tempContainer.style.top) - pImageHeight) + 'px';
		var tempImage = tempContainer.getElementsByTagName('img')[tempNumber + 1];

		$(tempContainer).animate({
				top: tempTop
			},
			{
				duration: mKioskDuration / 4,
				easing: 'easeOutCubic',
				complete: function()
				{
					setKioskReferenceLink(tempImage)
				}
			});}
	else
		tempContainer.style.top = '0px';}
		//window.clearInterval(mKioskInterval);}

// R.L. (17.08.2011)
function setKioskReferenceLink(pImage){
	if(mKioskLinkList && mKioskLinkList[0]){
		pIndex = pImage ? parseInt(pImage.title) : 1;

		var tempElement = document.getElementById('kioskReferenceLinkFalse');
		if(tempElement){
			for(i = 0;i < mKioskLinkList.length; i++){
				if(mKioskLinkList[i].split('#')[0] == pIndex){
					tempElement.href = mKioskLinkList[i].split('#')[1];
					break;}}}}}

function preOpenArea(pIndex){
	if(pIndex){
		var mArea = document.getElementById(pIndex);
		if(mArea){ showContentBoxTitle(mArea);}}}

// R.L. (19.08.2011)
function setupTeamBackground(){
	var tempElement = document.getElementById('team');

	if(tempElement)
		tempElement.className = 'team' + (Math.round(Math.random() * 2) + 1);}

function preOpenAreaOnPostBack(pIsPostBack){
	if(pIsPostBack){
		var divs = document.getElementsByTagName('div');
		for(var i=0;i<divs.length;i++) {
			if(divs[i].className == 'expandabledivwrapper'){
				showContentBoxTitle(divs[i].parentNode.getElementsByTagName('h1')[0]);
				return;}}}}
