var toggle = 'hidden';
var Site = {
	init: function() {
		//console.log('Site.init()');
		
		if ( $chk($('nav')) ) {
			Nav.init();
		}
		
		if ( $chk($('home')) ) {
			new CycleSlides({
				slides: $$('div#home_slides img'),
				automatic: true
			});
			
			new CycleSlides({
				slides: $$('div#home_testimonials p'),
				automatic: true
			});
		}
		
		if ( $chk($('our_team')) ) {
			new FancyZoom('pautler');
			new FancyZoom('taylor');
			new FancyZoom('enright');
			new FancyZoom('bruno');
			new FancyZoom('borrelli');
			new FancyZoom('garigen');
			new FancyZoom('leahy');
			new FancyZoom('jungjohann');
		}
		
		if ( $chk($('accounting_finance')) ) {
			new FancyZoom('taylor');
			new FancyZoom('enright');
			new FancyZoom('borrelli');
			new FancyZoom('bruno');
			new FancyZoom('garigen');
		}
		
		if ( $chk($('administrative')) ) {
			new FancyZoom('leahy');
			new FancyZoom('jungjohann');
		}
		
		if ( $chk($('human_resources')) ) {
			new FancyZoom('enright');
			new FancyZoom('garigen');
		}
		
		if ( $chk($('resources')) ) {
			new FancyZoom('interview');
			new FancyZoom('interview_q');
			new FancyZoom('resume');
			new FancyZoom('couchingit');
			new FancyZoom('difference');
		}
		
		if ( $chk($('community')) ) {
			SqueezeBox.assign($$('a[rel=boxed]'), {
				size: {x: 515, y: 415},
				ajaxOptions: {
					method: 'get'
				}
			});
		}
		
		if ($chk($('introvideo'))) {
			$$('html')[0].addEvent('click', function(e) {
				if (!($(e.target).match('#introvideo') || $(e.target).getParent('#introvideo'))){
					$('introvideo').fade('hide');					
					$('introvideo').set('html', '');
					toggle = 'hidden';
				}
			});
		}
		
		if ($chk($('introvideo'))) {
			$('introvideoClose').addEvents({
				'click': function(e){
					e.stop();
					$('introvideo').fade('hide');
					$('introvideo').set('html', '');
					toggle = 'hidden';
				}
			});
		}
		
		if ($chk($('introvideo'))) {
			$('introvideo').fade('show');
			toggle = 'show';
		}
		
		$('content').setStyle('height', $('copy').getStyle('height').toInt() + 40);
	}	
}

var Nav = {
	init: function() {
		//console.log("Nav.init()");
		
		$$('#nav li.nav_tab').each(function(el, i) {
			//console.log("My Height is: " + el.getStyle('height'));
			var nav_img = el.getElement('.nav_img');		
			
			var nav_img_src = nav_img.get('src');
			nav_img.set('src', 'images/nav/replacement.gif');
			nav_img.setStyle('background-image', "url('" + nav_img_src + "')");
			
			var nav_img_fx = new Fx.Morph(nav_img, {
				duration: 125,
				link: 'cancel'
			});
			
			var submenu_height = el.getStyle('height') + 10;
			
			var nav_tab_fx = new Fx.Morph(el, {
				duration: 125,
				link: 'cancel'
			}).set({
				'height': 48
			});
			
			el.addEvents({
				'mouseover': function(){
					if (! el.hasClass('active')) {
						nav_img_fx.start({
							'background-color': '#606060'
						});
						
						nav_img.setStyle('background-position', '0px -48px');
					}				
					
					nav_tab_fx.start({
						'height': submenu_height,
						'z-index': 3000
					});
					
				},
				'mouseleave': function(){
					if (! el.hasClass('active')) {
						nav_img_fx.start({
							'background-color': '#cccccc'
						});
						
						nav_img.setStyle('background-position', '0px 0px');
					}				
					
					nav_tab_fx.start({
						'height': 48,
						'z-index': 100
					});
					
					
				},
				'click': function(){
					//console.log('click');
				}
			});
		});
	}	
}

window.addEvents({
	'domready': function() {
		//console.log('DOM Ready');
		Site.init();
	},
	
	'load': function(){
		//console.log('Locked and Loaded');
	}
	
});

function checkForm(form) {
	required_fields = ['First Name', 'Last Name', 'Address', 'City', 'State', 'E-mail Address'];
	var errorList = '';
	
	for (i = 0; i < required_fields.length; i++) {
		field_name = required_fields[i].replace(/ /,'');
		if (form.elements[field_name].value == '') {
			errorList += '* '+required_fields[i]+'\n';
		}
	}
	
	if ( form.elements['HomeAreaCode'].value == '' || form.elements['HomeExchange'].value == '' || form.elements['HomePhoneNumber'].value == '') {
		errorList += '* Home Phone Number\n';
	}

	if (form.elements['Resume'].value == '' || form.elements['ResumeFile'].value == '') {
		errorList += '* Resume\n';
	}
		
	if (errorList != '') {
		alert ('The following fields are required:\n' + errorList);
		return false;
	}
}