/*  Vx custom Javascript file
 *  © 2006-2007 by Edd Couchman
 *  
 *  Requires prototype, script.aculo.us, and low pro
 *  this script has been validated using javascriptlint.com
 *  
 *  by using .bind(this) and .bindAsEventListener(this) one can use 'this'
 *  to reference functions, and 'self' to reference the local scope
 *  
 *------------------------------------------------------------------------*/

var Vx = Class.create();
Vx.prototype = {
	Version: '1.1',
	Updated: '2007-07-09',
	Copyright: 'Edd Couchman, 2007 (vuture.co.uk, the-vx.com, and redheat.co.uk)',
	
	initialize: function()
	{
		Event.observe(window, 'load', this.matchColumns);
		Event.observe(window, 'load', this.clearForms);
	},
	
	clearForm: function(self) {
		self.removeClassName('defaultform');
		if ( $F(self) == self.defaultValue )
		{
			self.clear();
		}

		self.observe('blur', function() {
			if ( !self.present() )
			{
				self.value = self.defaultValue;
				self.addClassName('defaultform');
			}
		});
	},

	clearForms: function() {
		var input = $A(document.getElementsByTagName('input')); // array of all form elements

		input.each(function(self) {
			if ( (self.getAttribute('type') == 'text' || self.getAttribute('type') == 'password') && self.getAttribute('class') != 'edit' )
			{
				self.addClassName('defaultform');
				self.observe('focus', function()
				{
					this.clearForm(self);
				}.bindAsEventListener(this));
			}
		}.bind(this));
	},

	matchColumns: function()
	{
		var columns = $$('div.column');
		var column_height = 0;
		var max_height    = 0;
		
		columns.each(function(column)
		{
			column_height = column.offsetHeight;
			max_height = ( column_height > max_height ) ? column_height : max_height;
		});

		columns.each(function(column)
		{
			column.setStyle({
				height: max_height + 'px'
			});
		});
	}
};