function changeTitle(newTitle) {
	document.title=newTitle;
}

$(document).ready(function(){
	

var pageTitle = $('.pageTitle').text();
var newTitle = $('title').html();
newTitle += ' - '+pageTitle;
changeTitle(newTitle);

// Resize Videos if wider than 500px
if(pageTitle.match(/video/i)) {
	var vid = $('#videos object embed');
	var vidWidth = vid.attr('width');
	
	if(vidWidth>500) {
		var vidHeight = vid.attr('height');
		var ratio = vidWidth/vidHeight;
		var newHeight = Math.round(500/ratio);
		vid.attr('width', 500).attr('height', newHeight);
	}
}

if(pageTitle.match(/contact/i)) {
	$('#first').focus();
}

$('#contactSubmit').click(function(){
	$('.error').hide();
	
	var first = $('#first').val();
	if(!first.match(/\S+/)) {
		$('#first_error').show();
		$('#first').focus();
		return false;
	}
	var last = $('#last').val();
	if(!last.match(/\S+/)) {
		$('#last_error').show();
		$('#last').focus();
		return false;
	}
	var company = $('#company').val();
	var email = $('#email').val();
	if(!email.match(/\S+/)) {
		$('#email_error').show();
		$('#email').focus();
		return false;
	}
	var message = $('#message').val();
	if(!message.match(/\S+/)) {
		$('#message_error').show();
		$('#message').focus();
		return false;
	}
	var referral = $('#referral').val();
	if(!referral.match(/\S+/)) {
		$('#referral_error').show();
		$('#referral').focus();
		return false;
	}
	
	$.post('../include/contact.php',{first:first, last:last, company:company, email:email, message:message, referral:referral},
		function(data) {
			$('#contact form').hide();
			$('#pageContent').after(data);
			return false;
		}
	);
	return false;
});

// Expand Blog Month
$('.blogMonthYear').click(function(){
	$(this).next('div').slideToggle('slow');
});

}); // END document.ready
