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

var imagesdone = false;
var loaded = 0;
var textBar, contuniueBar, parentDiv;



function loadimages()
{
	var child = window.document.getElementById("noscript");
	parentDiv = child.parentNode;
	var loadingText = '<div id="textBar" class="grey center middle vfalse">standby: waiting for data</div><div id="continuesBar" class="right vfalse"><div class="fb-like" data-href="https://www.facebook.com/thomas.stieler1" data-send="true" data-layout="button_count" data-width="451" data-show-faces="true" data-colorscheme="dark"></div><span class="g10 white"><a class="grey hbgdarkgrey" href="site.php?contentID=menu01">impressum</a> | <a class="grey hbgdarkgrey" href="http://www.eyemotion-design.com" onclick="window.open(this.href); return false;">designed by EyeMotion-Design.com</a></span></div>';
		
	parentDiv.removeChild(child);
	document.write(loadingText);
	
	textBar = document.getElementById('textBar');
	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 parentDivWidth = getWindowWidth(textBar.parentNode.id);
	
	textBar.style.visibility = "visible";
	
	randomHandler = randomFade("textBar", 0, 10, 10, 50, 100, 500, "sync", "timer");
}



function getWindowWidth(ElementID)
{
	Element = window.document.getElementById(ElementID);
	
	if (Element.innerWidth)
	{
		return Element.innerWidth;
	}
	else if( Element && Element.offsetWidth)
	{
		return Element.offsetWidth;
	}
	else 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()
{
	if ((loaded / imagenames.length * 100) > 90)
	{
		textBar.firstChild.data = "starting system";
	}
	else if ((loaded / imagenames.length * 100) > 60)
	{
		textBar.firstChild.data = "standby: digitalizing atmosphere";
	}
	else if ((loaded / imagenames.length * 100) > 30)
	{
		textBar.firstChild.data = "standby: loading navigation";
	}
	else if ((loaded / imagenames.length * 100) > 10)
	{
		textBar.firstChild.data = "standby: initializing kernel";
	}
	
	loaded++;
	
	if(loaded >= imagenames.length)
	{
		setTimeout('hideperouter()', 800);
	}
}



function hideperouter()
{
	clearTimeout(timeoutHandler[randomHandler]);
	
	textBar.style.visibility = "hidden";
	contuniueBar.style.visibility = "visible";
	facebookLikeButton(document, 'script', 'facebook-jssdk');
	
	imagesdone=true;
	
	//setTimeout('transfertosite()', 1000);
}



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