/* Cufon Replacements */
Cufon.replace('.nav_list li a', {
	hover: true
});
Cufon.replace('.posttitle');
Cufon.replace('.entry_info h3');
Cufon.replace('.clicks');
Cufon.replace('.graphic_novel_title');

/* Document Setup */
$(document).ready(function() {
	
	$("#dsq-new-post h3").text("Share your thoughts");
	
	/* Drop Down Contact Form */
	$("#contactLink").click(function() {
		if ($(".contactFormContent").is(":hidden") && $(".categoryContent").is(":hidden")) {
			slideDownContact();
		} else if (!($(".categoryContent").is(":hidden"))) {
			$(".categoryContent").fadeOut(300);
			$(".contactFormContent").fadeIn(600);
		} else {
			slideUpContact();
		}
	});
	
	$("#categorylink").click(function() {
		if ($(".categoryContent").is(":hidden") && $(".contactFormContent").is(":hidden")) {
			slideDownCat();
		} else if (!($(".contactFormContent").is(":hidden"))) {
			$(".contactFormContent").fadeOut(300);
			$(".categoryContent").fadeIn(600);
		} else {
			slideUpCat();
		}
	});
	
	/* Back to Top */
	$(".bttlink").click(function() {
		$("body").scrollTo( {top:0 , left:0}, 1000, 'easeInOutCubic');
		return false;
	});
	
	/* FancyBox */
	$("a#gnwide").fancybox({
		'frameWidth': 1000,
		'frameHeight': 800,
		'imageScale': false,
		'centerOnScroll': false
	});
	
	$("#ajaxcontactform").submit(function() {
		var str = $(this).serialize();
		
		$.ajax({
			type: "POST",
			url: "http://www.escapeintolife.com/wp-content/themes/eil/mail.php",
			data: str,
			success: function(msg) {
				$("#note").ajaxComplete(function(event,request,settings) {
					if (msg =='Success') {
						result = '<p>Your message has been sent, thank you.<br /><a style="text-align: center" href="" id="reset">Reset Form</a></p>';
						$("#fields").hide();
					} else {
						result = msg;
					}
					
					$(this).html(result);
				});
			}
		});
		
		return false;
	});
	
	$("#ajaxnewsletterform").submit(function() {
		var str = $(this).serialize();
		
		$.ajax({
			type: "POST",
			url: "http://www.escapeintolife.com/wp-content/themes/eil/newsletter.php",
			data: str,
			success: function(msg) {
				$("#ajaxnewsletterform").ajaxComplete(function(event,request,settings) {
					if (msg =='Success') {
						result = '<p>Thank you. <a style="text-align: center" href="" id="reset">Reset Form</a></p>';
					} else {
						result = msg;
					}
					
					$(this).html(result);
				});
			}
		});
		
		return false;
	});	
	
	$("#reset").click(function() {
		$("#note").hide();
		$("#fields").show();
	});
	
	$("textarea").click(function() {
		$(this).select();
	});
});

function slideDownCat() {
	$("#copyright").fadeOut(100);
	$("#dropDownContainer").slideDown(600, 'easeInOutQuad', function() {
		$("#footer").css("height","430px");
	});
	$(".categoryContent").fadeIn(1000);
	$("body").scrollTo(".push", 300, 'easeInOutCubic');
}

function slideUpCat() {
	$(".categoryContent").fadeOut(300);
	$("#dropDownContainer").slideUp(400, function() {
		$("#footer").css("height","150px");
		$("#copyright").fadeIn(100);
		$("body").scrollTo(".push", 300, 'easeInOutCubic');
	});
}

function slideDownContact() {
	$("#copyright").fadeOut(100);
	$("#dropDownContainer").slideDown(600, 'easeInOutQuad', function() {
		$("#footer").css("height","430px");
	});
	$(".contactFormContent").fadeIn(1000);
	$("body").scrollTo(".push", 300, 'easeInOutCubic');
}

function slideUpContact() {
	$(".contactFormContent").fadeOut(300);
	$("#dropDownContainer").slideUp(400, function() {
		$("#footer").css("height","150px");
		$("#copyright").fadeIn(100);
		$("body").scrollTo(".push", 300, 'easeInOutCubic');
	});
}

/* Close Form Function */
function closeForm() {
	$("#messageSent").show("slow");
	setTimeout('$("#messageSent").hide(); $("#contactForm").slideUp("slow"); $("#footer").css("height","150px")', 2000);
}

/* Popup Function */
function popUp(url) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=150');");
}