/* randomise script
 * Author: Elle Meredith <elle at designbyelle dot com dot au>
 * Version: 2009 Jan 20
 *
 * This script is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation. 
 *
 * http://designbyelle.com.au/
 *
 * Randomises the children of an unordered list container.
 * Then, whether it is displayed or not is controlled with CSS
*/

function randomise() {
	if (!document.getElementById || !document.getElementsByTagName) return false;
	if (!document.getElementById("quotes")) return false;
	
    var elem = document.getElementById("quotes");
    var quotes = elem.getElementsByTagName("li");
    var quote_count = quotes.length;
    var random_num = Math.floor ((Math.random() * quote_count));

    for (var i=0; i<quote_count; i++) {
		if (quotes[i] == quotes[random_num]) {
			addClass(quotes[i], "selected");
		} else {
			addClass(quotes[i], "hide");
		}
	}
	
}


/* function by Simon Willison (http://simon.incutio.com/) */
function addLoadEvent(func) {
	var oldonload = window.load;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

addLoadEvent(randomise);

