var scriptArray=new Array();
var lastLoadScript='';
var taskme=0;
var loaderBarId=1;
var subMenuIsLoad=false;
var subMenuSetPos=null;

function boot(){
	addBody('<div id="loader" align="center"><div id="loaderText"><p>DIEDERICHS Karosserieteile GmbH</p>Egal welches Auto man Ihnen bringt -<br>wir haben die nötigen Karosserieteile !<br></div><div id="loaderBar"></div></div>');
	addBody('<div id="debug" style="position:absolute;z-index:100000"></div>');
}

function addBody(a){
	__$('body').innerHTML=a+__$('body').innerHTML;
}

function $d(output){
	if (debug)
		__$('debug').innerHTML=__$('debug').innerHTML+output+'<br>';
}

function __$(id){
	return document.getElementById(id);
}

function require(src){
	scriptArray.push(src);
	//document.getElementById('loaderBar').innerHTML=document.getElementById('loaderBar').innerHTML+'<img id="loaderBar'+loaderBarId+'" style="margin:2px;" src="'+tplPath+'/images/loaderBarNone.gif">';
	__$('loaderBar').innerHTML=__$('loaderBar').innerHTML+'<span id="loaderBar'+loaderBarId+'" class="loaderBox"></span>';
	loaderBarId=loaderBarId+1;
}

var picturecache = []; 
function preloadPicture(src){
	var picture=$(new Image()).set('src', src).addEvent('load', function(){
		picture.isload=true;
	});
	picture.isload=false;
	picturecache.push(picture);
	picture.isload=true;
}

function killLoadScript(){
	scriptArray.shift();
}

function scriptWriter(id,src){
	var script_element=document.createElement("script");
	script_element.type="text/javascript";
	script_element.id=id;
	script_element.src=src;
	var head=document.getElementsByTagName("head").item(0);
	var old_script_element=document.getElementById(id);
	if (!old_script_element){
		head.appendChild(script_element);
	}else{
		head.replaceChild(script_element,old_script_element);
	} 
}

function loadScript(){
	if (scriptArray.length){
		if (lastLoadScript!=scriptArray[0]){
			lastLoadScript=scriptArray[0];
			taskme=taskme+1;
			switch(taskme){
			case 2:
				oldBrowser=false;
				if (Browser.ie){
					if (Browser.version<=7){
						oldBrowser=true;
					}
				}
				if (oldBrowser){
					Cookie.write('templateforce','compatible');
					if (Cookie.read('templateforce')=='compatible'){
						window.location.href="index.php";
					}else{
						window.location.href="index.php?templateforce=compatible";
					}
				}
				break;
			case 6:
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/ground/2.gif');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/button/button_small_search.gif');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/ground/88.gif');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/ground/bannerRight2.gif');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/ground/bannerRight.gif');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/ground/bottomShadow.png');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/ground/ground.png');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/ground/bottomShadow.png');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/ground/bottomShadow.png');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/top/logo.gif');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/top/groundShadow.png');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/menu/ground_first.png');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/menu/ground.png');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/menu/menuButtonSelect.gif');
				preloadPicture('http://entwicklung.diederichs.com/templates/frontend/silber/images/menu/menuButton.gif');
				$('body').preloadPictureWait=function(){
					var allLoad=true;
					for(var i=0;i<picturecache.length;i++){
						if (!picturecache[i].isload){
							allLoad=false;
						}
					};
					if (allLoad){
						clearInterval($('body').periodicalTimer);
					}
				}
				$('body').periodicalTimer=$('body').preloadPictureWait.periodical(100);
			}
			scriptWriter('scriptLoader'+taskme,scriptArray[0]);
			__$('loaderBar'+taskme).style.backgroundColor="#e60000";
			window.setTimeout('loadScript()',5);
			return
			}
		window.setTimeout('loadScript()',10);
	}else{
		$('banner').set('tween',
		{
			'duration':0,
			onComplete:function(el)
			{
				
			}
		});
		var myHTMLRequest=new Request.HTML({
			update:$('leftMenu'),
			url:"index.php?ajax=true&template=index/leftMenu&noDebug=true",
			onComplete: function(){
				ajaxCreateLinks();
				shadowclass();
				$('banner').setStyle('opacity',0);
				$('banner').setStyle('display','block');
				$('banner').tween('opacity',0,1);
				$('leftMenu').setStyle('opacity',0);
				$('leftMenu').setStyle('display','block');
				leftMenuSectorInit();
				init();
			}
		}).get();
	}
}
