function addActions(cell){
	
	cells = getDateCells();
	for (var i=0; i<cells.length; i++){
		Event.add(cells[i],'mouseover',highlight);
		Event.add(cells[i],'mouseout',unhighlight);
	}
	
}

function highlight(){
	changeCourseRefColor(this,'orange');
}

function unhighlight(){
	changeCourseRefColor(this,'');
}

function changeCourseRefColor(targetCell,color){
	var targetRowClasses = targetCell.parentNode.className.split(" ");
	var targetCourse =  targetRowClasses[1];
	
	cells = getDateCells();
	for (var i=0; i<cells.length; i++){
		var rowClasses = cells[i].parentNode.className.split(" ");
		var course = rowClasses[1];
		
		if(course == targetCourse)
			cells[i].style.backgroundColor = color;
	}	
}

function getDateCells(){
	var returncells = new Array();
	
	tables = document.getElementsByTagName('table');
	
	for (var i=0; i<tables.length; i++){

		if (tables[i].className == 'calendar'){

			var tbody = tables[i].getElementsByTagName('tbody');
			var cells = tbody[0].getElementsByTagName('td');
			
			var j;
			for (j=0; j<cells.length; j++){
				if (cells[j].className == 'date'){
					returncells = returncells.concat(new Array(cells[j]));
				}
			}
		}
	}
	return returncells;
}

var Event = {
		add: function(obj,type,fn) {
			if (obj.attachEvent) {
				obj['e'+type+fn] = fn;
				obj[type+fn] = function() { obj['e'+type+fn](window.event); }
				obj.attachEvent('on'+type,obj[type+fn]);
			} else
			obj.addEventListener(type,fn,false);
		},
		remove: function(obj,type,fn) {
			if (obj.detachEvent) {
				obj.detachEvent('on'+type,obj[type+fn]);
				obj[type+fn] = null;
			} else
			obj.removeEventListener(type,fn,false);
		}
	}




window.onload = addActions
