(function($){
	$.fn.randomize = function(childElem) {
		function shuffle(o) {
			for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
			return o;
		};
		return this.each(function() {
			var $this = $(this);
			var elems = $this.children(childElem);
			var shuffled = new Array();

			shuffle(elems);

			$this.detach(childElem);

			for(var i=0; i < elems.length; i++) {
				$this.append(elems[i]);
				shuffled[shuffled.length] = $(elems[i]).find('h3').html();
			}
			
			var $poll = $('#pds-answer8473522');
			var opts = $poll.children('.pds-answer-group');
			$poll.detach('.pds-answer-group');

			for( var i=0; i < shuffled.length; i++ ) {
				for( var j=0; j < opts.length; j++ ) {
					if ( $(opts[j]).find('.pds-answer-span').html() == shuffled[i] ) {
						$poll.append(opts[j]);
						break;
					}
				}
			}
		});
	}

	$('.randomize').randomize('.random_item');
})(jQuery);