
window.addEvent("load", function(){

	var loadingFx = new Fx.Slide($('loading_bar'));
	var backgroundFx = new Fx.Tween($('wrapper'));
	var mainFx = new Fx.Tween($('centerField'));
	
	backgroundFx.addEvent('complete', function(){
  		mainFx.start('opacity','0.0', '1.0');
	});
	
	loadingFx.addEvent('complete', function(){
  		backgroundFx.start('opacity','0.0', '1.0');
	});
	
	loadingFx.slideOut();
	
});



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

	// timebox
	var today = new Date();
	var today_string = today.getDate() + '.' + Number(today.getMonth()+1) + '.' + today.getFullYear()
	$('timebox').set('html',today_string);
	
	
	
	$(document.body).getElements('a[id^=menu]').each(function(element, index){
	
		if (element.get('class') == 'buttonMenuLeft') {
			element.addEvents({
				"mouseenter": function(el, obj){
					this.setStyle('color','yellow');
				},
				"mouseleave": function(el, obj){
					if (userLocation != this.get('id')) { 
						this.setStyle('color','white');
					}
				},
				"click": function(event) { 
					event.stop();
					if (this.get('id') != userLocation) {
						setUserLocation(this.get('id'));
						//pageTracker._trackPageview(this.get('href'));
						openPage(this.get('href'),true);
					}
				}
			});
		}
	
		if (element.get('class') == 'buttonMenuTop') {
			element.addEvents({
				"mouseenter": function(el, obj){
					this.setStyle('color','white');
					this.setStyle('background-color','black');
				},
				"mouseleave": function(el, obj){
					if (userLocation != this.get('id')) { 
						this.setStyle('color','black');
						this.setStyle('background-color','transparent');
					}
				},
				"click": function(event) { 
					event.stop();
					if (this.get('id') != userLocation) {
						setUserLocation(this.get('id'));
						//pageTracker._trackPageview(this.get('href'));
						openPage(this.get('href'),true);
					}
				}
			});
		}
	
	});

	
	setUserLocation = function(id) {
		var oldLocation = $('centerField').getElements('a[id=' + userLocation + ']');
		if (oldLocation.get('class') == 'buttonMenuTop') {
			oldLocation.setStyle('color','black');
			oldLocation.setStyle('background-color','transparent');
		}
		if (oldLocation.get('class') == 'buttonMenuLeft') {
			oldLocation.setStyle('color','white');
		}
		userLocation = id;	
	
	}
	openPage = function(link, animate) {
		
		var req = new Request.HTML({  
			method: 'get',  
			url: link,  
			data: { 'do' : '1' },
			noCache: true,
			onRequest: function() { 
				$('content').set('html','');
			},  
			update: $('content'),  
			onComplete: function(response) { 
				
				var fxTime = 0;
				$('content').getElements('div,h1,p').each(function(item,index) {
					animate ? item.setStyle('opacity','0.0') : null;
					(function(){animate ? item.tween('opacity','1.0'): null;}).delay(fxTime);
					fxTime = Number(fxTime) + 100;
				});
				
			}  
		}).send();
	}
	
	
	bgChange = function(link) {
		$(document.body).setStyle('background-image','url('+link+')');
	}
	
	
	// init
	var userLocation = 'Start';
	setUserLocation('menuTop1');
	$('menuTop1').setStyle('color','white');
	$('menuTop1').setStyle('background-color','black');
	openPage('contents/home.html',false);
	$('logo_link').addEvents({
		'click':function(){
			setUserLocation('menuTop1');
			$('menuTop1').setStyle('color','white');
			$('menuTop1').setStyle('background-color','black');
			openPage('contents/home.html',true);
		}
	});

	(Browser.Engine.gecko) ? $('menuTop').setStyle('margin-top',3) : null;
	(Browser.Engine.gecko) ? $('logo').setStyle('height',180) : null;

});
