$(document).ready(function() {

	// check js
	$('body').addClass('js');
	
	// loads form from ajax or fade in if already present
	$('a#loadContactForm').click(function() {
		if($.find('#ajaxCollect').length) {
			$contactform.show();
		} else {
			$('body').append('<div id="contactform"><div id="form"></div><div id="blackout"></div></div>');
			var $contactform = $('#contactform');
			$('#floatbox').addClass('poppedup');
			$('#contactform #form').load('/corporate/contact-us/contact-form.asp #ajaxCollect', function() {
				$('form label.other').hide();
				var $emailPos = parseInt($('#floatbox').css('top')) + 280;
				if($emailPos < 300) {
					var $pos = 58;
				} else {
					var $pos = $emailPos;
				}
				//console.log("'" + $emailPos + "'");
				//$('#contactform #form').css('stop', $pos + 'px');
				showOther($('#ajaxCollect form select#cHear'));
				showOther($('#ajaxCollect form select#cSpeak'));
				$('#ajaxCollect form').validate({
					messages: {
						cHear: 'Required.',
						cSpeak: 'Required.'
					}									
				});
				$('#contactform #form').append('<a href="#" id="closeContactForm">Close Window</a>');
				overlayFull();
			});
			$contactform.show();
			$('html, body').animate({scrollTop:0}, 1);
		}
		return false;
	});
	
	$('#closeContactForm, #blackout').live('click', function(event) {
		$('#contactform').children().hide();
		$('#contactform').remove();
		$('#floatbox').removeClass('poppedup');
		return false;
	});
	
	// scroll follow
	$('#floatbox').scrollFollow({
		container: 'wrapper',
		offset: 60,
		speed:1000,
		delay: 50
	});
});


// makes div entire size
function overlayFull() {

	var wHeight = $('body').height();
	var wWidth = $(window).width();

	// add css
	$('#blackout').css('width', wWidth);
	$('#blackout').css('height', wHeight);

	$(window).resize(function() {
		wWidth = $(window).width();

		// add css
		$('#blackout').css('width', wWidth);
		$('#blackout').css('height', wHeight);
	});

}

// show and hide other input
function showOther($selectbox) {
	$selectbox.change(function() {
		if($(this).val() == 'Other') {
			$(this).parent().next('.other').show();
			//$(this).parent().next('.other > input').addClass('required');
		} else {
			$(this).parent().next('label.other').hide();
			//$(this).parent().next('.other > input').removeClass('required');
		}
	});	
}