/*
#///////////////////////////////////////////////////////////////////////#
# Last modified on 02.03.2011					äöüß	#
#///////////////////////////////////////////////////////////////////////#
*/

	var rotatingImagePath = '/.images/rotating/';
	var rotatingImages = new Array();

	// Mainmenu Slider
	var sliderOpen		= new Array();
	var sliderOffset	= new Object();
	sliderOffset.top	= 174;
	sliderOffset.left	= 120;

	var menuOpen		= new Array();
	var menuButton		= new Array();
	var menuTimer		= new Array();

/*
#///////////////////////////////////////////////////////////////////////#
#									#
#///////////////////////////////////////////////////////////////////////#
*/

// thePage = 'home', 'contact', 'praxis', 'behandler', 'leistungen'

function getImagesHeadline (thePage) {

	if (thePage == 'home') {
		rotatingImages = new Array(
			'eingangsbereich-img9869.jpg',
			'empfang-img9933.jpg',
			'gardrobe-img0362.jpg',
			'eingangsbereich-img9784.jpg',
			'eingangsbereich-img0429.jpg',
			'empfang-img9888.jpg'
		);
	}
	else if (thePage == 'contact') {
		rotatingImages = new Array(
			'empfang-img9914.jpg',
			'gardrobe-img0362.jpg',
			'wartezimmer-img9995.jpg'
		);
	}
	else if (thePage == 'praxis') {
		rotatingImages = new Array(
			'beratung-img0166.jpg',
			'wartezimmer-img9995.jpg',
			'beratung-img0029.jpg'
		);
	}
	else if (thePage == 'behandler') {
		rotatingImages = new Array(
			'behandler-img0106.jpg',
			'beratung-img9973.jpg',
			'beratung-img0060.jpg',
			'beratung-img0029.jpg',
			'beratung-img007.jpg'
		);
	}
	else if (thePage == 'leistungen') {
		rotatingImages = new Array(
			'beratung-img9973.jpg',
			'beratung-img0029.jpg',
			'beratung-img0060.jpg',
			'wartezimmer-img9788.jpg',
			'beratung-img0166.jpg',
			'behandler-img0106.jpg',
			'beratung-img007.jpg',
			'wartezimmer-img9995.jpg'
		);
	}
	else {
		rotatingImages = new Array(
			'eingangsbereich-img9869.jpg',
			'behandler-img0106.jpg',
			'beratung-img0029.jpg',
			'beratung-img0060.jpg',
			'beratung-img0166.jpg',
			'beratung-img9973.jpg',
			'beratung-img007.jpg',
			'eingang-img9820.jpg',
			'eingangsbereich-img0429.jpg',
			'empfang-img9888.jpg',
			'empfang-img9933.jpg',
			'empfang-img9914.jpg',
			'gardrobe-img0362.jpg',
			'team-img0332.jpg',
			'team-img0346.jpg',
			'wartezimmer-img9788.jpg',
			'wartezimmer-img9995.jpg'
		);
	}

	if (rotatingImages.length > 1) {
		dojox.image.preload([rotatingImagePath + rotatingImages[1]]);
	}
}

/*
#///////////////////////////////////////////////////////////////////////#
#									#
#///////////////////////////////////////////////////////////////////////#
*/

function rotateImageHeadline () {

	if (imageTimer != false) {
		window.clearTimeout(imageTimer);
		imageTimer = false;
	}


	if (rotatingImages.length > 0) {

		var nextImage = currentImage + 1;
		if ((nextImage+1) > rotatingImages.length) {
			nextImage = 0;
		}

		if (rotatingImages[currentImage] != rotatingImages[nextImage]) {

			dojo.byId('imageSrc1').setAttribute('src', rotatingImagePath + rotatingImages[currentImage]);
			dojo.byId('imageSrc2').setAttribute('src', rotatingImagePath + rotatingImages[nextImage]);

			currentImage = nextImage;

			// Preload the image after next
			if (rotatingImages.length > (nextImage+1)) {
				dojox.image.preload([rotatingImagePath + rotatingImages[nextImage+1]]);
			}

			var img1 = dojo.fadeOut({
				node:		dojo.byId('boxImage1'),
				duration:	1500,
				start:		1,
				end:		0
			});

			var img2 = dojo.fadeIn({
				node:		dojo.byId('boxImage2'),
				duration:	2000,
				start:		0,
				end:		1
			});

			dojo.fx.combine([img1, img2]).play();
		}

		imageTimer = window.setTimeout("rotateImageHeadline()", timerRotatingImages);
	}
}

/*
#///////////////////////////////////////////////////////////////////////#
#									#
#///////////////////////////////////////////////////////////////////////#
*/

