var Menschel = {
	cubic: function(pos) {
		pos /= 0.5; return pos<1 ? 0.5*pos*pos*pos : 0.5*((pos-2)*(pos-2)*(pos-2)+2);
	}
};



function showArrangement() {
	if($('bournout_infos').getHeight() <= 0) {
		$('bournout_infos').setStyle({
			display: 'block',
			borderBottom: '1px solid #fff'
		});
		new Effect.Morph('bournout_infos', {
			style: 'height: 550px',
			duration: 0.5,
			delay: 0
		});	
		Effect.ScrollTo('bournout_infos');
	} else {
		new Effect.Morph('bournout_infos', {
			style: 'height: 0px',
			duration: 0.5,
			delay: 0,
			afterFinish: function() {
				$('bournout_infos').setStyle({
					display: 'none',
					borderBottom: 'none'
				});					
			}
		});	
	}
}


function showArrangement2() {
	if($('senses_infos').getHeight() <= 0) {
		$('senses_infos').setStyle({
			display: 'block',
			borderBottom: '1px solid #fff'
		});
		new Effect.Morph('senses_infos', {
			style: 'height: 550px',
			duration: 0.5,
			delay: 0
		});
		Effect.ScrollTo('senses_infos');
	} else {
		new Effect.Morph('senses_infos', {
			style: 'height: 0px',
			duration: 0.5,
			delay: 0,
			afterFinish: function() {
				$('senses_infos').setStyle({
					display: 'none',
					borderBottom: 'none'
				});					
			}
		});	
	}
}


function showPlayHelp(obj, pos) {
	new Effect.Move('button_play_slideshow',{x:-105,y:0,transition:Effect.Transitions.linear,duration:0.2,delay:0});
	new Effect.Move('button_play_slideshow_background',{x:-105,y:0,transition:Effect.Transitions.linear,duration:0.2,delay:0});
}

function hidePlayHelp() {
	new Effect.Move('button_play_slideshow',{x:105,y:0,transition:Effect.Transitions.linear,duration:0.2,delay:0});
	new Effect.Move('button_play_slideshow_background',{x:105,y:0,transition:Effect.Transitions.linear,duration:0.2,delay:0});
}

function showStopHelp(obj, pos) {
	new Effect.Move('button_stop_slideshow',{x:-137,y:0,transition:Effect.Transitions.linear,duration:0.2,delay:0});
	new Effect.Move('button_stop_slideshow_background',{x:-137,y:0,transition:Effect.Transitions.linear,duration:0.2,delay:0});
}

function hideStopHelp() {
	new Effect.Move('button_stop_slideshow',{x:137,y:0,transition:Effect.Transitions.linear,duration:0.2,delay:0});
	new Effect.Move('button_stop_slideshow_background',{x:137,y:0,transition:Effect.Transitions.linear,duration:0.2,delay:0});
}

function hideSlideshow() {
	
	new Effect.Morph('teaser', {
		style: 'height: 240px',
		duration: 1.5,
		delay: 0.0
	});
	
	new Effect.Opacity('overlay',{duration:1.5,from:0.4,to:0.0,transition:Effect.Transitions.linear,delay:0.0});
	
	new Effect.Move('teaser-body',{x:-300,y:0,transition:Effect.Transitions.linear,duration:0.5,delay:1.5});
	$('button_play_slideshow').show();
	$('button_play_slideshow_background').show();	
	
	
}



function showSlideshow() {
	/*new Effect.Opacity('button_play_slideshow',{duration:0.2,from:1,to:0.0,transition:Effect.Transitions.linear,delay:0});
	new Effect.Opacity('button_play_slideshow_background',{duration:0.2,from:0.4,to:0.0,transition:Effect.Transitions.linear,delay:0});*/
	
	$('button_play_slideshow').hide();
	$('button_play_slideshow_background').hide();

	
	new Effect.Move('teaser-body',{x:300,y:0,transition:Effect.Transitions.linear,duration:0.5,delay:0});
	
	new Effect.Morph('teaser', {
		style: 'height: 449px',
		duration: 1.5,
		delay: 0.7
	});
	new Effect.Opacity('overlay',{duration:1.5,from:0.0,to:0.4,transition:Effect.Transitions.linear,delay:0.7});
	
	

	new Effect.Opacity('teaserimage2',{duration:1.0,from:1.0,to:0.0,transition:Effect.Transitions.linear,delay:5});
	new Effect.Move('teaserimage2',{x:20,y:0,transition:Effect.Transitions.linear,duration:2,delay:5});


/*	new Effect.Opacity('teaserimage1',{duration:1.8,from:0.0,to:0.15,transition:Effect.Transitions.linear});*/
	new Effect.Opacity('teaserimage1',{duration:1.0,from:0.0,to:1.0,transition:Effect.Transitions.linear,delay:5});
	new Effect.Move('teaserimage1',{x:-20,y:0,transition:Effect.Transitions.linear,duration:1,delay:5});
	
	//new Effect.Move('teaser-body',{x:-300,y:0,transition:Effect.Transitions.spring,duration:0.8,delay:6});
	
	
	
	/*new Effect.Opacity('teaserimage2',{duration:1.8,from:0.0,to:0.15,transition:Effect.Transitions.linear});
	new Effect.Opacity('teaserimage2',{duration:1.0,from:0.15,to:0.0,transition:Menschel.cubic,delay:1.8});
	new Effect.Move('teaserimage2',{x:-80,y:0,transition:Effect.Transitions.linear,duration:3.8,delay:0.8});
*/	
}

// array with anonymous init-functions
var initFunctions = new Array();

// big standard-initfunction
initFunctions.push(function(){


});


function adjustShadowLayout() {
	var cnt_height = document.getElementById("page-section").offsetHeight;
	var win_height = (window.innerHeight)? window.innerHeight :document.body.clientHeight;
	var cnt_height = parseFloat(cnt_height);
	var win_height = parseFloat(win_height);
	var height = $('page-section').getHeight() + "px";
	var sl = document.getElementById("sh-left");
	if(sl) sl.style.height = height;
	var sr = document.getElementById("sh-right");
	if(sr) sr.style.height = height;
	//correctPagefooter();
}


function correctPagefooter() {
	// correct pagefooter
	var pf = $('page-footer');
	if (pf){
		var arrayPageSize = getPageSize();
		var height = pf.getHeight();
		var arrayOffset = pf.cumulativeOffset();
		if (arrayOffset[1]+height<arrayPageSize[1]){
			pf.setStyle({position: 'relative', top: (arrayPageSize[1] - arrayOffset[1] - height) + 'px'})
		}
	}
}


/* calculates content-dimensions */
function getPageSize(){

  var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	// using Prototype's viewport measurement instead of proprietary one above
	windowWidth = document.viewport.getWidth();
	windowHeight = document.viewport.getHeight();


	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}




/* initializing on dom:loaded... */
document.observe('dom:loaded', function(){
	if (!window._init){
		window._init = true;
		for (var i=0; i<initFunctions.length; i++) initFunctions[i]();				
	}
});
/* ...  or if not available also window.load */
Event.observe(window, 'load', function(){
	if (!window._init){
		window._init = true;
		for (var i=0; i<initFunctions.length; i++) initFunctions[i]();
	} 
});
