$(document).ready(function() {

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

//Hides agreement, terms and payment
$(document).ready(function() {
	$("#invite-agreement").hide();
	$("#invite-terms").hide();
	$("#invite-payment").hide();
	$("#confirm").hide();
});

//Shows agreement, fades link
$(document).ready(function() {
	$("#show-agreement").click(function() {
	$("#invite-agreement").fadeIn("slow");
	$("#invite-terms").fadeIn("slow");
	$("#invite-overview .next").fadeTo("slow", .3);
	});
});

//Shows payment form, fades link
$(document).ready(function() {
	$("#inviteTermsAgree").click(function() {
	$("#invite-payment").fadeIn("slow");
	});
});

//makes rad labels for forms
$(document).ready(function(){
  $("label").inFieldLabels();
});

//payment math formula by Jonathan Cutrell

	$(document).ready(function(){
		(function($){
			//this function removes the current value of the input
			var wCalc = {}
			wCalc.circlePool = 33750;
			wCalc.circleTraffic = 21800000;
			wCalc.estInput = $('input#impressions');
			wCalc.targetSpan = $('span#estimate');
			var holdText = wCalc.estInput.val();
			wCalc.estInput.css({"color":"#888"});
			wCalc.estInput.bind("focusin", function(){
				if (wCalc.estInput.val() == holdText){
					wCalc.estInput.val('').css({"color":"#232323"})
				}
				$(document).bind("keyup", function(){
					wCalc.estInput.change()
				})
			});
			wCalc.estInput.bind("focusout", function(){
				$(document).unbind('keyup');
				if (wCalc.estInput.val() == ''){
					wCalc.estInput.val(holdText).css({"color":"#888"});
				}
			});
			wCalc.estInput.change(function(){
				var self = $(this);
				var estimate = (wCalc.circlePool/wCalc.circleTraffic)*parseInt(self.val());
				estimateString = "$" + estimate.toFixed(2);
				if (isNaN(estimate)){
					estimateString = "Please enter a number."
				}
				wCalc.targetSpan.empty().html(estimateString);
			});
		})(jQuery);
	})
	

