// JavaScript Document
$(window).load(function() {
	(function($) {
		if ($('.fade').length > 0){

        // Get the list items and hide them
        var items = $(".fade");
        // Shuffle them
        shuffle(items);
        // Start the fade-in queue
        nextItemFade(items);
        }

        // Animation callback to start next fade-in
        function nextItemFade(items) {
                // Fade in the first element in the collection
                items.eq(0).fadeIn(500, function() {
                        // Recurse, but without the first element
                        nextItemFade(items.slice(1));
                });
        }
        
        // Shuffles an array
        // Based on http://jsfromhell.com/array/shuffle
        function shuffle(a) {
                var j,              // Random position
                    x,              // Last item
                    i = a.length;   // Iterator
                // Loop through the array
                while(i) {
                        // Select a random position
                        j = (Math.random() * i) | 0;
                        // Get the last item in the array
                        x = a[--i];
                        // Swap the last item with the item at the selected position
                        a[i] = a[j];
                        a[j] = x;
                }
                return a;
        }
        
        /* Minified version
        function shuffle(a) {
                for(var j, x, i = a.length; i; j = (Math.random() * i) | 0, x = a[--i], a[i] = a[j], a[j] = x);
                return a;
        } */
	})(jQuery);
});

$(window).load(function() {
	(function($) {
		if ($('.fade').length > 0){
        // Get the list items and hide them
        var items = $(".fadeOut");
        // Shuffle them
        shuffle(items);
        // Start the fade-in queue
        nextItemFadeOut(items);
        }

        // Animation callback to start next fade-in
        function nextItemFadeOut(items) {
                // Fade in the first element in the collection
                items.eq(0).fadeOut(500, function() {
                        // Recurse, but without the first element
                        nextItemFadeOut(items.slice(1));
                });
        }
        
       
	})(jQuery);
});
