var calendarCellFadeTo = '#233030';

if (window.addEventListener) {
	window.addEventListener('load', preps, false);
}
else {
	window.attachEvent('onload', preps);
}


function preps() {
	removeSomeButtonsCaptions();
	preloadImages('/wp-content/themes/grandma_garden/images/bullet_hover.gif', '/wp-content/themes/grandma_garden/images/goto_hover.gif', '/wp-content/themes/grandma_garden/images/goto_left_hover.gif');
	calendarCellHover();
}

// fade fx for table cells. Do fade on days with no associated entry, highlight days with one 
function calendarCellHover() {
	var calendar = document.getElementById('calendar');
	if (!calendar) {
		return;
	}
	var tbody = calendar.getElementsByTagName('tbody');
	if (!tbody.length) {
		return;
	}	
	cells = tbody[0].getElementsByTagName('td');
	for (i = 0; i < cells.length; i++) {
		cell = cells[i];
		has_entry = cell.getElementsByTagName('a').length > 0 ? true : false;
		if (has_entry) {
			cell.onmouseover = function() {
				this.style.cursor = 'pointer';
				this.style.backgroundColor = '#3b5351';
			}
			cell.onmouseout = function() {
				this.style.backgroundColor = 'transparent';
				//Fat.fade_element(makeSureId(this), 20, 800, '#3b5351', calendarCellFadeTo);
			}
		}
		else {
			cell.onmouseover = function() {
				this.style.cursor = 'default';
				this.style.backgroundColor = '#182222';			
				Fat.fade_element(makeSureId(this), 20, 800, '#182222', calendarCellFadeTo);
			}
		}
	}
}

function makeSureId(obj) {
	if (!obj.id) {
		var m = 1;
		var n = 10000;
		random_id = Math.floor(Math.random() * (n - m + 1)) + m;
		obj.id = random_id;
	}
	return obj.id;
}
