var aktSub;
var aktMain;
var oldMain;
var startPageActive=true;
var preloading=true;
//Seitenbaum
var site=new Array();
//Ladereihenfolge
var LRF=new Array();
			function setAktSub(_aktSub){

				aktSub=_aktSub;
				subOverFunc(aktSub);
			}
			function setAktMain(_aktMain){
				aktMain=_aktMain;
				//alert("aktMain="+aktMain);
				
			}

var mainLink;
function setMainLink(_mainLink){
	mainLink=_mainLink;
}
function prepareLRF(startPage){
	for (var i = 0; i < LRF.length; ++i){
		if(LRF[i]==startPage){
			var startIndex=i;
			LRF.splice(startIndex,1);
			LRF.unshift(startPage);
		}
	}
//	alert("1. Dok zum laden="+LRF[0]);
	preloadSite(site,LRF,0,startPage);
}

function preloadSite(site,LRF,count,startPage){
	
	if(site[LRF[count]][2]!='loaded'){
		jQuery('#parkplatz').append('<div id="'+site[LRF[count]][0]+'Box"></div>');
				
		jQuery('#'+site[LRF[count]][0]+'Box').load(mainLink+"/"+site[LRF[count]][1]+"/loadContent",function(responseText, textStatus, XMLHttpRequest) {	
				site[LRF[count]][2]='loaded';												
				
								
				if(site[LRF[count]][0]==startPage && startPageActive==true){						
					setStartTimerId = setTimeout (function(){setStart(startPage);} , 250 );
				}
				
				
				count++;
				if(count<LRF.length){
					preloadSite(site,LRF,count,startPage);	
				}else{
					preloading=false;
				}
		});	
	}else{
		count++;
		if(count<LRF.length){
			preloadSite(site,LRF,count,startPage);	
		}
	}
}
function setStart(startPage){
//	alert("setStart startPage="+startPage);
	clearTimeout(setStartTimerId);
	jQuery('#'+startPage+'Box').appendTo('#ajLayout');
	//eval('init'+startPage)();
	if(startPage=="referenzen"){
						referenzenLoadBilder('referenzen',0);	
					}
	fadeInStartTimerId = setTimeout ( "fadeInStart()", 50 );
	setAktMain(startPage);
	jQuery("#"+startPage).attr('linkingmode','current');

}
function fadeInStart(){
	//alert("fadeInStart");
	setLeft();	
	
	jQuery("#contentBlende").fadeOut("slow");	
	fadeInStartTimerId = setTimeout ( "fadeInStart()", 50 );
	clearTimeout(fadeInStartTimerId);
}

function fadeOutIn(ref,title){
	
	if ( !jQuery("#"+title+"Box").length ){		
		
		specialPreload(ref,title);
	}else{
		
		jQuery("#contentBlende").fadeIn(300,function(){
			
			if(oldMain=="printreferenzen" || oldMain=="printprojekte" ){
				closeprintreferenzenContent();			
			}else if (oldMain=="projekte" || oldMain=="druckfrisch"){
				closeprojekteContent();			
			}
			jQuery("#logoL").css('backgroundColor',jQuery('#'+title).attr('farbe'));
			jQuery('#'+oldMain+"Box").appendTo('#parkplatz');
//alert("schließen:"+aktMain);
			//eval('init'+title)();
			jQuery("#"+title+"Box").appendTo('#ajLayout');

			//jQuery("#"+ref+"Box").css("display", "block");
			setLeft();

			jQuery("#contentBlende").fadeOut(300);
			aktMain=title;
			//alert(ref);
			if(ref!='home'){
			//window.location.href = mainLink+"#"+ref;
			}
		});
							
	}
	
}


var contentLoaded=false;
function specialPreload(ref,title){

				if(preloading==true){
					startPageActive=false;	
				}
				jQuery('#parkplatz').append('<div id="'+site[title][0]+'Box"></div>');
				site[title][2]='loaded';
				
				//alert(" special preload ");
				jQuery('#'+title+'Box').load(mainLink+"/"+site[title][1]+"/loadContent",function(responseText, textStatus, XMLHttpRequest) {														

					contentLoaded=true;	
					if(title=="referenzen"){
						referenzenLoadBilder('referenzen',0);	
					}else if(title=="eigenart"){
						initeigenart();	
					}
					fadeOutIn(ref,title);		

				});
}



jQuery(window).resize(function() {
	hoeheOrg=jQuery(document).height();
	setLeft();
	
 //jQuery("#copyright").css( {  "top":(jQuery(window).height()-197) + "px" } );
});



