jQuery(document).ready(function() {
	
	var tagsList = jQuery(".tagcloud ul")
	var tagsItems = jQuery(".tagcloud li");
	var max = 10;
	var weight = Math.round(max*0.3);
	
	tagsItems.each(function(index) {
		jQuery(this).wrapInner('<span />');
		if (index <= weight) jQuery(this).addClass('weight-1');
		else if (index <= weight*2) jQuery(this).addClass('weight-2');
		else if (index <= weight*3) jQuery(this).addClass('weight-3');
		else { jQuery(this).remove(); }
	});
	
	tagsList.shuffle();
	
});

(function(jQuery){
  jQuery.fn.shuffle = function() {
    return this.each(function(){
      var items = jQuery(this).children();
      return (items.length)
        ? jQuery(this).html(jQuery.shuffle(items))
        : this;
    });
  }

  jQuery.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);
