window.addEvent('domready', function() { 
	
	var englishHolders = $$('.english');
	var frenchHolders = $$('.french').setStyles({'display': 'none', 'opacity':0});

	var panels = $$('div.contentPanel');

	var panelsYpos = [];
	var panelsHeight = [];
	
	var currentPanel = 0;

	var Menus = $$('#menu ul li a');
	var scrollerFx = new Fx.Tween($('scroller'));
	var contentFx = new Fx.Tween($('content'));

	function setHolderHeights() {
		panelsYpos = [];
		panelsHeight = [];

		var tmpSize = 0;

		panels.each(function(panel) {
			var size = panel.getSize();
			panelsYpos.push((tmpSize * -1));
			panelsHeight.push(size.y);
			tmpSize = tmpSize + size.y;
		});
		$('scroller').setStyle('margin-top', panelsYpos[currentPanel]);
		$('content').setStyle('height', panelsHeight[currentPanel]);
		
	}
	
	setHolderHeights();

	
	Menus.each(function(menu, i){
		menu.addEvent('click', function(e){
			var e = e.stop();
			Menus.removeClass('active');
			menu.addClass('active');
			scrollerFx.start('margin-top', panelsYpos[i]);
			contentFx.start('height', panelsHeight[i]);
			currentPanel = i;
		});
	});
	
	$$('a.contactLink').each(function(link) {
		link.addEvent('click', function(e){
			var e = e.stop();
			$$('#menu ul li a').removeClass('active');
			Menus[5].addClass('active');
			scrollerFx.start('margin-top', panelsYpos[5]);
			contentFx.start('height', panelsHeight[5]);
			currentPanel = 5;
		});
	});
	
	
	new SmoothScroll({
	    links: '.smoothAnchors',
	    wheelStops: false,
		duration: 1000
	}, window);

	/**
	*
	*	Language Selector
	*	Used to switch between English & French Translations	
	*
	*/
	
	var englishFX = [];
	englishHolders.each(function(eHolder) {
		englishFX.push(new Fx.Tween(eHolder));
	});

	var frenchFX = [];
	frenchHolders.each(function(fHolder) {
		frenchFX.push(new Fx.Tween(fHolder));
	});

	
	var selectors = $$('a.selector');
	
	selectors.each(function(selector) {
		selector.addEvent('click', function(e){
			var e = e.stop();

			switch(selector.id) {
				case 'english':
					frenchFX.each(function(fx) {
						fx.start('opacity', 0).chain(function() {
								$$('.french').setStyle('display', 'none');
							 	englishHolders.each(function(fHolder, i) {
							 		fHolder.setStyle('display', 'block');
									englishFX[i].start('opacity', 1);
							 	});
							 	selector.set('opacity',1);
							 	$('french').set('opacity',0.3);
							 	//Set the Language on the Form Submit button
							 	$('submitButton').set('value','Submit');
							 	$('formLanguage').set('value','english');
								setHolderHeights();
							 });
					});
					break;
				case 'french':
					englishFX.each(function(fx) {
						fx.start('opacity', 0).chain(function() {
								$$('.english').setStyle('display', 'none');
							 	frenchHolders.each(function(fHolder, i) {
							 		fHolder.setStyle('display', 'block');
									frenchFX[i].start('opacity', 1);
							 	});
							 	selector.set('opacity',1);
							 	$('english').set('opacity',0.3);
							 	//Set the Language on the Form Submit button
							 	$('submitButton').set('value','Valider');
							 	$('formLanguage').set('value','french');
								setHolderHeights();
							 });
					});
					break;			
			}
			logSlide.slideOut();
		});
	});
	
	/**
	*
	*	Form Validator
	*	
	*
	*/	
	var logSlide = new Fx.Slide('contactLog').hide(); 
	
	
	$('contactCourtenay').addEvent('submit', function(e) {
		/* Prevents the default submit event from loading a new page. */
		e.stop();
		/* Empty the log and show the spinning indicator. */
		var log = $('contactLog').empty();
		/* Set the options of the form's Request handler. */ 
		/* ("this" refers to the $('myForm') element). */
		this.set('send', {onComplete: function(response) { 
			log.set('html', response);
			logSlide.slideIn();
		}});
		/* Send the form. */
		this.send();
	});
});
