Event.observe(document, "dom:loaded", alignButtons);  //OnLoad listener for the window object.  This executes after the page is fully loaded.
Event.observe(document, "dom:loaded", tagLast);
Event.observe(document, "dom:loaded", candyStripe);

function alignButtons() {
	var buttons = $$('.callout'); //Select all HTML elements with className "callout"

	//Loop through them and position them at the bottom of their parents
	for(var i = 0; i < buttons.length; i++) {
		var pars = buttons[i].ancestors();
		var par;
		for(var j = 0; j < pars.length; j++) {
			if(pars[j].hasClassName('mc')) {
				par = pars[j];
				break;
			}
		}
		
		if(par) {
			var btn = buttons[i];
			var parH = par.getHeight();
			var btnH = btn.getHeight();
			var top = parH - btnH - 15;
			
			par.setStyle({position:'relative'});
			btn.setStyle({position:'absolute',top:top+'px',left:'16px',display:'block'});
		}
	}
}

function tagLast() {
	var ul = $$('ul');
	for(var i = 0; i < ul.length; i++) {
		var li = ul[i].select('li:last-child');
		li[0].addClassName('last');
	}
}

function candyStripe() {
	//Grab all the odd numbered rows in all tables
	var rows = $$('table tr:nth-child(odd)');
	
	//Apply the 'alt' CSS class to each of the odd numbered rows
	rows.each(function(obj) { obj.addClassName('alt'); });
}
