$(document).ready(function(){

// site variables used throughout this sheet
	var stSpeed 	= 1000;									// scroll to speed
	var mySlideShow = $("div.mySlideShow")					// slide show
	var contactForm	= $("#contactForm")						// contact form (1 of 2 forms on the page)
	var appForm		= $("#appForm")							// app form (2 of 2 forms on the page)

/*
// lazy load for images
   $("img").lazyload({         
     threshold		: 200,
     effect			: "fadeIn"
   });
*/

// drop down menus
	$('#navigation > li').bind('mouseover', jsddm_open);
	$('#navigation > li').bind('mouseout',  jsddm_timer);

// turns off the border on the first .divider 
	$(".divider:first").css('border-top','0');
	
// scroll to with click
	$("a.scrollMe").click(function(){
		var whereTo = $(this).attr('to');					// var the a[name]
		$.scrollTo( "a[name=" + whereTo + "]" , stSpeed );	// scroll to a[name]
	})
// scroll to with anchors
	if ( $.url.attr("anchor") ){
		var whereTo = $.url.attr("anchor");					// var the anchor from the url
		$.scrollTo( 0 );									// go to the top first
		$.scrollTo( "a[name=" + whereTo + "]" , stSpeed );	// then scroll to anchor
		if ( whereTo == 'application' ) {
			$("#appForm input[name=fname]").focus();
		}
	}

// slide show
	mySlideShow.cycle({ 
		random		: 1
	});
	
// validate
	contactForm.validate({ 									// first form
		rules: {
			fname	: "required",
			lname	: "required",
			email	: 
				{
				required: true, email: true
				},
			phone	: "required",
			to		: "required",
			message	: "required",
			human	:
				{
				required: true, equalTo: '#captcha'
				}
		}
	});

	appForm.validate({										// second form
		rules: {
			fname		: "required",
			lname		: "required",
			email		: 
				{
				required: true, email: true
				},
			position	: "required",
			phone		: "required",
			city		: "required",
			state		: "required",
			zip			: 
				{
				required: true, digits: true
				},
			address1	: "required",
			myResume	: "required",
			sex			: "required",
			race		: "required",
			human		:
				{
				required: true, equalTo: '#captcha2'
				}
		}
	});

// masked input
	$(function($){
 	  $("input[name=phone]").mask("(999) 999-9999");
 	  $("input[name=zip]").mask("99999");
	});

}) // dom ends

var timeout    = 600;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   $(this).addClass('myActiveLink');
   ddmenuitem = $(this).find('ul').css('display','block');
   }

function jsddm_close()
{  if(ddmenuitem) {
		ddmenuitem.css('display', 'none');
		$("#navigation li").removeClass('myActiveLink'); 
	}	
}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

document.onclick = jsddm_close;

