// domready
window.addEvent('domready',function(){
	if($('gmap')){
		getGoogleMap();
	}
	
	if($('flash_slideshow')){
		insertSwf();	
	}
	
	if($('cnc_map') || $('gmap')){
		createSubnavigation();	
	}
	
	cleanUp();
	fixBreadcrumb();
	if($$('.page_168')[0] || $$('.page_261')[0] || $$('.page_315')[0] || $$('.page_365')[0] || $$('.page_431')[0]){
		createFAQ();	
	}
});







// tx_dwlangdetection_pi1
function switchLanguage(){
	window.location.href=document.getElementById('language').value;
}







// tx_dwmap_pi1
var address;
var response;
var map;
var geocoder;

function showMarker(marker){
	$$('.markerinfo').setStyle('display','none');	
	if(marker != null){
		$(marker).setStyle('display','block');
	}
}

function getTargetURL(){
	window.location.href=$('location').value;	
}

function getGoogleMap(){
	if(GBrowserIsCompatible()){
		map = new GMap2(document.getElementById("gmap"));
		map.setUIToDefault();
		geocoder = new GClientGeocoder();
		geocoder.getLocations(address, centerMap);
	}
}

var html;
function centerMap(response){
	if(response.Placemark != null){
		// Map initialisieren + zentrieren
		ort = response.Placemark[0];			
		point = new GLatLng(ort.Point.coordinates[1],ort.Point.coordinates[0]);
		map.setCenter(point, 14);
		
		// Marker hinzuf�gen
		html = $$('.left')[0].innerHTML;
		newmarker = createMarker(point,html);
		map.addOverlay(newmarker);
	}
}

function createMarker(point,html,icon) {
	var marker = new GMarker(point,icon);
	GEvent.addListener(marker,"click",function(){
		marker.openInfoWindowHtml(html);
	});
	return marker;
}

var first_item=true;
function createSubnavigation(){
	var new_subnavi=new Element('ol');
	new_subnavi.inject($$('#navigation .active')[0],'after');
	locations=$$('#location option').each(function(item){
		if(first_item != true){
			new_li=new Element('li');
			new_li.inject($(new_subnavi));
			
			if('http://'+location.host+item.value != window.location.href){
				new_href = new Element('a',{
					'href': item.value,
					'html': item.innerHTML});
			}
			else{
				new_href = new Element('a',{
					'href': item.value,
					'styles':{
						'font-weight':'bold'	
					},
					'html': item.innerHTML});				
			}
			new_href.inject($(new_li));
		}
		else first_item=false;
	});
}












/* tx_dwheadpic_pi1 */
function insertSwf(){
	new Swiff('/fileadmin/templates/swf/slideshow.swf', {
		width: 709,
		height: 260,
		params: {
			wmode: 'opaque',
			bgcolor: '#ffffff'
		}
	}).inject('flash_slideshow');
}






/* tx_dwemployee_pi1 */
function gotoURL(){
	window.location.href=$('switch_employee').value;	
}

function fixBreadcrumb(){
	if($('employee') || $('gmap')){
		$$('#history strong')[0].setStyle('font-weight','normal');
		this_url=window.location.href.split('?');
		$$('#history strong')[0].innerHTML = '<a href="'+this_url[0]+'">'+$$('#history strong')[0].innerHTML+'</a>';
		$('history').innerHTML = $('history').innerHTML+' / <strong>'+$$('h1')[0].innerHTML+'</strong>';
	}
}





/* Remove Empty Tags */
function cleanUp(){
	$$('span:empty').dispose();
	$$('p:empty').dispose();
	$$('span').each(function(item){
		if(item.innerHTML.trim() == ''){
			item.dispose();
		}
		if(item.innerHTML.trim() == '&nbsp;'){
			item.dispose();
		}
	});
	$$('p').each(function(item){
		if(item.innerHTML.trim() == ''){
			item.dispose();
		}
		if(item.innerHTML.trim() == '&nbsp;'){
			item.dispose();
		}
	});
	if($$('.browsebox')[0]){
		$$('.browsebox')[0].dispose();
	}
}



/* FAQ */
function createFAQ(){
	faq_hideshow();
	$$('#content strong').getParent().addEvent('click',function(item,i){
		faq_hideshow();
		var this_next = this.getNext().setStyle('display','block');
		if(this_next.getNext().style.display == 'none'){
			this_next.getNext().setStyle('display','block');
		}
	});		
}

function faq_hideshow(){
		$$('#content p').setStyle('display','none');
		$$('#content strong').getParent().setStyles({'display':'block','cursor':'pointer'});	
}






/* Spamschutz */
function decryptString(enc,offset){var dec="";var len=enc.length;for(var i=0;i<len;i++){var n=enc.charCodeAt(i);if(n>=0x2B&&n<=0x3A){dec+=decryptCharcode(n,0x2B,0x3A,offset);}else if(n>=0x40&&n<=0x5A){dec+=decryptCharcode(n,0x40,0x5A,offset);}else if(n>=0x61&&n<=0x7A){dec+=decryptCharcode(n,0x61,0x7A,offset);}else{dec+=enc.charAt(i);}}return dec;}
function linkTo_UnCryptMailto(s){location.href=decryptString(s,-1);}
function decryptCharcode(n,start,end,offset){n=n+offset;if(offset>0&&n>end){n=start+(n-end-1);}else if(offset<0&&n<start){n=end-(start-n-1);}return String.fromCharCode(n);}