$(function() {
	$.getJSON("ajax/posts", function(j) {
		$("#load").remove();
		$.each(j,function(i,p) {
			$("<div />").addClass("post").addClass(p.z).html('<div class="title">'+p.title+'</div>'+p.entry+'<div class="stamp">'+p.stamp+'</div>').appendTo("#col"+(Math.ceil((i+1)/(j.length/4)))).animate({ opacity: 1 },(i*1000)/j.length);
		});
		$(".post").hover(function() {
			$(this).stop().css({ "padding":"5px","opacity":"1" }).animate({
				"font-size":"200%",
				"padding":"10px"
			},200);
			$(".column").stop().animate({
				"width":"20%"
			},200);
			$(this).parent().stop().animate({
				"width":"40%"
			},200);
		},function() {
			$(this).stop().animate({
				"font-size":"100%",
				"padding":"5px"
			},200);
		});
	});
	$("#btnLogin").click(function() {
		$("#login").slideToggle();
	});
	$("#formLogin").submit(function(e) {
		e.preventDefault();
		//$("#formLoginSubmit").attr("disabled","");
		dat = new Object();
		$.each($(this).find("input"),function(i,e) {
			dat[$(e).attr("name")] = $(e).val();
		});
		$.post("ajax/auth",dat,function(json) {
			if (json.accept == true) {
				$("#formLoginMessage").slideUp(function() {
					$(this).html("Login successful, welcome back ").append(json.name).append(".<br />Making everything awesome...").slideDown(function() {
						setTimeout(function() {
							$("<script />").attr({ "type":"text/javascript","src":_rDir+"theme/adminjs" }).appendTo("body");
						},1000);
					});
				});
			} else {
				$("#formLoginMessage").html("Incorrect Username/Password").slideDown();
				$("#formLoginSubmit").removeAttr("disabled");
			}
		},"json");
	});
});