var imagenames = document.getElementsByName('loadpics[]');
var images=new Array();

var barwidth = 200;
var barheight = 4;
var unloadedcolor = '#242424';
var loadedcolor = '#ffffff';
var bordercolor = '#ff8a00';

var imagesdone = false;
var loaded = 0;
var textBar, borderBar, loadingBar, contuniueBar;
var loadingStep = barwidth/(imagenames.length);

//var txt = '<div id="textBar" class="orange center middle vfalse">loading images ...</div><div id="borderBar" class="center border1orange vfalse"><div id="loadingBar" class="orange center middle vfalse"></div></div><div id="continuesBar" class="center vfalse"><a class="g10 white hbgdarkgrey1" href="site.php?MenuTyp=1&MenuID=2&UserMenu=1">Anfrage stellen</a><span class=\"g12 orange\">&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;</span><a class="g10 white hbgdarkgrey1" href="site.php?MenuTyp=1&MenuID=3&UserMenu=2">Gäste suchen</a></div>';
var txt = '<div id="textBar" class="orange center middle vfalse">loading images ...</div><div id="borderBar" class="center border1orange vfalse"><div id="loadingBar" class="orange center middle vfalse"></div></div><div id="continuesBar" class="center vfalse"><a class="g10 white hbgdarkgrey1" href="site.php?MenuTyp=1&MenuID=1&UserMenu=1">continue</a></div>';
document.write(txt);



function loadimages()
{
	document.getElementById('menubottom').removeChild(document.getElementById('noscript'));
	
	textBar = document.getElementById('textBar');
	borderBar = document.getElementById('borderBar');
	loadingBar = document.getElementById('loadingBar');
	contuniueBar = document.getElementById('continuesBar');
	
	window.onresize=barInit;
	barInit();
	
	for(n = 0; n < imagenames.length; n++)
	{
		images[n]=new Image();
		images[n].src=imagenames[n].value;
		
		setTimeout('checkload('+n+')' ,n*100);
	}
}



function barInit()
{
	var windowWidth = getWindowWidth();
	
	borderBar.style.visibility = "visible";
	loadingBar.style.visibility = "visible";
	textBar.style.visibility = "visible";
	
	borderBar.style.position = 'absolute';
	borderBar.style.left = ((windowWidth-barwidth)/2)+'px';
	borderBar.style.width = barwidth+'px';
	borderBar.style.height = barheight+'px';
	borderBar.style.backgroundColor = unloadedcolor;
	
	loadingBar.style.left = 100+'px';
	loadingBar.style.backgroundColor = loadedcolor;
	loadingBar.style.width = 1+'px';
	loadingBar.style.height = barheight+'px';
}



function getWindowWidth()
{
	if(window.innerWidth)
	{
		return window.innerWidth;
	}
	else if(document.body && document.body.offsetWidth)
	{
		return document.body.offsetWidth;
	}
	else
	{
		return 800;
	}
}



function checkload(index)
{
	(images[index].complete)? dispbars() : setTimeout('checkload('+index+')', 100);
}



function dispbars()
{
	barWidth = parseFloat(loadingBar.style.width);
	loadingBar.style.width = (barWidth+loadingStep)+'px';
	
	loaded++;
	
	if(loaded >= imagenames.length)
	{
		setTimeout('hideperouter()', 800);
	}
}



function hideperouter()
{
	textBar.style.visibility = "hidden";
	borderBar.style.visibility = "hidden";
	loadingBar.style.visibility = "hidden";
	contuniueBar.style.visibility = "visible";
	
	imagesdone=true;
	
	setTimeout('transfertosite()', 1000);
}



function transfertosite()
{
	//window.location.href = 'menue.php';
	window.location.href = 'site.php?MenuTyp=1&MenuID=1';
}



window.onload=loadimages;
