function setSize(numberofsquares) {
	sqnum = numberofsquares;
}

function getRandColor(colorSet) {
	if (colorSet == null ) {colorSet = chromo; }
	return colorSet[Math.floor(Math.random() * colorSet.length)];
}


chromo= new Array('pink', 'red', 'orange', 'yellow', 'teal', 'green', 'blue', 'purple');
hot= new Array('pink','orange');

function assignColors(colorArray) {
	for ( var eachsq=1;eachsq<sqnum+1;eachsq++ ) {		
		 var sqArr = getElementsByClass('sq'+eachsq)
		 var colorChoice = getRandColor(colorArray);
		 for ( i=0;i<sqArr.length;i++ ) {
		 	sqArr[i].className+=' '+colorChoice
		}
	}
}
	
function changeColors(colorArray, colorArrFather) {
 var sqpick = Math.floor(Math.random() * sqnum +1);
 var sqArr = getElementsByClass('sq' + sqpick);
 var colorChoice = getRandColor(colorArray);
  if (colorArray != null && colorArrFather == undefined)
 		colorArrFather = colorArray;
  if (colorArray == undefined){
 	colorArray = chromo;
 	colorArrFather = chromo;
 }
 
 for ( i=0;i<sqArr.length;i++ ) {
   for ( d=0;d<colorArrFather.length;d++ ) {
		sqArr[i].className=sqArr[i].className.replace(" "+colorArrFather[d], "");
		}
	sqArr[i].className+=" " + colorChoice;					
 }

  var timeoutFunc = function() {changeColors(colorArray,colorArrFather)};
 
setTimeout(timeoutFunc, Math.random() * ((360/sqnum)*75)+50);
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}