$(document).ready(function(){
	//$.historyInit(pageload, "index.php");
	//alert('test');
	//$('#lightbox_span a').lightBox();
});

function BannerLoad(pic,kat) {
		$banner  = '<img src="img/top_banner_'+pic+'.jpg" alt="banner1">';
		if(kat=='leistungen'){
			$banner += '<img src="img/top_banner_'+pic+'2.jpg" alt="banner2">';
		}
		document.getElementById('banner').innerHTML=$banner;
		//if(kat=='leistungen'){
			$('#banner').jqFancyTransitions({ 
				width: 909, // width of panel
				height: 109, // height of panel
				effect: 'curtain', // wave, zipper, curtain
				strips: 1, // number of strips
				delay: 6000, // delay between images in ms
				stripDelay: 450, // delay beetwen strips in ms
				titleOpacity: 0, // opacity of title
				titleSpeed: 1000, // speed of title appereance in ms
				position: 'curtain', // top, bottom, alternate, curtain
				direction: 'fountainAlternate' // left, right, alternate, random, fountain, fountainAlternate
			});
		//}
}

function SubLoad(kat,subkat,issub) {	
	if(!issub){
		$("#mid_navi_div").animate({marginLeft:-500}, 450, function() {
			$("#mid_navi ul.ul_on").each(function(){this.className='ul_off';});
			document.getElementById('ul_'+kat).className='ul_on';
			$("#mid_navi_div").animate({marginLeft:0}, 450);
		});
		$('#ul_'+kat+' a.a_on').each(function(){this.className='a_off';});
		document.getElementById('a_'+subkat).className='a_on';
		$('#top_navi a.a_on').each(function(){this.className='a_off';});
		document.getElementById('navi_'+kat).className='a_on';
		$('#bottom_navi a.a_on').each(function(){this.className='a_off';});
		document.getElementById('a_'+subkat).className='a_on';
	}
	else{
		$("#mid_navi ul.ul_on").each(function(){this.className='ul_off';});
		document.getElementById('ul_'+kat).className='ul_on';
	}
}

function SubReLoad(kat,subkat,obj) {
	$('#ul_'+kat+' a.a_on').each(function(){this.className='a_off';});
	document.getElementById('a_'+subkat).className='a_on';
}

