function clearPage() {
	$$('.fadein').fade('hide').removeClass('fadein');
}
var loaded=false;
function preload() {
	if (loaded == true) { return true; }
	var myImages = new Asset.images(
		[
			'fileadmin/templates/huismus/images/bg_interieur.jpg', 
			'fileadmin/templates/huismus/images/bg_kleding.jpg',
			'fileadmin/templates/huismus/images/bg_styling.jpg',
			'fileadmin/templates/huismus/images/bg_advies.jpg',
			'fileadmin/templates/huismus/images/bg_contact.jpg',
			'fileadmin/templates/huismus/images/bg_contact_rt1.jpg',
			'fileadmin/templates/huismus/images/bg_contact_rt2.jpg',
			'fileadmin/templates/huismus/images/bg_contact_rt3.jpg',
			'fileadmin/templates/huismus/images/bg_contact_rt4.jpg' 
		]);
	loaded=true;
}
function initPage() {
	clearPage();
	$('contentwrapper').set('tween', {duration: 1000});
	$('contentwrapper').get('tween').start('opacity', 0, 1).chain(function() {
		$('top').set('tween', {duration: 2000});
		$('top').get('tween').start('opacity', 0, 1).chain(function() {
			// volgende hier
		});
		$('menu').set('tween', {duration: 1000});
		$('menu').get('tween').start('opacity', 0, 1).chain(function() {
				
		});
		$('menulinks').set('tween', {duration: 1500});
		$('menulinks').get('tween').start('opacity', 0, 1).chain(function() {
				
		});

		
		$('content').set('tween', {duration: 2000});
		$('content').get('tween').start('opacity', 0, 1).chain(function() {
			
			if ($('hmoutlet')) { 
				$('hmoutlet').set('tween', {duration: 2000});
				$('hmoutlet').get('tween').start('opacity', 0, 1)			
			}
			
		});
		
		$('contact').set('tween', {duration: 2000});
		$('contact').get('tween').start('opacity', 0, 1).chain(function() {
			// volgende hier
		});
		
	});
}

var stap = 1;
function cnStep(inn){
	if (inn) { stap = parseInt(inn) + stap; }
	$('contentwrapper').set('tween', {duration: 500});
	$('contentwrapper').get('tween').start('opacity', 1, 0).chain(function() {

		$('cnforward').setStyle('opacity', 1); $('cnforward').setStyle('cursor', 'pointer');
		$('cnback').setStyle('opacity', 1);$('cnback').setStyle('cursor', 'pointer');
		for (i=1;i<=5;i++) {
			$('contentwrapper').removeClass('route'+i);
			$('contactnav').removeClass('route'+i);
		}
		if (stap > 3) { $('cnforward').setStyle('opacity', 0.5);$('cnforward').setStyle('cursor', 'default'); }
		if (stap <= 1) { $('cnback').setStyle('opacity', 0.5);$('cnback').setStyle('cursor', 'default'); }
	
	

		$('contentwrapper').addClass('route'+stap);
		$('contentwrapper').get('tween').start('opacity', 0, 1);

		$('contactnav').addClass('route'+stap);
		$('content').addClass('route');
	
		$('contactnav').set('tween', {duration: 1000});
		$('contactnav').get('tween').start('opacity', 0, 1).chain(function() {
			// volgende hier
		});		
		
	});	
}

function regularContact() {
	$('contentwrapper').set('tween', {duration: 1000});
	$('contentwrapper').get('tween').start('opacity', 1, 0).chain(function() {
		for (i=1;i<=5;i++) {
			$('contentwrapper').removeClass('route'+i);
			$('contactnav').removeClass('route'+i);
		}
		$('top').set('tween', {duration: 500});
		$('top').get('tween').start('opacity', 0, 1);
		
		$('menu').set('tween', {duration: 500});
		$('menu').get('tween').start('opacity', 0, 1);
		$('menulinks').setStyle('display', 'block');
		$('text').set('tween', {duration: 500});
		$('text').get('tween').start('opacity', 0, 1);
		$('content').removeClass('route');
		$('contactnav').get('tween').start('opacity', 1, 0);
		
		$('contentwrapper').get('tween').start('opacity', 0, 1);
	});
	//

}


function initContact() {
	$('emailbtn').addEvent('click', function(e) {
		window.top.location="mailto:info@dehuismus.nl";
	});
	$('routebtn').addEvent('click', function(e){
		e.stop();
		$('text').set('tween', {duration: 1000});
		$('text').get('tween').start('opacity', 1, 0).chain(function() {
			$('top').set('tween', {duration: 500});
			$('top').get('tween').start('opacity', 1, 0);

			$('menu').set('tween', {duration: 500});
			$('menu').get('tween').start('opacity', 1, 0);
			$('menulinks').setStyle('display', 'none');

			cnStep();
												
		});			
	});
	
	$('cnforward').addEvent('click', function(e) {
		e.stop();
		if (stap >3) { return false; }
		cnStep('1');
	});
	$('cnback').addEvent('click', function(e) {
		e.stop();
		if (stap <= 1) { return false; }
		cnStep('-1');
	});
	$('cnmain').addEvent('click', function(e) {
		e.stop();
		regularContact();
	});
}


window.addEvent('domready', function() {
	initPage();
	if ((typeof(isHome) == 'boolean') && (isHome == true)) { preload(); }
	if ($('routebtn')) { initContact(); }
});