function switchMenu (theOption, theMenuId, theSliderId, closeSlider) {

	if (theOption == 'show') {

		// Set the Menu to the starting position of the Slider
		var pos = getPositionOfElement(theSliderId);
		var offset = getPositionOfElement('boxNavigation');
		dojo.byId(theMenuId).style.top = (pos.top - offset.top + sliderOffset.top) +'px';
		dojo.byId(theMenuId).style.left = (pos.left - offset.left + sliderOffset.left) +'px';


		// Close all open slider
		for (var i in menuOpen) {
			if ( (menuOpen[i] == true) && (i != theSliderId) ) {
				if ( menuTimer[theSliderId] ) {
					clearMenuTimeout(i);
				}
				dojo.byId(sliderOpen[i]).style.display = 'none';
				menuOpen[i] = false;
				switchButton(i, false);
			}
		}

		if (menuOpen[theSliderId] != true) {

			// Add the open status
			menuOpen[theSliderId] = true
			sliderOpen[theSliderId] = theMenuId;

			var fade = dojo.fadeIn({
				node:		dojo.byId(theMenuId),
				duration:	150,
				start:		0,
				end:		0.9
			});

			var wipe = dojo.fx.wipeIn({
				node:		dojo.byId(theMenuId),
				easing:		dojo.fx.easing.linear,
				duration:	300
			});

			dojo.fx.combine([fade, wipe]).play();
		}
	}
	else {
		if (menuOpen[theSliderId] == true) {

			// Remove the open status
			menuOpen[theSliderId] = false;

			var fade = dojo.fadeOut({
				node:		dojo.byId(theMenuId),
				duration:	300,
				start:		0.9,
				end:		0,
				beforeBegin:	function () {
					clearMenuTimeout(theSliderId);
				},
				onEnd:		function () {
					dojo.byId(theMenuId).style.display = 'none';
					if (closeSlider == true) {
						switchButton(theSliderId, false);
					}
				}
			});

			var wipe = dojo.fx.wipeOut({
				node:		dojo.byId(theMenuId),
				easing:		dojo.fx.easing.linear,
				duration:	300
			});

			dojo.fx.combine([fade, wipe]).play();
		}
	}
}

/*
#///////////////////////////////////////////////////////////////////////#
#									#
#///////////////////////////////////////////////////////////////////////#
*/

function clearMenuTimeout (theSliderId) {
	window.clearTimeout(menuTimer[theSliderId]);
	menuTimer[theSliderId] = false;
	document.body.onclick = function (event) {};
}

/*
#///////////////////////////////////////////////////////////////////////#
#									#
#///////////////////////////////////////////////////////////////////////#
*/

function setMenuTimeout (theMenuId, theSliderId, closeSlider) {
	if (menuTimer[theSliderId] == false) {
		menuTimer[theSliderId] = window.setTimeout("switchMenu('close','"+ theMenuId +"','"+ theSliderId +"',"+ closeSlider +")", 800);
	}
}

/*
#///////////////////////////////////////////////////////////////////////#
#									#
#///////////////////////////////////////////////////////////////////////#
*/

function switchButton (theObject, theAction) {
	if (menuOpen[theObject] == true) {
		return;
	}


	if ( (theAction == false) && (menuButton[theObject] == true) ) {
		return;
	}
	else if (theAction == false) {
		if (theObject == 's00') {
			dojo.byId(theObject).className = 'button-home-off';
		}
		else if (theObject == 's01') {
			dojo.byId(theObject).className = 'button-praxis-off';
		}
		else if (theObject == 's02') {
			dojo.byId(theObject).className = 'button-leistungen-off';
		}
		else if (theObject == 's03') {
			dojo.byId(theObject).className = 'button-aktion-off';
		}
		else if (theObject == 's04') {
			dojo.byId(theObject).className = 'button-kontakt-off';
		}
		else if (theObject == 's05') {
			dojo.byId(theObject).className = 'button-impressum-off';
		}
	}
	else {
		if (theObject == 's00') {
			dojo.byId(theObject).className = 'button-home-on';
		}
		else if (theObject == 's01') {
			dojo.byId(theObject).className = 'button-praxis-on';
		}
		else if (theObject == 's02') {
			dojo.byId(theObject).className = 'button-leistungen-on';
		}
		else if (theObject == 's03') {
			dojo.byId(theObject).className = 'button-aktion-on';
		}
		else if (theObject == 's04') {
			dojo.byId(theObject).className = 'button-kontakt-on';
		}
		else if (theObject == 's05') {
			dojo.byId(theObject).className = 'button-impressum-on';
		}
	}
}

/*
#///////////////////////////////////////////////////////////////////////#
#									#
#///////////////////////////////////////////////////////////////////////#
*/

function getPositionOfElement (theId) {
	var elem = dojo.byId(theId);
	var tagname = '';

	var position = new Object();
	position.top = 0;
	position.left = 0;

	if ( (typeof elem == 'object') && (typeof elem.offsetTop != 'undefined') ) {
		while (elem && elem.tagName != 'BODY') {
			position.top  += parseInt( elem.offsetTop );
			position.left += parseInt( elem.offsetLeft );
			elem = elem.offsetParent;
		}
	}

	return position;
}

/*
#///////////////////////////////////////////////////////////////////////#
#									#
#///////////////////////////////////////////////////////////////////////#
*/

function DeCo ( e, o, s ) {
	var n = 0;
	var r = '';
	for( var i = 0; i < s.length; i++) {
		n = s.charCodeAt( i );
		if( n >= e ) {
			n = o;
		}
		r += String.fromCharCode( n - 1 );
	}
	return r;
}

function MaToDeCo ( e, o, s ) {
	location.href = DeCo( e, o, 'nbjmup;' ) + DeCo( e, o, s );
}