function ContentLoad(id,id2,issub,kat,subkat,obj,search) {
/*
	if(obj){
		var hash = '';
			if(obj.href){
				hash = obj.href;
			}
			hash = hash.replace(/^.*#/, '');
			$.historyLoad(hash);
	}*/
	
	
	var myFile = document.location.toString();
	if (myFile.match('#')) {
 	 	var myAnchor = '#' + myFile.split('#')[1];
 	 	myAnchor1 = myAnchor.split(',')[1];
 	 	myAnchor2 = myAnchor.split(',')[2];
 	 	myAnchor3 = myAnchor.split(',')[3];
 	 	myAnchor4 = myAnchor.split(',')[4];
 	 	if(!id){id=myAnchor3;}
 	 	if(!id2){id2=myAnchor4;}
 	 	if(!kat){kat=myAnchor1;}
 	 	if(!subkat){subkat=myAnchor2;}
	}
	else{
		if(!id){id=260;}
		if(!id2){id2=268;}
 	 	if(!kat){kat='unternehmen';}
 	 	if(!subkat){subkat='geschichte';}
	}
	
	BannerLoad(subkat,kat);
	SubLoad(kat,subkat,issub);
	SubReLoad(kat,subkat,obj);
		
	/*
	document.getElementById('mid_content_div').style.display='none';
	document.getElementById('mid_search_div').style.display='none';
	document.getElementById('mid_search_div').innerHTML='';
	document.getElementById('mid_right_div').style.display='none';
	document.getElementById('mid_right_div').innerHTML='';
	document.getElementById('mid_right').style.width='208px';
	document.getElementById('mid_rightpic_div').style.display='none';
	document.getElementById('mid_rightpic_div').innerHTML='';
	document.getElementById('bottom_navi').style.display='none';
	*/
	
	//$("#mid_rightpic_div").animate({opacity: 0.0}, 1);
	
	if(kat=='leistungen'){
		$('#mid_right_div').load('src/content_right.src.php?id='+id2, function() {
			document.getElementById('mid_right_div').style.display='block';	
		});
	}
	if(subkat=='zertifikate'){
		document.getElementById('mid_right').style.width='5px';	
		//alert('d');
		//$('#lightbox_span a').lightBox();
		//$('#lb_div a').lightBox({fixedNavigation:true});
	}
	if(subkat=='impressum'){
		$('#mid_right_div').load('src/content_right.src.php?id='+id2, function() {
			document.getElementById('mid_right_div').style.display='block';	
			document.getElementById('mid_right').style.width='398px';	
		});
	}
	
	if(subkat=='search'){
		
		document.getElementById('mid_content_div').style.display='none';
		document.getElementById('mid_search_div').style.display='none';
		document.getElementById('mid_search_div').innerHTML='';
		document.getElementById('mid_right_div').style.display='none';
		document.getElementById('mid_right_div').innerHTML='';
		document.getElementById('mid_right').style.width='208px';
		document.getElementById('mid_rightpic_div').style.display='none';
		document.getElementById('mid_rightpic_div').innerHTML='';
		document.getElementById('bottom_navi').style.display='none';
		
		$("#mid_rightpic_div").animate({opacity: 0.0}, 1);
		
		$("#contentload2").animate({opacity: 1.0}, 1);
		$('#mid_search_div').load('src/search.src.php?value='+search, function() {
			document.getElementById('mid_search_div').style.display='block';
			$("#contentload2").animate({opacity: 0.0}, 1);
		});
		document.getElementById('bottom_navi').style.display='block';
	}
	
	if(subkat!='search'){	
		//$("#contentload").animate({opacity: 1.0}, 1);
		//$('#mid_content_div').load('src/content.src.php?id='+id, function() {
			//$("#contentload").animate({opacity: 0.0}, 100, function() {
				if(subkat=='kompetenzen'){
					document.getElementById('mid_rightpic_div').innerHTML='<img src="img/kompetenz.jpg" alt="Bild Kompetenz">';}
				if(subkat=='standorte'){
					document.getElementById('mid_rightpic_div').innerHTML='<a href="http://maps.google.de/maps?q=Schwiercz+GmbH,+06847+Dessau-Ro%C3%9Flau,+Robert-Bosch-Stra%C3%9Fe+58&hl=de&cd=1&ei=YYDiS4PfJ5KL_AbF05SEDQ&ie=UTF8&view=map&f=d&daddr=Robert-Bosch-Stra%C3%9Fe+58,+06847+Dessau&geocode=CWEADb1O8TP4Fa7YFgMdyG26ACHaTb3Ff4FWtA&ved=0CBIQ_wY&z=16" title="Google Maps - Standort Dessau-Rosslau" target="_blank"><img src="ftp/bildarchiv/standorte_dessau.jpg" alt="Bild Standorte"></a><br><br><a href="http://maps.google.de/maps?q=Schwiercz+GmbH,+06847+Dessau-Ro%C3%9Flau,+Robert-Bosch-Stra%C3%9Fe+58&hl=de&cd=2&ei=Y4DiS4-kBMfD_gaXrY2ADQ&ie=UTF8&view=map&f=d&daddr=Rietzer+Berg+31,+14797+Kloster+Lehnin&geocode=CcOZJ_uUdooYFZBwHwMdjm_AACHBibZaIN2hHg&ved=0CBIQ_wY&ll=52.392049,12.611532&spn=0.037713,0.077162&z=14" title="Google Maps - Standort Rietz" target="_blank"><img src="ftp/bildarchiv/standorte_rietz.jpg" alt="Bild Standorte"></a>';}
				if(subkat=='waerme'){
					document.getElementById('mid_rightpic_div').innerHTML='<img src="img/leistungen_waerme.jpg" alt="Bild W&auml;rme">';}
				if(subkat=='wasser'){
					document.getElementById('mid_rightpic_div').innerHTML='<img src="img/leistungen_wasser.jpg" alt="Bild Wasser">';}
				if(subkat=='erdgas'){
					document.getElementById('mid_rightpic_div').innerHTML='<img src="img/leistungen_erdgas.jpg" alt="Bild Erdgas">';}
				if(subkat=='industrie'){
					document.getElementById('mid_rightpic_div').innerHTML='<img src="img/leistungen_industrie.jpg" alt="Bild Industrie">';}
				if(subkat=='biogasanlagen'){
					document.getElementById('mid_rightpic_div').innerHTML='<img src="img/leistungen_biogasanlagen.jpg" alt="Bild Biogasanlagen">';}
				if(subkat=='klaeranlagen'){
					document.getElementById('mid_rightpic_div').innerHTML='<img src="img/leistungen_klaeranlagen.jpg" alt="Bild Kl&auml;ranlagen">';}
				if(subkat=='kontakt'){
					document.getElementById('mid_rightpic_div').innerHTML='<a href="http://maps.google.de" title="Google Maps" target="_blank"><img src="img/kontakt.jpg" alt="Bild Kontakt"></a>';}
				
				document.getElementById('mid_content_div').style.display='block';
				document.getElementById('mid_rightpic_div').style.display='block';
				document.getElementById('bottom_navi').style.display='block';
				$("#mid_rightpic_div").animate({opacity: 1.0}, 500);
				if(subkat=='zertifikate'){
					$('#lb_div a').lightBox({fixedNavigation:true});
				}
			//});	
		//});
	}
	
}

