// adds hover class for dropdown li's in IE.
$(function() {
	$(".nav>li").hover(
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); }
	);
});

$(document).ready(function(){
	// sets up index form values
	$('#username_input').autofill({
		value: 'Email'
	});
	$('#password_input').autofill({
		value: 'Password'
	});
	$('#find_a_cpa_input').autofill({
		value: 'Search by Name, City or State…',
		defaultTextColor: '#666',
		activeTextColor: '#333'
	});

	// Detects credit card type on cart form.
	$('#cc_number').keypress(function(e){

		var length = $(this).val().length;
		
		if (length == 0) {
			var firstChar = String.fromCharCode(e.which);
		} else {
			var firstChar = $(this).val().charAt(0);
		}

		$('#cc_type').attr('class', '');

		switch (firstChar) {
			case '3':
				$('#cc_type').addClass("amex");
			break;
			case '4':
				$('#cc_type').addClass("visa");
			break;
			case '5':
				$('#cc_type').addClass("mastercard");
			break;
			case '6':
				$('#cc_type').addClass("discover");
			break;
		}
	});

	$('a.help').click(function(){
		$('a.help').show();
		$(this).hide();
		$('.help_content').slideToggle();
		return false;
	});

	$('a.pay_by_check').click(function(){
		$('a.pay_by_check').show();
		$(this).hide();
		$('.personal_info, .cc_info, .submit_field').slideToggle();
		$('.pay_by_check_content').slideToggle();
		return false;
	});

	// fixes ie6 z-index issue with dropdown nav lists over selects
	// requires jquery.bgiframe.min.js
	$('.drop_nav').bgiframe();
  
  
  $('a.toggle').click(function(){
	var hiddenContent = $(this).prev('.hidden');
	$(hiddenContent).slideToggle();
		return false;
  });

	$('a.toggle').toggle (
		function(){
			$(this).text('close');
		},
		function(){
			$(this).text('more info');
		}
	);    
  
});
