/**
 * Created By: Seamus P. H. Leahy <moronicbajebus.com>
 * File: AddAClassNameAtRandomToAnElement.js
 * Requires:  JQuery to be included before hand
 * Information: http://moronicbajebus.com/2006/07/30/add-a-class-randomly-from-a-set/
 *
 * Example usage:
 * ...
 * <head>
 * ...
 * <script src="/lib/nupp/jquery-1.3.2.js"></script>
 * <script src="AddAClassNameAtRandomToAnElement.js"></script>
 * <script>
 *
 * var setOfRandomClassNames = new Array("aa", "bb", "cc");
 *
 * //var queryForElementsToAddRandomClassTo = "body"; // adds the class name to the body
 * var queryForElementsToAddRandomClassTo = "#cow"; // adds the class name to an element with the id of cow
 *
 * $(document).ready(function(){ 
 *   AddARandomClassNameToElements(queryForElementsToAddRandomClassTo, setOfRandomClassNames);
 * });
 * </script>	
 *	<style>
 *	
 *	.aa{
 *		background-color: Red;
 *		font-size: 200%;
 *	}
 *	.bb{
 *	 background-color: Blue;
 *	 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
 *	}
 *	
 *	.cc{
 *	 background-color: Green;
 *	 padding: 50px;
 *	}
 *	</style>
 * </head>
 * <body>
 *  <div id="cow">Hi! how are you, this box will have a class randomly picked from a list 
 *      of classes. The classes can have different background colors, background images, text color, etc.  </div>
 * </body>
 * </html>
 */

/**
 * RandomValueFromSet
 * This function will return, at random, one of the values from the setOfValues.
 * @param setOfValues - an Array of values ordered by index from 0 to setOfValues.length-1.
 * @return a value from the set of values
 */
function RandomValueFromSet(setOfValues){
   return setOfValues[Math.round(Math.random()*(setOfValues.length-1))];
}


/**
 * AddARandomClass
 * This function will add a class randomly from the setOfClassNames to all the elements described in the query.
 * For additional information about '$.fn.' see JQuery Plugin <http://jquery.com/docs/Plugin/>
 * Credit goes to John Resig <http://ejohn.org/> for informing me about making it more intuitive
 * @param setOfClassNames - an Array of strings of the class names 
 */

$.fn.addRandomClass = function (setOfClassNames){
return this.addClass(RandomValueFromSet(setOfClassNames));
};


// The array to hold the multple classnames to be picked at random
var setOfRandomClassNames = new Array("aa", "bb", "cc", "dd");

//var queryForElementsToAddRandomClassTo = "body"; // adds the class name to the body
var queryForElementsToAddRandomClassTo = "#topnavholderhome"; // adds the class name to an element with the id of cow


// The element(s), to which we will add a class name, have not loaded, hence do not exist,
// at this point in time when executing the script.  Since they do not exist, we cannot 
// add the class name to them. But if we wait until after all the elements have loaded, we
// can then safely and succesfully add the class name. To do this, our statement is 
// encapsulated in an anonymous function will be executed after all the elements have
// loaded by passing it to $(document).ready().
 
 $(document).ready(function(){$(queryForElementsToAddRandomClassTo).addRandomClass(setOfRandomClassNames);});
