var speedOut = 150;
var speedIn = 100;
var waitTime = 50;
var i=1;
var background_effect_speed = 1000;

				
// Von http://www.brain4.de/programmierecke/js/arrayShuffle.php
function arrayShuffle() { // Array mischen
  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;
  }
}
Array.prototype.shuffle = arrayShuffle;


// Zeigt ein Bildschirmf�llendes Wischerfenster an

function showWischer(object){
	var newHeight = document.body.clientHeight;
	var newWidth = document.body.clientWidth;
	// var availHeight = $(document).height();
	var pos_x = 0;
	var pos_y = 0;	
	
	/*
	var av_height = screen.availHeight;
	var center = (av_height/2) + scrolltop;
	var offset_from_center = center - (tab_height*2);
	*/
	$('#wischer').height(newHeight);
	$('#wischer').css("width", newWidth);
	$('#wischer').css("top", pos_y);
	$('#wischer').css("left", pos_x);
	
	if (newWidth==0 || newHeight==0) {
		return;
	}
	else {
		$('#wischer').show();
	}
	
	// Die mittleren beiden Divs sind genau x Pixel breit. Die �usseren m�ssen je nach Bildschirmbreite angepasst werden.
	var middleWidth =  $('#layer2').width();
	var innerWidth = $('#wischer').width();
	var newWidth = ((innerWidth-middleWidth)/2); // Scrollbar abziehen :-(
		
	$('#layer1,#layer3,#layer4,#layer6').width(newWidth);
	
	/*
	var numLayers = $('#wischer .layer').length;
	$('#wischer .layer').css("width", width+"%").css("height", height+"%");
	*/
}



// Versteckt das Wischer wieder
function hideWischer(doit){
	if (doit!=="true") {
		window.setTimeout("hideWischer('true')", waitTime);
	}
	else {
		var elemente = new Array();
		var numLayers = $('#wischer .layer').length;
		
		var i=1;
		for (i=1; i<=numLayers; i++) {
			window.setTimeout("hideLayer("+i+", "+numLayers+")", (speedOut/2)*i);
		}
		window.setTimeout("$('#wischer').hide()", (speedOut/2)*i);
	}
	
}

function showLayers(url){
	var numLayers = $('#wischer .layer').length;
	$('#wischer').show();
	showLayer(1, numLayers, url);
	return false;
}


function hideLayer(currentLayer, numLayers, elemente) {
	
	var obj = '#layer'+currentLayer+" .inner";
	$(obj).fadeOut(speedOut);
}


function showLayer(currentLayer, numLayers, url) {
	
	if (currentLayer<=numLayers) {
		
		$('#layer'+currentLayer+" .inner").fadeIn(speedIn, function() {
			showLayer((currentLayer+1), numLayers, url);
		});
		return false;
	}
	else {
		if(url.charAt(0) != "/" && SERVER_HTTP_HOST().indexOf("stadtreklame") > 0){
			url = "/" + url;
		}
		
		location.href=url;
	}
}



/*************************************
  http://forum.jswelt.de/javascript/33848-sleep-funktion-javascript.html
 *************************************/
function sleep(ms){
	var zeit=(new Date()).getTime();
	var stoppZeit=zeit+ms;
	while((new Date()).getTime()<stoppZeit){};
} 
