function moveMapElement() {
	sizeo = $('body').getSize();
//	div = document.getElementById('leftmap');
//	div.style.left = ((document.documentElement.clientWidth - 900)/2)-134+'px';
	$('leftmap').setStyle('left', ((sizeo.size.x-900)/2)-134+'px');
}

window.addEvent('domready', function() {
	
	moveMapElement();
	window.addEvent('resize', function() { moveMapElement() });

	// Subpages
	$$('#header ul li a').each(function(element,index) {  
		element.addEvent('click', function(event) {
			if (event) {
			    var event = new Event(event);
				event.stop();
			}
			new_subpage = this.getProperty('href').replace('\.html','');
			
			if (subpage == new_subpage) return true;
			$(subpage).setStyle('display', 'none');
			$(subpage+'_menu').removeClass('sel');
			this.addClass('sel');

			$(new_subpage).setStyle('display', 'block');
			subpage = new_subpage;
		});	
	}); 


	// Screenshots
	current = false;
	timer = null;
	isAnimating = false;
	
	animation = new Fx.Style($('screenshot'),'opacity', {duration: 1250, wait: false, 
				onStart: function()
				{
					isAnimating = true;
//					console.log('animation1 started');
				},
				onComplete: function() 
				{
//					console.log('animation1 completed');
					isAnimating = false;
				},
	});

	$$('#sidebar ul li a').each(function(element,index) {  
		element.addEvent('click', function(event) {
			if (event) {
			    var event = new Event(event);
				event.stop();
			}
			if (current) current.removeClass('c');
			current = this;
			this.addClass('c');

			if (isAnimating)
			{
				animation.stop();
				animation2.stop();
			}
			
			animation2 = new Fx.Style($('screenshot'),'opacity', {
				duration: 750,
				wait: false,
				onStart: function()
				{
					isAnimating = true;
//					console.log('animation2 started');
				},
				onComplete: function() 
				{
//					console.log('animation2 completed');
					$('screenshot').setStyle('background-image', 'url("'+current.getProperty('href')+'")');		
					animation.start(0,1);
				},
			});			
			
			animation2.start(1,0);
		});
	}); 
	firstElement = $('sidebar').getElement('a');
	firstElement.fireEvent('click');	

	function nextScreenshot() {
		if (current.getParent().getNext())
		{
			current.getParent().getNext().getFirst().fireEvent('click');
		}
		else
		{
			current.getParent().getParent().getFirst().getFirst().fireEvent('click');		
		}
	}

	function timerStop() {
		timer = $clear(timer);
	}
		
	function timerStart() {
		timerStop();
		timer=nextScreenshot.periodical(5000);
	}

	$('sidebar').addEvent('mouseover', timerStop);
	$('sidebar').addEvent('mouseout', timerStart);
	
	timerStart();
	
});