var DEBUG;(typeof(window.console) != "undefined")?DEBUG=1:DEBUG=0;//alert(DEBUG);

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

	var active = 0.88;
	var inactive = 0.64;
	
	var El1 = $('agentur');
	var El1a = $('agenturContainer');
	$('agenturContainer').setStyle('z-index', '2');
	$('agenturContainer').setStyle('opacity', inactive);
	$('agentur').setStyle('z-index', '2');
	$('agentur').setStyle('opacity', inactive);

	var El2 = $('projekte');
	var El2a = $('projekteContainer');

	$('projekteContainer').setStyle('z-index', '3');
	$('projekteContainer').setStyle('opacity', active);
	$('projekte').setStyle('z-index', '3');
	$('projekte').setStyle('opacity', active);
	
	var zindexProjekte	= $('projekteContainer').getStyle('z-index');
	var opacProjekte	= $('projekteContainer').getStyle('opacity');
	
	var zindexAgentur	= $('agenturContainer').getStyle('z-index');
	var opacAgentur 	= $('agenturContainer').getStyle('opacity');
	
	var zindexAgenturAdd = eval(parseInt(zindexAgentur) + 1);
	var zindexAgenturSub = eval(parseInt(zindexAgentur) - 1);
	
	var zindexProjekteAdd = eval(parseInt(zindexProjekte) + 1);
	var zindexProjekteSub = eval(parseInt(zindexProjekte) - 1);
	
	function menuswitch(where) {
		switch (where) {
			case '2projekte' :
				var zindexAgentur = $('agenturContainer').getStyle('z-index');
				var zindexProjekte = $('projekteContainer').getStyle('z-index');
				
				if(zindexProjekte < zindexAgentur){
					
					$('projekteContainer').setStyle('z-index', zindexProjekteAdd);
					$('projekte').setStyle('z-index', zindexProjekteAdd);
					$('agenturContainer').setStyle('z-index', zindexAgenturSub);
					$('agentur').setStyle('z-index', zindexAgenturSub);
				
					// projekte	
					var myFxEl2 = new Fx.Tween(El2);
					var myFxEl2a = new Fx.Tween(El2a);
					myFxEl2.start('opacity', inactive, active);
					myFxEl2a.start('opacity', inactive, active);
				
					// agentur 
					var myFxEl1 = new Fx.Tween(El1);
					var myFxEl1a = new Fx.Tween(El1a);
					myFxEl1.start('opacity', active, inactive);
					myFxEl1a.start('opacity', active, inactive);
				}
			break;  
			case '2agentur' :
				var zindexAgentur = $('agenturContainer').getStyle('z-index');
				var zindexProjekte = $('projekteContainer').getStyle('z-index');
				if(zindexAgentur < zindexProjekte){
				
					$('agenturContainer').setStyle('z-index', zindexAgenturAdd);
					$('agentur').setStyle('z-index', zindexAgenturAdd);
					$('projekteContainer').setStyle('z-index', zindexProjekteSub);
					$('projekte').setStyle('z-index', zindexProjekteSub);
				
			
					// projekte	
					var myFxEl2 = new Fx.Tween(El2);
					var myFxEl2a = new Fx.Tween(El2a);
					myFxEl2.start('opacity', active, inactive);
					myFxEl2a.start('opacity', active, inactive);
				
					// agentur 
					var myFxEl1 = new Fx.Tween(El1);
					var myFxEl1a = new Fx.Tween(El1a);
					myFxEl1.start('opacity', inactive, active);
					myFxEl1a.start('opacity', inactive, active);
				
				}
			break;  
		}
	}

	
	$('switch2projekte').addEvent('click', function(e) {
		e.stop();
		menuswitch('2projekte');
	});
	
	$('switch2agentur').addEvent('click', function(e) {
		e.stop();
		menuswitch('2agentur');
	});
	
	$$('#fl1 a').addEvent('click', function(e) {
		e.stop();
		var zindexAgentur = $('agenturContainer').getStyle('z-index');
		var zindexProjekte = $('projekteContainer').getStyle('z-index');
		if(zindexAgentur < zindexProjekte){
		
			$('agenturContainer').setStyle('z-index', zindexAgenturAdd);
			$('agentur').setStyle('z-index', zindexAgenturAdd);
			$('projekteContainer').setStyle('z-index', zindexProjekteSub);
			$('projekte').setStyle('z-index', zindexProjekteSub);
		
	
			// projekte	
			var myFxEl2 = new Fx.Tween(El2);
			var myFxEl2a = new Fx.Tween(El2a);
			myFxEl2.start('opacity', active, inactive);
			myFxEl2a.start('opacity', active, inactive);
		
			// agentur 
			var myFxEl1 = new Fx.Tween(El1);
			var myFxEl1a = new Fx.Tween(El1a);
			myFxEl1.start('opacity', inactive, active);
			myFxEl1a.start('opacity', inactive, active);
		
		}
		
	});

//	if( Browser.Engine.trident4==true ) {
	// url contains projects
	// alert (window.location.href);
	if( location.href.toLowerCase().contains('projekte') ) {
		document.getElement('body').set('id','projects');
	}
	// url contains agency
	else if( location.href.toLowerCase().contains('agentur') ) {
		document.getElement('body').set('id','agency');
		if(zindexAgentur < zindexProjekte){
		
			$('agenturContainer').setStyle('z-index', zindexAgenturAdd);
			$('agentur').setStyle('z-index', zindexAgenturAdd);
			$('projekteContainer').setStyle('z-index', zindexProjekteSub);
			$('projekte').setStyle('z-index', zindexProjekteSub);
		
	
			// projekte	
			var myFxEl2 = new Fx.Tween(El2);
			var myFxEl2a = new Fx.Tween(El2a);
			myFxEl2.start('opacity', active, inactive);
			myFxEl2a.start('opacity', active, inactive);
		
			// agentur 
			var myFxEl1 = new Fx.Tween(El1);
			var myFxEl1a = new Fx.Tween(El1a);
			myFxEl1.start('opacity', inactive, active);
			myFxEl1a.start('opacity', inactive, active);
		}
	}
	// other pages
	else {
		document.getElement('body').set('id','index');
	}
//	}

});