
undefined;

// ---------------------------------------------------------------------------- //
/*	String.trim()
*/
// ---------------------------------------------------------------------------- //

String.prototype.trim = function()
{
	var	str = this.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}


// ---------------------------------------------------------------------------- //
/*	lz_validate_inputs
	
	This function accepts a series of HTML objects and checks their value.
	
	It assumes these fields will have <label>s with ids that are the same as 
	the field + "_req" (e.g., f_name & f_name_req) if that field is required.
	
	It also assumes any email address in the form will end with '_email'.
	
	In the case of radio buttons, the first element should have an id the same
	as the name, but no others should have ids. Other input types should have
	the same name and id.
	
	Any field that does not contain data will have its label's class changed
	to "required". The class name is cleared every time data is found in a 
	required fields, so class names shouldn't carry class names of their own.
*/
// ---------------------------------------------------------------------------- //

function lz_validate_inputs( inputs )
{
	var			n = inputs.length;
	var			form_ok = true;
	
	for( var i = 0; i < n; i++ )
	{
		var		id = inputs[i].id;
		var		req = document.getElementById( id + "_req" );
		
		if( req != undefined )
		{
			var		value = '';
			
			if( inputs[i].type == 'radio' )	// Note: Radio Group name must be same as id.
				value = get_radio_value( inputs[i].name );
			
			else if( inputs[i].type == 'checkbox' )
				value = inputs[i].checked ? inputs[i].value : '';
			
			else
				value = inputs[i].value;
				
			if( value.trim() == '' )
			{
				req.className = 'required';
				form_ok = false;
			}
			else
			{
				if( id.substr( id.length-6, 6 ) == '_email' )
				{
					if( value.search( "^[A-Za-z0-9._\\-]+@[A-Za-z0-9._\\-]+\\.[A-Za-z]{2,4}$" ) == -1 )
					{
						req.className = 'required';
						form_ok = false;
					}
					else
						req.className = '';
				}
				else
					req.className = '';
			}
		}
	}
	
	if( !form_ok )
		alert( "Please complete the required fields, highlighted in red." );
	
	return form_ok;
}

// ---------------------------------------------------------------------------- //
/*	Show and hide menus.
*/
// ---------------------------------------------------------------------------- //

// Requires jQuery 1.3.2 or later
function show_menu( id )
{
	$("#" + id + "_link").addClass('hovered');
	$("#" + id + "_menu").show();
}

function hide_menu( id )
{
	$("#" + id + "_link").removeClass('hovered');
	$("#" + id + "_menu").hide();
}


// ---------------------------------------------------------------------------- //
/*	Fade_In_Scroller

	March the headings up the screen and transition to the final green and white
	text box. For the welcome page only.
	
	Requires jQuery. Written for v1.3.2.
	
	This has been set up as an object for the purposes fo containing like variables
	only. Since only one instance is running, there was no need to complicate it by
	making setInterval work with multiple instances.
*/
// ---------------------------------------------------------------------------- //

var g_scroller = 0;

function Fade_In_Scroller()
{
	this.self_id = this;
	this.scroll_dur = 20000;	// How long does it take to scroll the whole list?
	this.scroll_from = "310px";
	this.scroll_to = "-360px";
	this.refresh_rate = 100;	// Refresh graphics every x milliseconds.
	
	this.time_left = this.scroll_dur;
	this.start_time = 0;		// Helps to keep track of how long we've been scrolling for.
	this.interval_id = 0;

	this.fade_list = $("#marching_headings dl *");		// Grab all objects within the scrolling area.
	this.fade_count = this.fade_list.length;
	
	// ------------------------------------------------------------------------ //

	this.start_of_march = function ()
	{
		$("#marching_headings").bind( "mouseenter", g_scroller.halt );
		$("#marching_headings").bind( "mouseleave", g_scroller.march );
		$("#marching_headings").css( { top: g_scroller.scroll_from } )
		g_scroller.march();
	}
	
	// ------------------------------------------------------------------------ //

	this.march = function ()
	{
		var		date = new Date();
		
		g_scroller.start_time = date.getTime();
		
		$("#marching_headings").animate( { top: g_scroller.scroll_to }, g_scroller.time_left, "linear", g_scroller.end_of_march );
		interval_id = setInterval( "g_scroller.update_opacity();", g_scroller.refresh_rate );
	}
	
	// ------------------------------------------------------------------------ //

	this.halt = function ()
	{
		var		date = new Date();
		var		end_time = date.getTime();
		
		g_scroller.time_left = g_scroller.time_left - (end_time - g_scroller.start_time);
		if( g_scroller.time_left < 0 )
			g_scroller.time_left = 0;
		
		$("#marching_headings").stop();
		if( g_scroller.interval_id )
			clearInterval( g_scroller.interval_id );
		g_scroller.interval_id = 0;
	}
	
	// ------------------------------------------------------------------------ //

	this.end_of_march = function ()
	{
		$("#splash_foreground").fadeIn( "slow" );
		if( g_scroller.interval_id )
			clearInterval( g_scroller.interval_id );
		interval_id = 0;
	}
	
	// ------------------------------------------------------------------------ //

	this.update_opacity = function ()
	{
		var box_top = $("#marching_headings").position().top;
		
		for( var i = 0; i < g_scroller.fade_count; i++ )
		{
			var		item_top = $(g_scroller.fade_list[i]).position().top;
			var		item_offset = Math.abs( item_top + box_top - 145 );	
			// Last term adjusts the bottom of the transition area.
			var		item_opacity = (1 - ((item_offset - 80) / 70)).toFixed(2);
			// (1 - ((item_offset - x) / y)).toFixed(2);
			// Increasing x increases the area with 100%
			// Increasing y increases the area with > 0% opacity

			$(g_scroller.fade_list[i]).css( { opacity: "" + item_opacity, filter: "alpha(opacity=" + (item_opacity * 100).toFixed(0) + ")" } );
		}
	}
}

function init_welcome()
{
	g_scroller = new Fade_In_Scroller();
	g_scroller.start_of_march();
	
}

