$(document).ready(function() {
	//Form validation
	$('form.requiredForm').submit(function() {
		$('form.requiredForm .error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
			if(jQuery.trim($(this).val()) == '') {
				var labelText = $(this).prev('label').text().replace('*','');
				$(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
				hasError = true;
			} else if($(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).prev('label').text().replace('*','');
					$(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
					hasError = true;
				}
			}
		});
		if(hasError) {
			return false;
		}
	});
	//End form validation

	//Homepage branding area
	var itemHeight = $('#branding .frame').height();
	var numItems = $('#branding .frame').length
	$('#branding .frames').height(itemHeight * numItems);
	$('#branding .nav a').click(function() {
		$('#branding .nav .current').removeClass('current');
		$(this).parent().addClass('current');
		var curPos =  $(this).parent().prevAll().length;
		curPos = curPos * itemHeight;
		curPos = '-' + curPos + 'px';
		$('#branding .frames').animate({'top':curPos}, 750);
		return false;
	});
	//End homepage branding area

	//Invesment Calculator
	function addFormField() {
		var id = $('#investmentCalculator #id').val();

		$('#investmentCalculator .addAnother').before("<li><label for='investment_name" + id + "'>Investment Name " + "</label><input type='text' name='investment_name" + id + "' id='investment_name" + id + "' /></li><li><label for='ticker_number" + id + "'>Ticker Number " + "</label><input type='text' name='ticker_number" + id + "' id='ticker_number" + id + "' /></li><li><label for='number_shares" + id + "'>Number of Shares " +"</label><input type='text' name='number_shares" + id + "' id='number_shares" + id + "' /></li><li><label for='dollar_value" + id + "'>Dollar Value " + "</label><input type='text' name='dollar_value" + id + "' id='dollar_value" + id + "' /></li>");
		id++;
		$('#investmentCalculator #id').val(id);
		if(id >= 20) {
			$('#investmentCalculator .addAnother').hide();
		}
	}
	$('#investmentCalculator .buttons').before('<li class="addAnother"><a href="#" id="addInvestment">Add Another Investment</a></li>');
	$('#investmentCalculator #addInvestment').click(function() {
		addFormField();
		return false;
	});
	//End investment calculator

});