jQuery.extend({ 
	frequency: function(json){              
	//get keys and values of json
	var keys = [];
	var values = [];
	for(var key in json){
		keys.push(key);
	}        
	jQuery(keys).each( function (i) {
		values.push(parseInt(json[keys[i]]));
	});        
	//normalized to 100%
	var sum = 0;
	jQuery(values).each( function (i) {  
		sum += values[i];
	});
	jQuery(values).each( function (i) {
		values[i] = values[i]*100/sum;
	});    
	//calculation of the ranges
	jQuery(values).each( function (i) {                     
		values[i+1] = values[i] + values[i+1];
	});
	values.splice(values.length-1, 1);     
	//search random values in the ranges
	var x = Math.floor(100 * (Math.random() % 1));
	var result;
	jQuery(values).each( function (i) {
		var max = values[i];
		var min = values[i-1];
		if( i-1 < 0 ) min = 0;            
		if( x >= min && x < max ) result = keys[i];
	});        
	//return the key of JSON with some frequency
	return result;
	}
});
