var quote_data = {"quotes": [
        {"author": "Evan Wallace - Brown University", "quote": '"I always find Upload Robots to be surprisingly fast. I just love its simplicity"' },
        {"author": "Tony Christopher - Stanford University", "quote": '"UploadRobots is simply the best file uploading service I have ever used.  Plus, it\'s free"' },
        {"author": "Graham Merfield - VP, Rhodia INC", "quote": '"Upload Robots is valuable as a business resource, it\'s perfect for sharing documents."' },
        {"author": "Stephen Fry - Actor & Comedian", "quote": '"Bloody Impressed. Clean UI and so quick."' },
	{"author": "Co-Founder of Smoking Apples", "quote": '"I commend them on their beautiful design. The home page is simple, everything is nicely laid out."' },
	{"author": "Robert Hillger - Senior Advisor EPA", "quote": '"Upload Robots is so simple to use, it feels wonderful when you use something that just works."' }
    ]
};

$(document).ready(function() {
	quoteVar=eval(quote_data);
	quoteCounter=-1;
	$("#login, #login_btn").click(function() {
		$("#l_holder").animate({ top:"-8px" }, 1100);
	});	
	$("#l_close").click(function() { $("#l_holder").animate({ top:"-70px" }, 1100); });
	$("#l_go").click(function() { login(); });
	$("#l_user").keypress(function (e) { if (e.which==13) { login(); }}).click(function() {
		if ($(this).val()=="Username") {
			$(this).val("");
		}
	});
	$("#l_pass").keypress(function (e) { if (e.which==13) { login(); }}).click(function() {
		if ($(this).val()=="password") { $(this).val(""); }
	});
	setInterval(function() {
		$(".q").fadeOut("slow",function() {
			if (++quoteCounter>quoteVar.quotes.length-1) {
				quoteCounter=0;
			}
			$(".author").text(quoteVar.quotes[quoteCounter].author);
			$(".q").text(quoteVar.quotes[quoteCounter].quote);
			$(this).fadeIn("slow");
		});
	}, 4500);
});

function login() {
	$.get("ajax.php",{action: "login", user:$("#l_user").val(),pass:SHA1(SHA1($("#l_pass").val()))}, function(r) {
		r=eval("(" + r + ")");
		if (r['error']==0) {
			createCookie("username", $("#l_user").val(),30);
			createCookie("password", SHA1(SHA1($("#l_pass").val())), 30);
			window.location="/files";
		} else {
			$("#l_holder").animate({backgroundPosition:"(-1px -7px)"}, 200, function() { $("#l_error").text(r['message']).fadeIn(); });
			setTimeout(function() { $("#l_error").fadeOut(); setTimeout(function() { $("#l_holder").animate({backgroundPosition:"(-1px -25px)"}, 200) }, 500); }, 2500);
		}
	});
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