function oeffnefenster (url) {
 	fenster = window.open(url, "fenster1", "width=600,height=400,toolbar=no,location=no,directories=no,status =no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no");
 	fenster.focus();
}
function setLeft(){

	contentHoehe=jQuery('#ajLayout').height();
//alert("hoeheOrg="+hoeheOrg+ "contentHoehe="+contentHoehe);
	if(contentHoehe<=hoeheOrg){
	//	alert("contentHoehe<hoeheOrg")	
		if(contentHoehe>jQuery('#wrapper').height()){
			jQuery('#wrapper').css("height",contentHoehe+'px')
			
		}else{
			jQuery('#wrapper').css("height",hoeheOrg+'px');
		}
		jQuery('#left').css("height",hoeheOrg+'px');
		jQuery('#main').css("height",hoeheOrg+'px');
		jQuery(document).css("height",hoeheOrg+"px");

	}else{
		//contentHoehe-=166;
	jQuery('#wrapper').css("height",contentHoehe+'px');
	jQuery('#left').css("height",jQuery('#wrapper').height()+'px');
		jQuery('#main').css("height",jQuery('#wrapper').height()+'px');
	}
	
	/*if(contentHoehe<hoeheOrg){		
		jQuery(document).css("height",hoeheOrg+"px");
		jQuery('#wrapper').css("height",jQuery(document).height()+'px');
	}
	
	if(jQuery(document).height()>jQuery('#wrapper').height() || contentHoehe<jQuery('#wrapper').height()){
		jQuery(document).css("height",jQuery('#wrapper').height()+'px');
		//alert("setLeft jQuery(document).height()="+jQuery(document).height());
	}else{
		jQuery('#wrapper').css("height",contentHoehe+'px');
		//alert("setLeft contentHoehe="+contentHoehe);
	}*/

	//jQuery('#wrapper').css("height",jQuery("body").height()+'px');
		
		
		
		/*if(jQuery('#ajLayout').height()<=1200){
			jQuery('#left').css("height",jQuery('#ajLayout').height()+'px');
			//jQuery('#wrapper').css("height",jQuery('#ajLayout').height()+'px');
		}else{
			jQuery('#left').css("height",jQuery('#wrapper').height()+'px');
			//jQuery('#wrapper').css("height",'1200px');
		}*/
		
	
	jQuery("#copyright").css( {  "top":(jQuery(window).height()-360) + "px" } );
}
function IsIE8Browser() {

    var rv = -1;

    var ua = navigator.userAgent;

    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");

    if (re.exec(ua) != null) {

        rv = parseFloat(RegExp.$1);

    }

    return (rv == 4);

}


				//WHITE SPACES ENTFERNEN
				function leerWeg(wert){
					var wert_array = wert.split(" ");
					var neuer_wert = wert_array.join("");
					return neuer_wert;
			  	}



			// NAVIGATION
			var tmpMain="";
			  function overFunc(ref,farbe){			  		 
			  		jQuery("#"+ref).css("color", farbe);			
			  }
			  function outFunc(ref){
			  	if(aktMain!=ref){
				//jQuery("#sNH"+ref).css("left", "-310px");
					if((aktMain=="projekte" && ref=="druckfrisch") ){
						
					}else if(aktMain=="printreferenzen" && ref=="printprojekte"){
						
					}else if (aktMain=="webseiten" && ref=="webdesign"){
						
					}else{
						jQuery("#"+ref).css("color", "#121110"); 
					}
				}
				 tmpMain="";
			  }
			  function clickFunc(link,ref,farbe){	
				//alert("ref="+ref+" aktMain="+aktMain);
				if(ref!=aktMain){
					_gaq.push(['_trackEvent', link.slice(1), aktMain, 'file.mp3']);
					jQuery("#"+ref).attr('linkingmode','current');
					jQuery("#"+ref).css("color", farbe);
					if(aktMain=="printreferenzen"){
						jQuery("#printprojekte").attr('linkingmode','link');
						jQuery("#printprojekte").css("color", "#121110"); 
					}else if(aktMain=="projekte"){
						jQuery("#druckfrisch").attr('linkingmode','link');
						jQuery("#druckfrisch").css("color", "#121110"); 
					} else if(aktMain=="webseiten"){
						jQuery("#webdesign").attr('linkingmode','link');
						jQuery("#webdesign").css("color", "#121110"); 
					}else if(aktMain){						
						jQuery("#"+aktMain).attr('linkingmode','link');
						jQuery("#"+aktMain).css("color", "#121110"); 
					}
					
					if(ref=="druckfrisch" || ref=="projekte"){
						printreferenzenLoading="noLoading";
						projekteLoading="nichtAlleBilder";
						//projekteLoadAll();
					}else if(ref=="printprojekte" || ref=="printreferenzen"){
						projekteLoading="noLoading";
						printreferenzenLoading="nichtAlleBilder";//alleBilder
						//printreferenzenLoadAll();
					}
					oldMain=aktMain;
					aktMain=ref;
					//window.location.href = link;
					
					
					//loadPage(link,ref);
					window.location.href = mainLink+"#"+link.slice(1);
				}
			  }
			  function clickFuncIntern(link,ref,farbe){	
				//alert("ref="+ref+" aktMain="+aktMain);
				if(ref!=aktMain){
					_gaq.push(['_trackEvent', link.slice(1), aktMain, 'file.mp3']);
					//alert("aktMain="+aktMain);
					oldMain=aktMain;
					//aktMain=ref;
					//window.location.href = link;
					
					
					//loadPage(link,ref);
					window.location.href = mainLink+"#"+link.slice(1);
				}
			  }
			  // NAVIGATION
			  function subOverFunc(ref){			  		 
			  		jQuery("#"+ref+" .normal").css("display", "none");			
					jQuery("#"+ref+" .over").css("display", "block");			
			  }
			  function subOutFunc(ref){
			  	if(ref!=aktSub){
				//jQuery("#sNH"+ref).css("left", "-310px");
			  		jQuery("#"+ref+" .normal").css("display", "block");			
					jQuery("#"+ref+" .over").css("display", "none");			
				 }
			  }
			  function subClickFunc(link,ref){	
				
				if(ref!=aktSub){
					jQuery("#"+ref).attr('linkingmode','current');
					if(aktSub){						
						jQuery("#"+aktSub+" .normal").css("display", "block");	
						jQuery("#"+aktSub+" .over").css("display", "none");	

					}
					aktSub=ref;
					//loadSubPage(link,ref);
					window.location.href = mainLink+"#"+link.slice(1);
				//	window.location.href = link;
					//this.href = hashLink+"#"+ref;
				}
			  }
			  
