$(document).ready(function(){
	//start faq directives
	$('.faq_answer').hide();
	
	var questions = $('.faq_question');
	for (i = 0; i < questions.length; i++) {
		questions[i].style.cursor='pointer';
	}
	
	$('.faq_question').click(function(){
		var id = $(this).attr('id');
		id = id.split('question_').join('');
		
		$('.faq_answer').hide('fast');
		$('#answer_' + id).show('slow');
	});//end faq
	
	
	
	//start paypal directives
	if ($('input[@name=payment_method]').val()) {
		switch_payments();
	}
	
	$('input[@name=payment_method]').click(function(){
		switch_payments();
	});//end paypal
	
	
	
	//start shipping directives
	if ($('input[@name=ship_to]').val()) {
		switch_shipping();
	}
	
	$('input[@name=ship_to]').change(function(){
		switch_shipping();
		switch_state_province('shipping');
	});//end shipping
	
	
	
	//start state / province directives
	if ($('select[@name=billing_information_country]').val()) {
		switch_state_province('billing');
	}
	if ($('select[@name=shipping_information_country]').val()) {
		switch_state_province('shipping');
	}

	$('select[@name=billing_information_country]').change(function(){
		switch_state_province('billing');
	});

	$('select[@name=shipping_information_country]').change(function(){
		switch_state_province('shipping');
	});//end state / province
});




function switch_state_province(section) {
	var domestic = $('select[@name=' + section + '_information_country]').val() == 'United States';
	
	switch (domestic) {
		case true:
			$('input[@name=' + section + '_information_province]').parent().hide('slow');
			break;
		
		case false:
			$('input[@name=' + section + '_information_province]').parent().show('slow');
			break;
	}
}



function switch_payments() {
	var showing = $('input[@name=payment_method]:checked').val();
	
	switch (showing) {
		case 'Credit Card':
			$('.paypal').hide('slow',function(){
				$('.credit_card').show('slow');
			});
			break;

		case 'PayPal':
			$('.credit_card').hide('slow',function(){
				$('.paypal').show('slow');
			});
			break;
	}
}




function switch_shipping() {
	var showing = $('input[@name=ship_to]:checked').val();
	
	switch (showing) {
		case 'shipping':
			$('.shipping').show('slow');
			switch_state_province('shipping');
			break;

		case 'billing':
			$('.shipping').hide('slow');
			break;
	}
}