var r = 0;
function random(max)
{
	var d = new Date();
	if (Math.random) r = Math.random() * max ;
	else r = (d.getTime() * Math.abs(Math.cos(r)));
	return Math.floor(r) % max;
}

function pick_img ()
{
	var n = random(13);
	n = n + 1
	if (document['Img_1']) {

		document['Img_1'].src = "/images/static/random/" + n + ".jpg";
	}
}

function pick_testimonial() {
	var testimonialsOrigElement = $('testimonialsOrig');
	var testimonialsNewElement = $('testimonialsNew');
	
	// store the child nodes in our own array
	// this is because firefox and IE behave differently when removing nodes from node.childNodes
	// IE does something freaky with the indices, firefox does not
	var childNodes = new Array();
	for(var childNodeIndex = 0; childNodeIndex < testimonialsOrigElement.childNodes.length; childNodeIndex++) {
		childNodes.push(testimonialsOrigElement.childNodes[childNodeIndex]);
	}
	//alert("childNodes.length [" + childNodes.length + "]");

	// remove the child nodes from the document and push them all into a local array
	var localChildNodeArray = new Array();
	for(var childNodeIndex = 0; childNodeIndex < childNodes.length; childNodeIndex++) {
		var curChildNode = childNodes[childNodeIndex];
		//alert("nodeType [" + curChildNode.nodeType + "] nodeName [" + curChildNode.nodeName + "]");
		if(curChildNode.nodeType == 1) {
			var removedNode = testimonialsOrigElement.removeChild(curChildNode);
			localChildNodeArray.push(removedNode);
			//alert("removed child with id [" + removedNode.id + "]");
		}
	}
	
	// randomly add the elements back into the document, ensuring they are not duplicated
	var displayedNodeMap = new Array();
	var displayedNodeCount = 0;
	for(var checkedNodeCount = 0; checkedNodeCount < (localChildNodeArray.length * 10); checkedNodeCount++) {
		if(displayedNodeCount >= 3) {
		//if(displayedNodeCount >= localChildNodeArray.length) {
			//alert("done after [" + checkedNodeCount + "] attempts for [" + localChildNodeArray.length + "] elements");
			break;
		}
		
		var displayNodeIndex = random(localChildNodeArray.length);
		if(displayedNodeMap[displayNodeIndex] == null) {
			testimonialsNewElement.appendChild(localChildNodeArray[displayNodeIndex]);
			displayedNodeMap[displayNodeIndex] = 1;
			displayedNodeCount++;
		}
	}
}
