
	// Document initialisation.
	//
	
	// Init some vars.
	var fxVerticalScrollableMenu = null;
	var fxVerticalScrollableBottomImage = null;
	var menuYloc = 0;
	
	
	
	Event.observe(window, 'resize', function(event) {
		adjustFloatableElement('NavigationMenu',event);
	},false);

	
	// Do some stuffs when page loads.
	Event.observe(window, 'load', function(event){
		
		Event.observe(window, 'resize', function(event) {
			adjustFloatableElement('NavigationMenu',event);
		},false);

		loadAccordions();
		
		adjustFloatableElement('NavigationMenu',event);
		
	}, false);


	
	Event.observe(window, 'scroll', function(event) {
		adjustFloatableElement('NavigationMenu',event);
	},false);

	
	
	document.observe("dom:loaded", function(event){
		menuYloc = parseInt($('NavigationMenu').getStyle("top").substring(0,$('NavigationMenu').getStyle("top").indexOf("px")))
		
		adjustFloatableElement('NavigationMenu',event);
	}, false);
	
	
	
	// Implémentation on Brian Crescimanno' Accordion script by Bremond Sebastien - See flag {Callback implementation by Sebastien Bremond} in accordion.js
	// More info on http://www.tocra.org or http://www.web-medias.com
	function loadAccordions() {
		if( $('test-accordion') )
		{
			var topAccordion = new Accordion('test-accordion',0);
			topAccordion.mapSyncCallback('onend',function(){ adjustFloatableElement('NavigationMenu',null); });
		}
	}

	
	
	function adjustFloatableElement(name,e){
		if(document.loaded)
		{
			// Window is scrolling & Dom is ready.
			
			if(e != null){ Event.stop(e); }
			if( fxVerticalScrollableMenu != null ){ fxVerticalScrollableMenu.cancel(); }
			
			fxVerticalScrollableMenu = new Effect.Morph(name, {
				style: 'top:'+ parseInt(menuYloc+document.viewport.getScrollOffsets().top)+'px;', // CSS Properties
				duration: 0.6, // Core Effect properties
				transition:Effect.Transitions.EaseFromTo,
				queue:{ position: 'end', scope: 'scopeScrollableMenu', limit: 5 }
			});
			
			
			if( fxVerticalScrollableBottomImage != null ){ fxVerticalScrollableBottomImage.cancel(); }
			
			if( $('floatableBottom') )
			{
				availableHeightContentArea  =  Math.min( parseInt(document.viewport.getDimensions().height) , parseInt($('main').getHeight())+parseInt($('baseline').getHeight())  );
				useVerticalScrollOfsset = (parseInt(document.viewport.getDimensions().height) == availableHeightContentArea)? true:false;
				fxVerticalScrollableBottomImage = new Effect.Morph($('floatableBottom').id, {
					style: 'top:'+ parseInt(availableHeightContentArea + ((useVerticalScrollOfsset)? document.viewport.getScrollOffsets().top : 0) - $('floatableBottom').getHeight() )+'px;', // CSS Properties
					duration: 0.1, // Core Effect properties
					transition:Effect.Transitions.EaseFromTo,
					queue:{ position: 'end', scope: 'scopeScrollableBottomImage', limit: 5 }
				});
			}

		}
	}
	



//--- > Embed part of transitions.js

// EaseFromTo (adapted from "Quart.EaseInOut")
Effect.Transitions.EaseFromTo = function(pos) {
	if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,4);
	return -0.5 * ((pos-=2)*Math.pow(pos,3) - 2);    
};

