// nicemenu.js
/*
 * Fading Menu
 * 
 * @author Collin Bourdage
 */

$(document).ready(function() {
	var fm = new FadeMenu('fadeMenu');
});


var FadeMenu = function(elem) {
	var menuItems = $('#' + elem + ' li');
	menuItems.shuffle();
	
	jQuery.each(menuItems, function(key, val) {
		$(val).animate({empty: 1},parseInt(Math.random() * 1100), 0)
			  .fadeTo(2000, 1);
		
		$(val).hover(
			function() {
				$(this).stop().fadeTo('def', 0.75);
			},
			function() {
				$(this).stop().fadeTo('def', 1.0);
			}
		);
	});
}


// Shuffles an array
$.fn.shuffle = function() {
	var j, temp, i = this.length;
	
	while (--i) {		
		j = parseInt(Math.random() * i);
		temp = this[i], this[i] = this[j], this[j] = temp;
	}
	
	//console.log(this);
	return this;
}

