/**
 * DOM Fader
 * -----------------
 * A simple class to fade a set of DOM
 * elements in when a user moves their
 * mouse. 
 *
 * @author Paul Lewis [www.aerotwist.com]
 * @version 1.0
 */
var cDomFader = new Class({
	
	arrHidden: null,
	iSecondsToFadeIn: 4,
	fnToFade: null,
	
	/**
	 * Constructor - runs when the
	 * instance is created
	 */
	initialize: function()
	{
		// find all the hideonload elements
		this.arrHidden 	= $$(".hideonload");
		
		// get the function we need to fade in elements
		this.fnToFade	= this.fadeInElements.bind(this);
		
		// get the document body
		var docBody		= $(document.body);
		
		// now attach an event for when the mouse moves
		if(docBody)
			docBody.addEvent('mousemove', this.fnToFade);
	},
	
	/**
	 * Fades in the DOM elements
	 */
	fadeInElements: function()
	{
		// get the count
		var iCount = this.arrHidden.length;
		
		// work back to zero
		while(iCount--)
		{
			// definitely ensure all items are hidden
			this.arrHidden[iCount].setStyle('opacity', 0);
			
			// create a morph instance to animate the opacity
			var fxMorph = new Fx.Morph(this.arrHidden[iCount], {duration: this.iSecondsToFadeIn * 1000,
																transition: Fx.Transitions.Expo.easeOut});
			
			// fade up to 1
			fxMorph.start({'opacity': 1});
		}
		
		// now clean up - get the document body
		var docBody		= $(document.body);
		
		// remove the event
		if(docBody)
			docBody.removeEvent('mousemove', this.fnToFade);
			
	}
});

// create an instance of the DOMFader class when the page has finished loading
window.addEvent('domready', function()
{
	// create the fader
	var domFader = new cDomFader();
})
