imga = new Image();
imga.src = "gfx/layout/dummy.png";
imgb = new Image();
imgb.src = "gfx/layout/loading.gif";
aktuell = 27;
aktuellerBereich = 2;
aktuellOne = 27;
aktuellShow = 0;
lastHandledHash = window.location.hash;

function loadContent(inhalt,bereich,titel,noHashChange) {
if(noHashChange != 1) {
	if(bereich == 2) {
		window.location.hash = "!" + inhalt;
	} else {
		var partOne = new String (window.location.hash);
		var index = partOne.indexOf("|",0);
		if(index > 0) {
			partOne = partOne.substring(0, index);
		}
		lastHandledHash = partOne + "|" + inhalt + ";" + titel;
		window.location.hash = partOne + "|" + inhalt + ";" + titel;
	}
}

if(bereich == 2) {
	aktuellOne = inhalt;
}

$("#section" + bereich).children(this).animate( { opacity:0 },500,'swing' );


http_request = false;
if (window.XMLHttpRequest) {
   http_request = new XMLHttpRequest();
   if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
   }
    } else if (window.ActiveXObject) { // IE
    try {
       http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
       http_request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    }
   if (!http_request) {
       alert('Das Request Objekt konnte nicht erzeugt werden! Bitte ueberpruefen Sie Ihre JAVA Einstellungen!');
        return false;
    }
	var action = "";
	var loc = new String (window.location);
	if (loc.indexOf("action=le",0) != -1) {
		action = "&action=le";
	}
   http_request.onreadystatechange = function () { show(bereich,inhalt,noHashChange); };
   http_request.open('GET', 'sites/_getContent.inc.php?site='+inhalt+action, true);
   http_request.send(null);


   $("#section" + bereich)
   		.css("background-image","url('gfx/layout/loading.gif')")
		.css("background-repeat","no-repeat")
		.css("background-position","center");
   
   if( (bereich == '3') || (bereich == 3) ) {
		$("#section3").css("min-height", $("#section2").css("min-height") );
		
		$("#lineLevel2")
	   		.css("display","block")
			.animate({ opacity:1 } , 1000,'linear');
		
		$("#lineLevel2").children().animate({width:'0px',opacity:0}, 900,'linear', function () {	$(this).css("display","none");	});
		
		$("#lineLevel2").children().first()
			.before("<div class='lineTitel' style='width:0px;opacity:0;overflow:hidden;white-space:nowrap;'>&rarr;&nbsp;&nbsp;"+titel+"</div>");
		$("#lineLevel2").children().each( function() {
            if( $(this).css("width") == "0px") {
				$(this).animate({width:"300px",opacity:1},900,'linear', function() { $(this).css("width","auto"); } );
			}
        });
		
		if ( !$("#lineLevel2").text() )
		{
						$("#lineLevel2").html("<div class='lineTitel' style='overflow:hidden;white-space:nowrap;'>&rarr;&nbsp;&nbsp;"+titel+"</div>");
		}
		
			
		$("#section3").animate({ marginTop: '55px' } , 500, 'linear');
   } else {
	   	$("#lineLevel2")
			.text("")
			.animate({ opacity:0,marginTop:'0px' } , 1000,'linear', function () {  $("#lineLevel2").css("display","none");  });
			
		$("#section3")
			.css("overflow","hidden")
			.css('height', $("#section3").height() )
			.css("min-height","0px")
			.animate({ marginTop: '0px',height:'0px'} , 1000, 'linear', function() { $("#section3").text(""); } );
   }
   
   smoothScrollTo("section" + bereich);
   aktuell = inhalt;
   aktuellerBereich = bereich;
   
}



function show(bereich,inhalt,noHashChange) {
if (http_request.readyState == 4) {
	
      document.getElementById("section" + bereich).innerHTML = http_request.responseText;

	  initSecondSites();
	  
	  adjustPaddingInSectionTwo(inhalt,bereich);
	  
	  initMainSites();
	  
	  if(inhalt == "nav_ueber") {
		  map_initialize();
	  }
	    
  var isLE = 0;
  
  $(".LE_HEAD").each(function(index, element) {
    isLE++;
   });
  
  if(isLE>0 ) {
	  initLECMS();
	  
	  initEditables();
  }
  
	$("#section" + bereich).children().css("opacity","0");
	
	if( $(".dg_back").css("background-image") ) {
		backImg = new Image();
		var str = $(".dg_back").css("background-image")
			.replace("url(" , "")
			.replace("'" , "")
			.replace("'" , "")
			.replace("\"" , "")
			.replace("\"" , "")
			.replace(")" , "")  ;


		backImg.onload = function () {
			window.setTimeout( function() {
			$("#section" + bereich).children().animate( { opacity:1 },900);
				},500);
			window.setTimeout( function() {
			$("#section" + bereich)
		   		.css("background-image","url('gfx/layout/dummy.png')" );
				},900);
			}
		
		backImg.src =  str;
		
	} else {
		window.setTimeout( function() {
		$("#section" + bereich).children().animate( { opacity:1 },900);
			},400);
			
		window.setTimeout( function() {
		$("#section" + bereich)
	   		.css("background-image","url('gfx/layout/dummy.png')" );
			},800);
	}
	

		$("#section2").css("min-height","600px")
			.css("height","auto");
	
	
	if( bereich == 3) {
	
	var isLe = 0;
	$(".LE_HEAD").each(function(index, element) {
        isLe++;
    });
	
	if(isLE>0 && false) {
		$("#section3")
		.animate( { 
			paddingTop: "10px" ,
			paddingBottom: "5px"
		 },500);
	 }
	  
		$("#section3").css("min-height","600px")
			.css("height","auto")
			.css("max-width","none")
			.css("width","auto");
	}
	
	if(noHashChange == 1) {
		var hash = window.location.hash.substr(2);
		var hindex = hash.indexOf("|");
		if (hindex > 0) {
			
			var secondPart = hash.substr(hindex+1);
			var secondContent = secondPart.substr(0, secondPart.indexOf(";"));
			var secondHeading = secondPart.substr(secondPart.indexOf(";")+1);
			
			if(aktuellShow != secondContent) {
				
				window.setTimeout( function () {
					loadContent(secondContent , 3 , secondHeading,1);
				} ,"1000");
				
			}
		}
	}
	var hash = window.location.hash.substr(2);
	var secondPart = hash.substr(hindex+1);
	var secondContent = secondPart.substr(0, secondPart.indexOf(";"));
	aktuellShow = secondContent;
	lastHandledHash = window.location.hash;
}
}

