// domready
window.addEvent('load',function(){

	checkBgImage();
	
	cleanUp();
	
	if($('slideshow')){
		slideshow.periodical(7000);
	}
	
	if($$('.csc-textpic-above')[0]){
		$$('.csc-textpic-above')[0].setStyle('margin-top',-26);
	}
	else{
		if($('headline2') != null){
			$('headline2').setStyle('border-color','#9f9f9f');
		}
		else{
			$$('h2')[0].setStyle('border-color','#9f9f9f');			
		}
	}
	
	if($('gallery')){
		$$('.gallery_controls')[0].setStyle('display','block');		
		$('gallery').addEvent("mouseover", function(){
			$$('.gallery_controls').set('morph',{
				duration: 300
			}).morph({'bottom':0});
		});
		$('gallery').addEvent("mouseout", function(){
			$$('.gallery_controls').set('morph',{
				duration: 300
			}).morph({'bottom':-79});
		});
	}
	
	
	
	if($('preview_0')){
		runFancyZoom();	
	}
	
	if(new String(window.location).match(/\/de\//)){
		if($$("#languageSwitch a")[2]){
			$$("#languageSwitch a")[2].setStyles({
				'font-weight': 'bold',
				'color': '#1A1857'});
		}
	}
	if(new String(window.location).match(/\/en\//)){
		if($$("#languageSwitch a")[1]){
		$$("#languageSwitch a")[1].setStyles({
			'font-weight': 'bold',
			'color': '#1A1857'});}
	}
	if(new String(window.location).match(/\/jp\//)){
		if($$("#languageSwitch a")[0]){
		$$("#languageSwitch a")[0].setStyles({
			'font-weight': 'bold',
			'color': '#1A1857'});}
	}
});







// bgImage
function checkBgImage(){
	var contentHeight=$('main').offsetHeight;
	var windowHeight=window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight;
	if(windowHeight <= contentHeight){
		$('hg').style.height=contentHeight+'px';
	}
	else{
		$('hg').style.height=windowHeight+'px';		
	}
}







// Startseite Newsteaser
var last_control = 0;
function switchTeaser(what){
	var position = what * 200;
	$$('#newsteaser div')[0].set('morph',{duration:500}).morph({'marginLeft':'-'+position+'px'});
	$$('.control')[last_control].className='control';
	$$('.control')[what].className+=' active';
	last_control=what;
}






// Referenzen: Gallery
var last_thumbnail = 0;
var last_control = 0;
function gallery_goto(what){
	$$('.gallery_controls').setStyle('display','none');
	$$('.gallery_controls')[what].setStyle('display','block');		
	
	var position = what * 570;
	$$('.innerWrap')[0].set('morph',{duration:1000}).morph({'marginLeft':'-'+position+'px'});
	$$('.thumb')[last_thumbnail].className='thumb';
	$$('.thumb')[what].className+=' active';
	last_thumbnail=what;
	$('untertitel').innerHTML='<p>'+$('pic_'+what).alt+'</p>';
}

function click_zoom(id){
	$(id).fireEvent('click');	
}







// Leere Ps und SPANs löschen
var node={};
function cleanUp(){
	$$('span:empty').dispose();
	$$('p:empty').dispose();
	$$('span').each(function(item){
		if(item.innerHTML.trim() == ''){
			item.dispose();
		}
	});
	$$('p').each(function(item){
		if(item.innerHTML.trim() == ''){
			item.dispose();
		}
	});
}












// slideshow Startseite
var img_counter = 0;
function slideshow(){
	img_counter++;
	new Request.JSON({url: window.location.href, onSuccess: function(response){
																	 
		// Counter zurücksetzen
		if(response['max'] <= img_counter){
			img_counter=0;	
		}
		
		var html = '<img src="'+response.bild+'" class="galleryPic" style="display:none;" />';
		$('slideshow').innerHTML += html;
		
		$$('#slideshow img')[1].setStyle('visibility','hidden');
		$$('#slideshow img')[1].setStyle('opacity',0);
		$$('#slideshow img')[1].setStyle('display','block');
		
		// Einfaden
		$$('#slideshow img')[1].set('morph',{
			duration: 2500, 
			onComplete : function(){
				
				// Entfernen des alten Elements
				$$('.galleryPic')[0].dispose();
				
			}
		}).morph({opacity:1});
		
	}}).get({'eID': 'bildwechsler','getpic': img_counter, 'this_pid' : this_pid});
}