//JQUERY
function PreLoad() {
	setTimeout("PreLoader()",1000);
}
function PreLoader() {
	var cache = [];
  	$.preLoadImages = function() {
    	var args_len = arguments.length;
    	for (var i = args_len; i--;) {
    	  	var cacheImage = document.createElement('img');
     	 	cacheImage.src = arguments[i];
      		cache.push(cacheImage);
    	}
  	}
  	jQuery.preLoadImages(
  		"img/top_banner_geschichte.jpg",
  		"img/top_banner_aktuelles.jpg",
  		"img/top_banner_biogasanlagen.jpg",
  		"img/top_banner_erdgas.jpg",
  		"img/top_banner_impressum.jpg",
  		"img/top_banner_industrie.jpg",
  		"img/top_banner_kompetenzen.jpg",
  		"img/top_banner_kontakt.jpg",
  		"img/top_banner_partner.jpg",
  		"img/top_banner_standorte.jpg",
  		"img/top_banner_waerme.jpg",
  		"img/top_banner_wasser.jpg",
  		"img/top_banner_zertifikate.jpg",
  		"img/top_banner_biogasanlagen2.jpg",
  		"img/leistungen_klaeranlagen2.jpg",
  		"img/top_banner_erdgas2.jpg",
  		"img/top_banner_industrie2.jpg",
  		"img/top_banner_waerme2.jpg",
  		"img/top_banner_wasser2.jpg",		
  		"img/kompetenz.jpg",
  		"img/standorte.jpg",
  		"img/leistungen_waerme.jpg",
  		"img/leistungen_erdgas.jpg",
  		"img/leistungen_wasser.jpg",
  		"img/leistungen_industrie.jpg",
  		"img/leistungen_biogasanlagen.jpg",
  		"img/leistungen_klaeranlagen.jpg",
  		"img/kontakt.jpg"
  		
  		);
}	

//$(document).ready(function () {
	//UL-Menue Slidedown-effekt
	/*$('ul.menu').superfish({
		animation: {height:'show'},
		delay:     500,          
		autoArrows:  false, 
        dropShadows: false,
        speed: 600
	});*/
	//UL-Submenue Slideright-effekt	
	/*$('ul.submenu').superfish({
		animation: {width:'show'},
		delay:     500,           
		autoArrows:  false,               
        dropShadows: false,
        speed: 600
	});*/	
//});


/// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser
	function pageload(hash) {
		 //alert("pageload: " + hash);
		// hash doesn't contain the first # character.
		if(hash) {
			// restore ajax loaded state
			if($.browser.msie) {
				// jquery's $.load() function does't work when hash include special characters like aao.
				hash = encodeURIComponent(hash);
			}
			ContentLoad();
			
		} else {
		
		}
	}
	



