TDefault = {};

TDefault.OnInit = function() {
	SyntaxHighlighter.all();

	$("[rel=Navigation]").bind("mouseover", function() {
		var NumChildren = $(".Tutorials").children().length;

		if(NumChildren > 5) {
			if($(this).attr("id") == "Tutorials") {
				$(".Tutorials").fadeIn("fast");
			}else{
				$(".Tutorials").fadeOut("fast");
			}
		}
	});

	$(window).bind("mousemove", function(e) {
		var MaxY = 44 + $(".Tutorials").height() + 80;

		if(e.pageY > MaxY) {
			$(".Tutorials").fadeOut("fast");
		}
	});

	$(".CommentReplyButton").bind("click", function() {
		var CommentID = $(this).attr("rel");

		$("[id^=CommentReply\_]").slideUp("normal");
		$("#CommentReply_" + CommentID).slideDown("normal", function() {
			$(this).focus();
		});
	});

	$(".LeaveCommentSubmit").bind("click", function() {
		TDefault.SubmitComment($(this));
	});

	$(".LeaveCommentHide").bind("click", function() {
		$(this).parent().slideUp("normal");
	});

	$("#EmailListName").bind("keydown", function(e) {
		if(e.keyCode == 13) TDefault.EmailSignUp();
	});

	$("#EmailListEmail").bind("keydown", function(e) {
		if(e.keyCode == 13) TDefault.EmailSignUp();
	});
}

TDefault.SubmitComment = function($Obj) {
	var WebsitesID	= $("#WebsitesID").val();
	var PostsID		= $("#PostsID").val();

	var Name		= $Obj.parent().find("[name=Name]").val();
	var Email		= $Obj.parent().find("[name=Email]").val();
	var Website		= $Obj.parent().find("[name=Website]").val();

	var ParentID	= $Obj.parent().find("[name=ParentID]").val(); 
	var Content		= $Obj.parent().find("textarea").val();

	if(Name == "") {
		alert("Please enter your Name");
		$Obj.parent().find("[name=Name]").focus();
		return;
	}

	if(Email == "") {
		alert("Please enter your Email Address");
		$Obj.parent().find("[name=Email]").focus();
		return;
	}

	if(Content == "") {
		alert("Please enter your Comment");
		$Obj.parent().find("textarea").focus();
		return;
	}

	var Parms = {
		"WebsitesID": WebsitesID,
		"PostsID"	: PostsID,
		"ParentID"	: ParentID,
		"Name"		: Name,
		"Email"		: Email,
		"Website"	: Website,
		"Content"	: Content
	};

	CAJAX.Add("Default", "Template", "Comment", Parms, function(Code, Content) {
		if(Code > 0) {
			window.location.href = CURL.FormatURL("", {}, true, true) + "#Comment_" + Code;
			window.location.reload(true);
		}else{
			alert(Content);
		}
	});
}

TDefault.EmailSignUp = function() {
	var WebsitesID	= $("#WebsitesID").val();

	var Name		= $("#EmailListName").val();
	var Email		= $("#EmailListEmail").val();

	if(Name == "") {
		alert("Please enter your Name");
		$("#EmailListName").focus();
		return;
	}

	if(Email == "") {
		alert("Please enter your Email Address");
		$("#EmailListEmail").focus();
		return;
	}

	var Parms = {
		"WebsitesID": $("#EmailListWebsitesID").val(),
		"Name"		: Name,
		"Email"		: Email
	};

	CAJAX.Add("Default", "Template", "EmailList", Parms, function(Code, Content) {
		if(Code > 0) {
			$(".FooterContentSocialEmailText").slideUp("fast", function() {
				$(this).html("<br/>Thank You for signing up!<br/><br/>");
				$(this).slideDown("fast");
			});
		}else{
			alert(Content);
		}
	});
}

$(TDefault.OnInit);

