$(document).ready(function() {
			
	$('.chubbyness').fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'titleShow' : false,
		'overlayOpacity' : .85,
		'overlayShow'	:	true
	});

	$('.iframe').fancybox();
	
	$('#featuredBox2').cycle({
		fx: 'fade', 
		timeout: 12000,
		pause: 1,
		pager: '#nav',
		cleartypeNoBg: true
	});
			
   	//show/hide everything
	$('.toggle').hide();
	$('.toggler').click(function() {
		$('.toggle').toggle("slow");
		return false;
	});
		
	//sexy-up the create-account form
	if ($('#applyCode')[0]) {
		$('#couponWorked').hide();
		$('#applyCode').click(function() {
			if ($('#coupon_code').val().length > 0) {
				$.ajax({
					url: '/apply_coupon.php',
					type: 'post',
					data: 'coupon=' + $('#coupon_code').val(),
					dataType: 'json',//yeah you need this
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						
					},
					success: function(data, textStatus, XMLHttpRequest) {
						if (!data.error) { //coupon successful
							var days_free = parseInt(data.free_months) * 30;
							var message_cost = parseFloat(data.message_cost).toFixed(2);
							var monthly_fee = parseFloat(data.monthly_fee).toFixed(2);
							var theString = '<span>Coupon Accepted</span><ul>';
							theString += '<li>Coupon: ' + data.discount_code + '</li>';
							theString += '<li>Monthly Fee: $' + data.monthly_fee + '</li>';
							theString += '<li>Free Months: ' + data.free_months + '</li>';
							theString += '<li>Message Cost: $' + data.message_cost + '</li>';
							theString += '<li>Keyword Tokens: ' + data.default_tokens + '</li>';
							theString += '<li>Extra Keyword Cost: $' + data.token_cost + '</li>';
							theString += '<li>Clients: ' + data.default_clients + '</li>';
							theString += '<li>Extra Client Cost: $' + data.extra_client_cost + '</li></ul>';
							
							$('#couponWorked').html('');
							$('#couponWorked').append(theString);
							$('.days_free').text(days_free);
							$('.system_cost').text(monthly_fee);
							$('.message_cost').text(message_cost);
							$('.free_until').text(data.trial_until);
							$('#couponWorked').fadeIn('slow');
						}
						else { //bad coupon, no donut
							var theString = '<span>Invalid Coupon</span>';
							$('#couponWorked').html('');
							$('#coupon_code').val('');
							$('#couponWorked').append(theString);
							$('#couponWorked').fadeIn('slow');
						}
					}
				});
			}
			return false;
		});
	}
	
	
	
	//See what kind of card they're using
	$('#credit_card_number').blur(function(){
		//Visa = 4
		//Master = 51, 55
		//Amex == 34, 27
		var visaValue = $(this).val().substr(0,1);
		var otherValue = $(this).val().substr(0,2);
		
		if (visaValue == '4'){
			$('#masterLogo').addClass('fadethis');
			$('#amexLogo').addClass('fadethis');
			$('#visaLogo').removeClass('fadethis');
		}
		
		if (otherValue == '51' || otherValue == '55'){
			$('#visaLogo').addClass('fadethis');
			$('#amexLogo').addClass('fadethis');
			$('#masterLogo').removeClass('fadethis');
		}
		if (otherValue == '34' || otherValue == '27' || otherValue == '37'){
			$('#visaLogo').addClass('fadethis');
			$('#masterLogo').addClass('fadethis');
			$('#amexLogo').removeClass('fadethis');
		
		}
		
	});
	
	
	//Work some expiration date magic = the power of apparently influencing the course of events by using mysterious or supernatural forces.   some what?!
	var previousValue = '';
	$('#credit_card_expire').focus(function(){
		if($(this).val() == 'mm/yyyy'){
			previousValue = $(this).val();
			$(this).val('');
		}
	});
	$('#credit_card_expire').blur(function(){
		if($(this).val() == ''){
			$(this).val(previousValue);
		}
	});
	
	
	$('#dhjdx-dhjdx').focus(function(){
		if($(this).val() == 'email@domain.com'){
			previousValue = $(this).val();
			$(this).val('');
		}
	});
	
	$('#dhjdx-dhjdx').blur(function(){
		if($(this).val() == ''){
			$(this).val('email@domain.com');
		}
	});
		
});






























