$(document).ready(function() {
	var slideheight = $("ul.slideshow li").height();
	
	$('ul.slideshow').innerfade({
		animationtype: 'fade',
		speed: 750,
		timeout: 5000,
		type: 'sequence',
		containerheight: slideheight + 'px'
	});
	
	$("#commentCancel").hide();
	$("#commentSubmit").hide();
	
	$("#commentPreview").click(function(){
		var commentName = $("input#commentName").val();
		var commentEmail = $("input#commentEmail").val();
		var commentWebsite = $("input#commentWebsite").val();
		var editorText = FCKeditorAPI.GetInstance("FCKeditor01");
		var commentBody = editorText.GetXHTML(true);
		var now = new Date();
		now.toGMTString();
		var commentPreview = '<li class="newcommentLast">'+commentBody+'<p>&#8211; <a href="mailto:'+commentEmail+'">'+commentName+'</a> &middot; '+now+'</p>';

		$("#commentCancel").fadeIn("normal");
		$("#commentSubmit").fadeIn("normal");
		$("li.newcommentLast").remove();
		$(".commentLast").after(commentPreview);
		$("li.newcommentLast").hide();
		$("li.newcommentLast").fadeIn("normal");
		$("li.newcommentLast").css({'background-color' : '#efefef'});
	});
	$("#commentSubmit").click(function(){
		var commentId = $("input#commentId").val();
		var commentName = $("input#commentName").val();
		var commentEmail = $("input#commentEmail").val();
		var editorText = FCKeditorAPI.GetInstance("FCKeditor01");
		var commentBody = editorText.GetXHTML(true);
		var now = new Date();
		now.toGMTString();
		var commentPreview = '<li class="newcommentLast">'+commentBody+'<p>&#8211; <a href="mailto:'+commentEmail+'">'+commentName+'</a> &middot; '+now+'</p>';

		var dataString = 'id='+commentId+'&name='+escape(commentName)+'&email='+escape(commentEmail)+'&body='+escape(commentBody);

		$.ajax({
			type: 'post',
			url: '/includes/php/comment-save.php',
			data: dataString,
		
			success: function(){
				$("#commentLeave").slideUp("normal");
				$("li.newcommentLast").remove();
				$(".commentLast").after("<li class='newcommentLast'>Awaiting comment approval.</li>");
				$("li.newcommentLast").hide();
				$("li.newcommentLast").fadeIn("normal");
				$("p.commentLast").remove();
			}
		});
	});
	$("#commentCancel").click(function(){
		$("li.newcommentLast").fadeOut("normal");
	});
	
	$("#feature").prepend('<ul class="slideshow">' + $("body#home ul.slideshow").html() + '</ul>');
	$("body#home #content ul.slideshow").remove();
});