// JavaScript Document
// Refer to http://www.consideropen.com/blog/2008/08/30-days-of-mootools-12-tutorials-day-1-intro-to-the-library/

/* 
	fadingDiv
	
	fades in any div with the "fadein" class when mouse is moved within the body

*/

// build the functions
var fadingInDiv = function() {
	
	// select all divs with the "fadein" class
	var divArray = $$('div.fadein');
	
	// define the fader function
	var divFader = function() {
		// set the duration
		$$('div.fadein').set('tween', {duration: 'long'});
		// activate the effect
		$$('div.fadein').fade('in');
	};
	
	// process the divs
	divArray.each(divFader);
	
};

var fadingOutDiv = function() {
	
	// select all divs with the "fadein" class
	var divArray = $$('div.fadein');
	
	// define the fader function
	var divFader = function() {
		// set the duration
		//$$('div.fadein').set('tween', {duration: 'long'});
		// activate the effect
		$$('div.fadein').fade('out');
	};
	
	// process the divs
	divArray.each(divFader);
	
};

/*
	linkFade --NOT WORKING
	
	fades links' colors when mouse goes over them



// build the function
var linkFade = function() {
	
	// select all links
	var linkArray = $$('a');
	
	// define the fader function
	var linkFader = function() {
		var newColor = "#ffaa22";
		// store the initial colour
		var origColor = $$('a').getStyle('color');
		//set the functions
		var fadeLinkIn = function() {$$('a').tween('color', [origColor, newColor])};
		var fadeLinkOut = function() {$$('a').tween('color', [newColor, origColor])};
		// activate the effect
		$$('a').addEvent('mouseenter', fadeLinkIn);
		$$('a').addEvent('mouseleave', fadeLinkOut);
	};
	
	// process the divs
	linkArray.each(linkFader);
	
};

*/


//start the functions
window.addEvent('domready', function() {
	// set initial state of divs to hidden
	$$('div.fadein').fade('hide');
	// set the body trigger
	$$('body').addEvent('mouseover', fadingInDiv);
	$$('body').addEvent('click', fadingInDiv);
	//$$('body').addEvent('mouseleave', fadingOutDiv);
	// linkFade(); --not working
	
});