function expandPage() {
	$('copyright').tween('margin-top', '128px');
	$('maschera').tween('margin-top', '-50px');
	$('coda').tween('margin-top', '0px');
	$('logo').tween('margin-top', '-200px');
}

function collapsePage() {
	$('copyright').tween('margin-top', '-20px');
	$('maschera').tween('margin-top', '0px');
	$('coda').tween('margin-top', '-248px');
	$('logo').tween('margin-top', '0px');
}

function loadContent(url) {
	var f = function() {
		$('content').load(url);
	}
	f.delay(200);
}

function removeContent() {
	$('content').set('text', '');
}

function setBackground(color) {
	$('main').tween('background-color', color);
}

function setSelected(item) {
	$('homepage-item').erase('class');
	$('presentazione-item').erase('class');
	$('contatti-item').erase('class');
	$('lavori-item').erase('class');
	//$('links-item').erase('class');
	item.set('class', 'selected');
}

window.addEvent('domready', function() {
	if ($('avviso')) {
		$('avviso').hide();
	}
	$('navigation').setStyle('top', '-400px');
	$('navigation2').setStyle('top', '-400px');
	$('content').innerHTML = '';
	$('navigation2').innerHTML = '';
	$('presentazione-item').addEvent('click', function(event) {
		expandPage();
		setSelected(this);
		setBackground('#5eb493');
		loadContent('documents/presentazione.php');
		event.stop();
	});
	$('contatti-item').addEvent('click', function(event) {
		expandPage();
		setSelected(this);
		setBackground('#5eb493');
		loadContent('documents/contatti.php');
		event.stop();
	});
	$('lavori-item').addEvent('click', function(event) {
		expandPage();
		setSelected(this);
		setBackground('#5eb493');
		loadContent('documents/lavori.php');
		event.stop();
	});
	/*$('links-item').addEvent('click', function(event) {
		expandPage();
		setSelected(this);
		setBackground('#5eb493');
		loadContent('documents/links.php');
		event.stop();
	});*/
	$('homepage-item').addEvent('click', function(event) {
		setBackground('#5eb493');
		setSelected(this);
		removeContent();
		collapsePage();
		event.stop();
	});
	$('presentazione-item').addEvent('mouseenter', function(event) {
		this.tween('width', '200px');
	});
	$('contatti-item').addEvent('mouseenter', function(event) {
		this.tween('width', '200px');
	});
	$('lavori-item').addEvent('mouseenter', function(event) {
		this.tween('width', '200px');
	});
	$('homepage-item').addEvent('mouseenter', function(event) {
		this.tween('width', '200px');
	});
	$('presentazione-item').addEvent('mouseleave', function(event) {
		this.tween('width', '180px');
	});
	$('contatti-item').addEvent('mouseleave', function(event) {
		this.tween('width', '180px');
	});
	$('lavori-item').addEvent('mouseleave', function(event) {
		this.tween('width', '180px');
	});
	/*$('links-item').addEvent('mouseleave', function(event) {
		this.tween('width', '180px');
	});*/
	$('homepage-item').addEvent('mouseleave', function(event) {
		this.tween('width', '180px');
	});
	$('viewer').addEvent('click', function(event) {
		event.stop();
		$('viewer').fade('hide');
		$('viewer').setStyle('z-index', '1');
		$('viewer').setStyle('width', '320px');
		$('viewer').setStyle('height', '220px');
		$('viewer').setStyle('margin-left', '-160px');
		$('viewer').setStyle('margin-top', '-110px');
		$('viewer-image').set('src', 'resources/loading.png');
	});
	var f = function() {
		setBackground('#5eb493');
	}
	f.delay(1000);
	var g = function() {
		$('coda').tween('margin-top', '-248px');
		$('copyright').tween('margin-top', '-20px');
		$('navigation').tween('top', '200px');
		$('maschera').tween('top', '0px');
		$('logo').tween('top', '10px');
	}
	g.delay(2000);
	$('viewer').innerHTML = '<div class="imageHeader"><span id="viewer-caption"></span><div class="imageButton">click to close <img src="resources/close.png"/></div></div><div class="image"><img id="viewer-image"/></div>';
	//$('mode').innerHTML = '<a href="home.php">Visita il sito in versione HTML</a>.';
});

function showImage(file, width, height) {
	$('viewer-image').set('src', 'resources/loading.png');
	$('viewer-caption').set('text', file);
	$('viewer').set('title', file);
	$('viewer').setStyle('z-index', '100');
	$('viewer').fade(1);
	$('viewer').morph({ width: width + 'px', height: height + 'px', 'margin-left': (-width / 2) + 'px', 'margin-top': (-height / 2) + 'px' });
	var f = function() {
		$('viewer-image').set('src', file);
	}
	f.delay(1000);
}

function showImage2(file, caption, width, height) {
	$('viewer-image').set('src', 'resources/loading.png');
	$('viewer-caption').set('text', file);
	if (caption) {
		$('viewer').set('title', caption);
	} else {
		$('viewer').set('title', file);
	}
	$('viewer').setStyle('z-index', '100');
	$('viewer').fade(1);
	$('viewer').morph({ width: width + 'px', height: height + 'px', 'margin-left': (-width / 2) + 'px', 'margin-top': (-height / 2) + 'px' });
	var f = function() {
		$('viewer-image').set('src', file);
	}
	f.delay(1000);
}

function hideNavigation() {
	$('navigation').tween('top', '-400px');
}

function showNavigation() {
	$('navigation').tween('top', '200px');
}

function hideNavigation2() {
	$('navigation2').tween('top', '-400px');
}

function showNavigation2() {
	$('navigation2').tween('top', '200px');
}

function restoreHomePage() {
	setBackground('#5eb493');
	setSelected($('homepage-item'));
	removeContent();
	hideNavigation2();
	collapsePage();
	showNavigation();
}

