Element.addMethods({
	switchClassNames: function(element, old_class, new_class) {
		// given two class names, the first will be removed from the element while the latter is added.  in other words,
		// if you have div.open and you call switchClassNames(div, "open", "closed") then the result will be a div.closed
		
		return $(element).removeClassName(old_class).addClassName(new_class);
	},
	
	printEmail: function(a) {
		if(a.tagName != "A" || (a.tagName=="A" && !a.href)) return;
		var data = a.href.parseQuery();					// returns a data = { n: "", d: "" } object
		if(data.n && data.d) {							
			var email = data.n + "@" + data.d;
			var display = a.readAttribute("rel"); 
			a.update(!display ? email : display).href = "mailto:" + email;
		} return a;
	},		
	
	vListHighlight: function(table) {
		if(table.tagName != "TABLE" && !table.hasClassName("v_list")) return;
		var headers = table.down("thead").select("tr").last().select("th").invoke("identify");
		table.select("td").each(function(cell) {
			cell.observe("mouseover",   highlight_column.bind(cell));
			cell.observe("mouseout",  dehighlight_column.bind(cell));
			
			// the header for this cell refers to an id listed in its headers attribute which is also a 
			// member of the headers Enumerable gathered above.  prototype's Enumerable functions allow
			// us to identify this header quickly.  then, we'll store it as a property of the cell
			
			cell.header  = $w(cell.readAttribute("headers")).find(function(h) { return headers.member(h) });
		}); return table;
	}
});

document.observe("dom:loaded", function() {
	// to protect email addresses from being harvested from our site, we've printed them as name AT somedomain.com in
	// a link to /contact.php.  however, for those people with JavaScript, we can enhance those links to act as simple
	// mailto: links without fear of harvesting.  the following line does just that by finding links to /contact.php
	// and altering their href and their contents.

	$$('a[href^=/contact.php]').invoke("printEmail");
	
	// on the site there maybe some tables in which we wish to highlight the column over which we're hovering. row 
	// highlighting can be done easily with CSS, but column highlighting is more difficult.  to initiate column
	// highlihgting, the v_list class must be added to the table.  after that, this code will invoke the Element
	// method added above.
	
	$$("table.v_list").invoke("vListHighlight"); 
	
	// and, if we find input fields of type "file" we're going to want to manipulate them to make them look appropriate
	// in our form styling.  since those fields cannot be styled by CSS very well, we'll use javascript to make things
	// work out.
	
	var file_inputs = $$("input[type=file]").each(function(input) { new File_Input_Hider(input); });
	
	$$("img[style]").each(function(img) {
		// TinyMCE uses inline floating CSS code but we'd rather use the left and right styles that we've defined
		// to assist in the proper margins and padding.
	
		var float = img.getStyle("float");
		if(float=="left" || float=="right") img.addClassName(float).writeAttribute("style");
	});
	
	$$("ul.menu").each(function(menu) { new ProtoFish(menu.identify(), 400, "hover", true); });
});

function print_email() { } // this was the old name of a function from the last site.  it's stubbed to avoid errors

// these two functions are called from the above table.v_list manipulations for column highlighting.  the first will find
// all cells within a table's body with the appropriate header and higlhight them, the second removes that highlighting. 
// these functions are bound (via prototpye) to cell over which the visitor is currently hovering.  note that the header
// property of the cell is set above.

function highlight_column() {   this.up("tbody").select("td[headers~=" + this.header + "]").invoke("addClassName", "highlight");    }
function dehighlight_column() { this.up("tbody").select("td[headers~=" + this.header + "]").invoke("removeClassName", "highlight"); }