function element_count(objParent, strElementName)
{
	var i;
	var total;
	total = [];
	
	for (i = 0; i < objParent.childNodes.length; i++) {
		if (objParent.childNodes[i].nodeType == 1) {
			if (objParent.childNodes[i].nodeName.toLowerCase() == strElementName.toLowerCase()) {
				total[total.length] = objParent.childNodes[i];
			}
		}
	}
	
	return total;
}

function show_N_random()
{
	var list_items;
	var obj;
	var items_to_show = 3;
	
	obj = document.getElementById('testimonials');
	
	if (obj) {
		list_items = element_count(obj, 'li');
		
		// Only operate on a list with at least 1 item to hide
		if (list_items.length > items_to_show) {
			// Pick a random starting point in the list of items
			var start_idx = Math.floor(Math.random() * list_items.length);
			var i;
			
			// Hide all the items
			for (i = 0; i < list_items.length; i++) {
				list_items[i].className = "ignored";
			}
			
			// Show the grouping of items to show
			for (i = start_idx; i < start_idx + items_to_show; i++) {
				list_items[i % list_items.length].className = "selected";
				//alert("Showing list item " + (i % list_items.length));
			}
			
			// Make a link to show them all
			var temp_link = document.createElement('a');
			temp_link.appendChild(document.createTextNode("View All"));
			temp_link.id = "view_all_link";
			//temp_link.className = "view_all_link";
			temp_link.onclick = function() {
				var obj2 = document.getElementById('testimonials');
				if (obj2) {
					var list_items2 = element_count(obj2, 'li');

					//alert("Showing " + list_items2.length + " list items.");
					
					for (var j = 0; j < list_items2.length; j++) {
						list_items2[j].className = "selected";
					}
				}

				// Kill the link
				document.getElementById("view_all_link").style.display = "none";
			}
			obj.parentNode.appendChild(temp_link);
		}
	}
}

addLoadEvent(show_N_random);