// remap jQuery to $
(function($){})(window.jQuery);

$(document).ready(function (){
	$("#socialTwitterClick").live("click", function() {
		$("#socialArrow").animate({
        	marginTop: "17px"
		}, 500);
		$("#socialFacebook").hide();
		$("#socialYouTube").hide();
		$("#socialTwitter").fadeIn(500);
	});
	$("#socialFacebookClick").live("click", function() {
		$("#socialArrow").animate({
        	marginTop: "70px"
		}, 500);
		$("#socialTwitter").hide();
		$("#socialYouTube").hide();
		$("#socialFacebook").fadeIn(500);
	});
	$("#socialYouTubeClick").live("click", function() {
		$("#socialArrow").animate({
        	marginTop: "123px"
		}, 500);
		$("#socialTwitter").hide();
		$("#socialFacebook").hide();
		$("#socialYouTube").fadeIn(500);
	});
	
	$("#commentForm").submit(function() {
		$.ajax({
			type: "POST",
			url: "http://ktdiaries.com/wp-content/themes/ktdiaries/_/php/submit.php",
			data: "realname=" + $("#name").val() + "&email=" + $("#email").val() + "&address=" + $("#address").val() + "&zip=" + $("#zip").val() + "&phone=" + $("#phone").val() + "&message=" + $("#message").val(),
			success: function(){
				$('#commentForm').hide("fast", function(){$('div.successes').fadeIn();});
			},
			error: function(){
				$('#commentForm').hide("fast", function(){$('div.errors').fadeIn();});
			}
		});
		return false;
	});
	
	function resizeContent() {
		/*
		var contentHeight = $("#content").outerHeight();
		var contentOffset = $("#content").offset();
		var contentTop = contentOffset.top;
		var contentBottom = contentTop + contentHeight;
		var headerHeight = $("#head").outerHeight();
		var headerBottom = 35+90+headerHeight;
		var adHeight = $("#ADspace").outerHeight();
		var adOffset = $("#ADspace").offset();
		var adTop = adOffset.top;
		var adBottom = adTop + adHeight;
		
		if(contentBottom >= adBottom) {
			//Large
			$(".post, .entry").css("height", (contentHeight-467)+80);
			$("#ADspace").show();
		}
		else if(contentBottom >= headerBottom && contentBottom < adBottom) {
			//Medium
			$(".post, .entry").css("height", (contentHeight-467)+230);
			$("#ADspace").show();
		}
		else {
			//Small
			$("#ADspace").hide();
		}
		*/
		
		/*
		var contentHeight = $("#content").outerHeight();
		if(contentHeight >= 467) {
			$('#spacer').css("height", contentHeight-467+80);
			
			var spacerHeight = $("#spacer").height();
			var adHeight = $("#ADspace").outerHeight();
			
			if(spacerHeight > adHeight+60)
				$("#ADspace").show();
			else
				$("#ADspace").hide();			
		}
		*/
		
		var adHeight = $("#ADspace").outerHeight()+60;
		var greenHeight = $("article").outerHeight()-380;
		
		if(greenHeight >= adHeight)
			$("#ADspace").show();
		else
			$("#ADspace").hide();
	}
	
	resizeContent();
});
