// JavaScript Document
(function () 
{
	function $id(el)
	{
		return document.getElementById(el);
	}
	function $tn(el)
	{
		return document.getElementsByTagName(el);	
	}
	$(document).ready( function ()
	{
		// if the default get updates value changes you have to change it here
		var loadEmailValue = 'Email Address'; //$id('email_input').value;
		
		//////////////////////////////////////////////////////////////////////////////////////////
		//////   add this function to validate email address on submit
		$('#updates_form').submit( function(ev)
		{
				//validate form
				var email_content = $('#email_input').val();
							
				if (  email_content == '' || email_content == loadEmailValue ) {
					alert('Please enter your email address.');
					return false;
				} else { // the email address has been entered
					if ( !email_content.match(/^.+@.+\.[a-z]{2,6}$/) ) {
						alert('Your email address seems to be invalid.');
						return false
					} else {
						return true
						//$('#updates_form');
					}
				}// end if they entered any content				
		}); // end add submit event;
			
		
		///////////////////////////////////////////////////////////////////////
		// replace the default text in the email value
	
	
		$('#email_input').focus( function()
		{
				if ( $id('email_input').value == loadEmailValue ) {
					$id('email_input').value = '';
				}
		});
			
		// replace the default text in the email value
		$('#email_input').blur( function()
		{
				if ( !$id('email_input').value.match(/\S/) ) { // if you do not match something other than white space
					$id('email_input').value = loadEmailValue;
				}
		});
		//////////////////////////////////////////////////////////////////////
		//   add this as a sucker fish drop down fix
		// for all the li children of naviagation add a function. that function calls a jquery on 'this' ( what ever current element) to have a mouse over/out event
		$('#navigation > li').each( function(i)
		{ 	$(this).mouseover( function () 
			{ 
				
				this.className +=" sfhover"; // add the class name
			});
			$(this).mouseout( function()
			{
				//alert( this.className );
				this.className = this.className.replace(/sfhover/g, ""); // remove the class name (globally = or all matches)
				
			});
		});
		///////////////////////////////////////////////////////////////////////
		// replace the target in the footer - used instead of rel='external'
		var i = 0;
		while ( $tn('a')[i] ) {
			if( typeof  $tn('a')[i].getAttribute('rel') != 'undefined' &&  $tn('a')[i].getAttribute('rel') == 'external'  ) { 
				 $tn('a')[i].target = "_blank";
			}
			i++;
		}
	}); // close document ready

}) ();
