var currentElement = null;
var currentSubElement = null;

Window.onDomReady(function()
{
  $('menuContent').getElements('a').each(function(el){
		el.addEvent('click', function(){setSelItem(this);});		
	});
  
  $('a_impressum').addEvent('click', function(){ShowImpressum();});
	
  sldSubMenu = new Fx.Slide('subMenu', {duration: 400});
  sldSubMenu.hide();
	
  //home setzen
  setSelItem($('home'));
  
  //scrollHeight beachtet den iframe nicht
  var iHeight = window.getScrollHeight() + 231;

	backgroundBox = new Element('div', {
		'styles': {
			'background-color': 'black',
			'position': 'absolute',
			'top': '0px',
			'left': '0px',
			'width': window.getWidth() + 'px',
			'height': iHeight + 'px',
			'opacity': '0.5',
			'z-layer': '100'			
		}
	});		

	foregroundBox = new Element('div', {
		'styles': {
			'background-color': 'white',
			'border': '1px solid #636363',
			'position': 'absolute',
			'top': '800px',
			'left': ((window.getWidth()/2) - 150) + 'px',
			'width': '300px',
			'height': '200px',
			'z-layer': '200'			
		}
	});
  
});

function loadContent(url)
{
	var myAjax = new Ajax(url, {method:'get',update: $('textContent')}).request();
}

function loadFormEvent(){
	$('kontaktform').addEvent('submit', function(e) {
				
		new Event(e).stop();
	
		this.send({
			update: foregroundBox,
			onComplete: function() {
				document.body.appendChild(backgroundBox);
				document.body.appendChild(foregroundBox);
						
				$('ajaxFormClose').addEvent('click', function(){
					foregroundBox.remove();
					backgroundBox.remove();							
				});
							
			}
		});	
	});				
}


function loadSliders()
{
	Sld = new Array();
	
	$('textContent').getElements('div[id^=question]').each(function(el){
		el.addEvent('click', function(){
			var aTmp = this.id.split("_");
			var iNum = aTmp[1];
			iNum--;
			Sld[iNum].toggle();
			
		});
	});

	$('textContent').getElements('div[id^=answ]').each(function(el){
		Sld.include(new Fx.Slide(el.id,{duration: 400}).hide());
	});	

	$('textContent').getElements('div[id^=answ]').each(function(el){
		el.setStyle('display', 'block');
	});		
}

function setSelItem(Item)
{
	currentSubElement = "";

	switch (Item.id) {
			case 'home':
			loadContent('content_home/home.htm');
			sldSubMenu.slideOut();
			break;
		case 'wir':
            var myAjax = new Ajax('content_wir/wir.htm', {method:'get',update: $('textContent'), onComplete: function(){ $('wir_link').addEvent('click', function(){ setSelItem($('projekthilfe')) } ); }}).request();
			sldSubMenu.toggle();
			break;
		case 'reisen':
            var myAjax = new Ajax('content_reisen/reisen.htm', {method:'get',update: $('textContent'), onComplete: function(){ $('reisen_link').addEvent('click', function(){ setSelItem($('projekthilfe')) } ); }}).request();
			sldSubMenu.slideOut();
			break;
		case 'aktuelles':
			loadContent('content_aktuelles/aktuelles.htm');
			sldSubMenu.slideOut();
			break;
		case 'kontakt':
			var myAjax = new Ajax('content_kontakt/kontakt.htm', {method:'get',update: $('textContent'), onComplete: function(){ loadFormEvent(); }}).request();
			sldSubMenu.slideOut();
			break;			
		case 'reiseinfos':
			var myAjax = new Ajax('content_reiseinfos/reiseinfos.htm', {method:'get',update: $('textContent'), onComplete: function(){ loadSliders(); }}).request();
			sldSubMenu.slideOut();
			break;
    case 'philosophie':
      loadContent('content_philosophie/philosophie.htm');
      break;
    case 'projekthilfe':
      loadContent('content_projekthilfe/projekthilfe.htm');
      break;
	}
}

function ShowImpressum() {
	fenster = window.open('content_impressum/impressum.html', "_blank", "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=300,left=30,top=30");
}