/*
 * jQuery shuffleChildren plugin
 * Examples, description, and documentation at: http://www.chuckharmston.com
 * Copyright (c) 2009 Chuck Harmston
 * Version: 1.0 (2009-02-28)
 * Dual licensed under the MIT and GPL licenses:
 *      http://www.opensource.org/licenses/mit-license.php
 *      http://www.gnu.org/licenses/gpl.html
 * Tested with jQuery 1.3.2, but should work with earlier versions.
 */

jQuery.fn.shuffleChildren = function() {
	return this.each(function(){
		var items = new Array(); var newList = '';
 		jQuery(this).children().each(function(){
			var newItem = '<' + this.tagName;
			jQuery(this).each(function(){
				for( i=0; i<this.attributes.length; i++ ){
					if( !!this.attributes[i]['nodeValue'] && this.attributes[i]['nodeValue'] != "null" )
						newItem += ' ' + this.attributes[i]['nodeName'] + '="' + this.attributes[i]['nodeValue'] + '"';
				}
			});
			newItem += '>' + jQuery(this).html() + '</' + this.tagName + '>';
			items.push(newItem);
		});
		var i = items.length;
		if ( i == 0 ) return false;
		while ( --i ) {
			var j = Math.floor( Math.random() * ( i + 1 ) );
			var tempi = items[i];
			var tempj = items[j];
			items[i] = tempj;
			items[j] = tempi;
		}
		for(i=0;i<items.length;i++)
			newList += items[i];
		jQuery(this).html(newList);
	});
};