//Ticker Randomizing Script---------------------------------
//John Driftmier, http://www.treenumbertwo.com
//January 2009
//
//Basically, this takes all the divs with the class "randomscroll" and mixes up the content inside those divs.
//Note that you also have to add the " group1" bit to the class, just in case you want to randomize two lists
//on the page, you would just make that list with the class "randomscroll group2", etc

if (document.getElementById)
document.documentElement.className = 'jsclass'; //hide content for DOM capable browsers


var randomordercontentdisplay={
	divholders:new Object(),
	masterclass: "randomscroll",

	init:function(){
		if (!document.getElementById)
			return
		var alldivs=document.getElementsByTagName("div")
		var randomcontentsearch=new RegExp(this.masterclass+"\\s+(group\\d+)", "i") //check for CSS class="randomcontent groupX" (x=integer)
		for (var i=0; i<alldivs.length; i++){
			if (randomcontentsearch.test(alldivs[i].className)){
				if (typeof this.divholders[RegExp.$1]=="undefined"){ //if object to hold this group of divs doesn't exist yet
					this.divholders[RegExp.$1]=new Object() //create object
					this.divholders[RegExp.$1].ref=[] //create array to hold each div within group
					this.divholders[RegExp.$1].contents=[] //create array to hold each div's content within group
				}
					this.divholders[RegExp.$1].ref.push(alldivs[i]) //add this div to the array
					this.divholders[RegExp.$1].contents.push(alldivs[i].innerHTML) //add this div's content to the array
			}
		}
	this.scrambleorder()
	},

	scrambleorder:function(){
		for (group in this.divholders){ //loop thru each array within object
			this.divholders[group].contents.sort(function() {return 0.5 - Math.random()}) //scramble contents array
			for (var i=0; i<this.divholders[group].ref.length; i++){
				this.divholders[group].ref[i].innerHTML=this.divholders[group].contents[i]
				this.divholders[group].ref[i].style.display="block"
			}
		}
	}
}
