// This is a constructor for a Div object. 
// It's only used to associate a div and a color to each other
// Could have used an Object instead but I think it makes the purpose
// clearer when using a home-brewn class
function Div(elt, color, border) {
	this.div = elt;
	this.color = color;
	this.border = border;
	}  
	// I store all Div objects in this variable between clicks
	var previousDivs = null;
	// Performs all the work. Takes an element and a color as default but
	// you can pass as many ids (strings) to elements after the color as you want.
	// The extra elements you pass as string ids will get their background set
	// as well.
function changeColor(elt, color, border) {
	// Change the color back on the elements you shifted on last click
	// but previousDivs will be null first time...
	if(previousDivs != null) {          
	for(var i = 0 ; i < previousDivs.length ; i++) {
	previousDivs[i].div.style.backgroundColor = previousDivs[i].color;
	previousDivs[i].div.style.border = previousDivs[i].border;
	}
	}
	// create a new Array to put your new Divs in
	previousDivs = new Array();
	// create a Div object for elt and pass it the element and its background color        
	previousDivs[0] = new Div(elt, elt.style.backgroundColor, elt.style.border);
	// set new color for elt
	elt.style.backgroundColor = color;
	elt.style.border = border;
	// loop over all the extra elements you passed in and do the same as for elt         
	/* for(var i = 2 ; i < arguments.length ; i++) {
	var currentDiv = document.getElementById(arguments[i]);
	previousDivs[previousDivs.length] = new Div(currentDiv,currentDiv.style.backgroundColor,currentDiv.style.border);
	currentDiv.style.backgroundColor = color;
	currentDiv.style.border = border;
	} */              
}

