/* jQuery Functions */
$(document).ready(function () {
	
	/* Partner RollOvers */
	$("dl.partner-list").hover(
		function () {
			$(this).children("dd").css({ display: 'block' });
			$(this).children("dt").fadeTo(121, .05);
		}, 
		function () {
			$(this).children("dt").fadeTo(121, 1, function(){
				$(this).children("dd").css({ display: 'none' });
			});
		}
	);
	
	/* Input fields auto clear/refill */
	$('input').focus(function () {
		$(this).css({ color: '#444444'});
		$(this).parent().css({ backgroundPosition: 'right -1000px' });
		
		if ($(this).val() == "( optional )") { $(this).val(""); };
    });

	$('input').blur(function () {
		if ( ($(this).val() == "") && $(this).hasClass("optional") ) {
			$(this).val("( optional )");
			$(this).css({
				color: '#cccccc'
			});
		};
    });

	/* Quick hide of validation notices */
	$('textarea').focus(function () {
		$(this).css({ color: '#444444' });
		$(this).parent().css({ backgroundPosition: 'right -1000px' });
    });

	$('select').focus(function () {
		$(this).parent().css({ backgroundPosition: 'right -1000px' });
    });

	/* Fade out any site messages after a few seconds */
	$('#site_message').css({ background: '#54a32e' })
	.animate({ opacity: 1.0 }, 4200)
    .fadeOut('slow', function() {
		$(this).remove();
	});
	
	/* Portfolio Slideshow */
	$('.folio-img').cycle({ 
		fx: 'scrollLeft', 
		speed: 690, 
		timeout: 4420,
		pause: 1
	});
});

/* Hide/Show Speaking Dates */
function showSpeaking(id) {
	$(id).animate({
		top: "37px"
	}, 210 );
	return false;
};

function hideSpeaking(id) {
	$(id).animate({
		top: "151px"
	}, 210 );
	return false;
};

/* Mail Form Validation */
function Validate(theForm) {
	isValid = true;
	
	theName = document.getElementById('name');
	theEmail = document.getElementById('eml');
	theSubject = document.getElementById('subject');
	theMessage = document.getElementById('message');
	
	nameWrap = document.getElementById('err_name');
	emailWrap = document.getElementById('err_eml');
	subjectWrap = document.getElementById('err_subject');
	messageWrap = document.getElementById('err_message');
	
	if (theName.value == '') {
		nameWrap.style.backgroundPosition = 'right 3px';
		isValid = false;
	}
	
	if (theEmail.value == '') {
		emailWrap.style.backgroundPosition = 'right -68px';
		isValid = false;
	} else {
		var str = theEmail.value;
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (!filter.test(str)) {
			emailWrap.style.backgroundPosition = 'right -68px';
			isValid = false;
		}
	}
	
	if (theSubject.value == '-1') {
		subjectWrap.style.backgroundPosition = 'right -142px';
		isValid = false;
	}
	
	if (theMessage.value == '') {
		messageWrap.style.backgroundPosition = 'right -210px';
		isValid = false;
	}
	
	if (isValid) {
		theForm.submit();
	}
};

/* Eml Protect */
function EmlWrt(dom, usr, output) { 
	if ((output.length == 0) || (output.indexOf('@')+1)) {
		document.write('<a href=' + '"mai' + 'lto:' + usr + '@' + dom + '">' + usr + '@' + dom + '<\/a>'); }
	else {
		document.write('<a href=' + '"mai' + 'lto:' + usr + '@' + dom + '">' + output + '<\/a>');
	}
};