sfHover = function() {
	$$('#menu li').each(function(li) {
		li.onmouseover=function() {
			this.addClassName("sfhover");
		}
		li.onmouseout=function() {
			this.removeClassName("sfhover");
		}
	});
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

var footerOverallHeight = 0;
var footerElements = ['footer'];
var contentElements = ["body", "header"];
var contentOverallHeight = 0;

maximisePageHeight = function() {
	contentOverallHeight = 0;
	contentElements.each(function(element) {
	  element = $(element);
		contentOverallHeight = contentOverallHeight + element.getHeight() + parseInt(element.getStyle('marginTop')||0) + parseInt(element.getStyle('marginBottom')||0);
	});
	
	required_height = parseInt(document.viewport.getHeight() - footerOverallHeight);

  page_container = $('page');
	if (contentOverallHeight < required_height) {
		page_container.setStyle({'height': (required_height - parseInt(page_container.getStyle('paddingTop')||0) + parseInt(page_container.getStyle('paddingBottom')||0)) + "px"});
	} else {
	  page_container.setStyle({'height': contentOverallHeight + "px"});
	}
}

if (FastInit) {
	FastInit.addOnLoad(function()
	{
		footerElements.each(function(element) {
			footerOverallHeight = footerOverallHeight + $(element).getHeight() + parseInt($(element).getStyle('marginTop')||0) + parseInt($(element).getStyle('marginBottom')||0);
		});
		
		maximisePageHeight();
		
		Event.observe(document.onresize ? document : window, "resize", maximisePageHeight);
		
		if ($('body_content_right').innerHTML.gsub(/(\n|\r|\t|[" "])/, "").length == 0){
			$('body_content_right').hide();
			$('body_content_left').addClassName('no_body_content_right');
		}

		[$$('#body_content_right p').first(), $$('#body_content_left p').first()].compact().each(function(first_paragraph) {
			first_paragraph.addClassName('first_paragraph');
		});
		
		$$('#body_content p img', '#body_content p iframe').each(function(media) {
			media.up('p').addClassName('with_media');
		});
		
		$$('table').each(function(table) {
			odd = true;
			table.select('tr').each(function(tr) {
				tr.addClassName(odd ? 'odd' : 'even');
				[tr.select('td').first(), tr.select('th').first()].compact().first().addClassName('first_column');
				[tr.select('td').last(), tr.select('th').last()].compact().first().addClassName('last_column');
				odd = !odd;
			});
		});
		
		$$('.homepage #weekly_schedule').each(function(schedule){
			schedule.select('table').each(function(table) {
				table.select('th').first().innerHTML = "&nbsp;";
				table.select('td').each(function(cell) {
					if (cell.innerHTML.gsub(/(\n|\r|\t|[" "])/, "") == "x") {
						cell.innerHTML = "•"
						cell.addClassName("filled");
					}
				});
			});
			
			box = new Element("div", {id: 'schedule_box'});
			schedule.insert(box);
			schedule.childElements().each(function(child) {
				if (child.tagName.toUpperCase() != "H2") {
					try {
						box.insert(child);
					}catch($e){} // not sure why it reports an error.
				}
			});
		});
		
		if ((iframe_box_top = $('iframe_box')) != null) {
			var img_top = new Element("img", {id: 'yoga_frame_top', src: '/images/yoga_symbol_frame.png'});
			var img_bottom = new Element("img", {id: 'yoga_frame_bottom', src: '/images/yoga_symbol_frame.png'});
			
			iframe_box_top.insert(img_top);
			iframe_box_top.insert(img_bottom);
		}
		
		if ((iframe = $$('#body_content_left iframe').first()) != null) {
			var img_top = new Element("img", {id: 'yoga_frame_top', src: '/images/yoga_symbol_frame.png'});
			var img_bottom = new Element("img", {id: 'yoga_frame_bottom', src: '/images/yoga_symbol_frame.png'});
			var iframe_box = new Element("div", {id: 'iframe_box'});
			
			$('body_content_left').insertBefore(iframe_box, iframe);
			iframe_box.insert(img_top);
			iframe_box.insert(iframe);
			iframe_box.insert(img_bottom);
			
			iframe_box.style.height = img_top.getHeight() + iframe.getHeight() + img_bottom.getHeight() + "px";
		}
		
		maximisePageHeight();
	});
}
$(document).observe("dom:loaded", maximisePageHeight);