$(document).ready(function(){
    excludeNewsStory();
    randomItem(2, ".random-group-2");
    randomItem(1, ".random-group-1");
});

function excludeNewsStory(){
	var content = $('#content');
	var storyID = content.find('#contentText.news').attr('title');
	content.find('#sidebar .feature li[title=' + storyID + ']').removeClass('random-group-item').hide();
}; 

function randomItem(visibleItemNumber, objItemGroupSelector){
    $(objItemGroupSelector).each(function(){
        var items = $(this).find(".random-group-item");
        var itemCount = items.length;
        if (itemCount > 0) {        
	        //Hide all the items in the random group intially
	        items.hide();
	        
	        var randomItems = getUniqueNumbers(itemCount - 1, Math.min(visibleItemNumber, itemCount));
	        
	        for (var i in randomItems) {
	            $(items[randomItems[i]]).show();
	        }
        }
    }) 
}

/*
 * Originally Created by: Barry Pranklin
 * Heavily modified by: OHO - Akeem Williams
 */

function getUniqueNumbers(maxValue, numUnique){
    //console.log(maxValue);
		
		
	var found = false;
    var current = new Array();
    var count = 0;
    var current = new Array(numUnique);
    
    for (i = 0; count < numUnique; count++) {
        found = false;
        var rndValue = Math.round(Math.random() * maxValue);
        var j = 0;
        for (j = 0; j < current.length; j++) {
            if (current[j] == rndValue) {
                found = true;
                break;
            }
        }
        if (found) {
            count--;
        }
        else {
            current[count] = rndValue;
        }
    }
    return current;
}
