// Drop Down hack for IE6 & IE7
// Necessary for drop down to work properly in IE
window.startList = function() {	
	if (document.all&&document.getElementById) {		
		navRoot = document.getElementById("nav");		
		for (i=0; i<navRoot.childNodes.length; i++) {			
			node = navRoot.childNodes[i];			
			if (node.nodeName=="LI") {				
				node.onmouseover=function() {					
					this.className+=" over";				
				}				
				node.onmouseout=function() {					
					this.className=this.className.replace(" over", "");				
				}			
			}		
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", window.startList);

// Legacy JS, not sure what purpose it serves
var PAGERESULT = '888';	

// Used to validate the landing page form
function validateLandingPageForm() 
{	
	var form = document.getElementById('contactForm');	
	var valid = true;	
	var str = '';	
	
	if (form.name.value == '' || form.name.value == 'First Name')
	{		
		valid = false;		
		str = str + 'You forgot to include your name.\n'; 	
	}	
	if (form.message.value == '' || form.message.value == 'Legal Question?')
	{		
		valid = false;		
		str = str + 'You forgot to include your question.\n'; 	
	}		
	if (form.email.value == '' || form.email.value == 'Email')
	{		
		valid = false;		
		str = str + 'You forgot to include your email address.\n'; 	
	}
	if (form.email.value && form.email.value != 'Email')
	{		
		// Validate email		
		var filter = /^.+@.+\..{2,3}$/		
		if (!filter.test(form.email.value)) 
		{			
			valid = false;			
			str = str + 'The email address provided has an error.\n'; 		
		}	
	}
	if (form.phone.value && form.phone.value != 'Phone (optional)')
	{		
		// Validate phone number		
		var filter = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/		
		if (!filter.test(form.phone.value)) 
		{			
			valid = false;			
			str = str + 'The phone number provided has an error.\n'; 		
		}	
	}
	if (str) 
		alert(str);	
	return valid;
}

// blue functions
function focusControl(field, placeholder) 
{	
	if (field.value == placeholder) 
	{		
		field.value = '';		
		field.style.fontStyle = 'normal';	
	}
}

function blurControl(field, placeholder) 
{	
	if (field.value == '' || field.value == ' ') 
	{		
		field.value = placeholder;		
		field.style.fontStyle = 'italic';	
	}
}

// header image carousel
function slideSwitch() 
{
	var $active = $('#slideshow DIV.active');

	if ($active.length == 0) 
		$active = $('#slideshow DIV:last');

	var $next = $active.next().length ? $active.next()
		: $('#slideshow DIV:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() 
		{
			$active.removeClass('active last-active');
		});
}

$(function() {
	setInterval( "slideSwitch()", 5000 );
});
