").attr("class", "info");
e.append(h);
c.append(l).append(m);
g.append(c).append(e).append(p);
g.click(function () {
$(this).children(".info").slideToggle("fast")
});
c = String(this.alarm_time).replace(/GMT.*$/, "");
e = String(this.parsed.created_at).replace(/GMT.*$/, "");
g.children(".info").append(j("Alarm: ", c));
g.children(".info").append(j("Created: ", e));
g.children(".info").append(j("Type: ", this.parsed.type == "every" ? "Recurring" : "One-time"));
g.data("timer", this);
this.tick = function () {
if (i.time_left() <= 0) {
$("audio")[0].play();
if (i.every) {
var a = f();
i.alarm_time = f(a.getTime() + i.every);
i.beeped = false;
n()
} else i.remove()
} else l.text(i.display())
};
$("#y").append(g)
}
function o(a, b, d) {
this.rx = a;
this.mapper = b;
this.callback = d
}
function s(h) {
function j(a, b, d, c) {
return a * 24 * 60 * 60 * 1E3 + b * 60 * 60 * 1E3 + d * 60 * 1E3 + (c ? c : 0) * 1E3
}
function g(d, c) {
var e = [];
$.each(d, function (a, b) {
e.push(c(b))
});
return e
}
function i(b) {
return g(b, function (a) {
a = Number(a);
return isNaN(a) ? 0 : a
})
}
var l = new o(/(\d\d?):([0-5][0-9])(?::([0-5][0-9]))? *([Aa][mM]|[pP][mM])?/, function (d) {
return g(d, function (a) {
var b = Number(a);
return isNaN(b) ? a : b
})
}, function (a, b, d, c) {
if (c && (a === 0 || a > 12) || !c && a > 23) return null;
if (c) switch (c.toUpperCase()) {
case "AM":
a = a === 12 ? 0 : a;
break;
case "PM":
a = (a + 12) % 24;
break
}
c = f();
var e = new Date(c.getFullYear(), c.getMonth(), c.getDate());
a = f(e.getTime() + j(0, a, b, d));
if (a <= c) a = f(a.getTime() + 864E5);
return new k(a, h)
}),
m = /^(?:(\d+) *d(?:ays|ay)?)? *(?:(\d+) *h(?:ours|our|r)?)? *(?:(\d+) *m(?:inutes|in|ins)?)? *(?:(\d+) *s(?:econds|ec|ecs)?)?$/,
p = new o(m, i, function (a, b, d, c) {
if (a === 0 && b === 0 && d === 0 && c === 0) return null;
var e = f();
a = f(e.getTime() + j(a, b, d, c));
return new k(a, h)
});
m = new o(m, i, function (a, b, d, c) {
if (a === 0 && b === 0 && d === 0 && c === 0) return null;
var e = f();
e = f(e.getTime() + j(a, b, d, c));
return new k(e, h, j(a, b, d, c))
});
l = {
at: l,
"in": p,
every: m
};
return l[h.z] ? l[h.z].run(h.t) : null
}
function t(a) {
var b = $("#e");
a = $("
").attr("class", "fail").hide().text(a);
b.html(a);
a.fadeIn("slow")
}
k.prototype.time_left = function () {
return this.alarm_time - f()
};
k.prototype.display = function () {
var a = this.time_left(),
b, d, c;
b = Math.floor(a / 864E5);
a %= 864E5;
d = Math.floor(a / 36E5);
a %= 36E5;
c = Math.floor(a / 6E4);
a %= 6E4;
a = Math.floor(a / 1E3);
d = (d < 10 ? "0" + d : "" + d) + ":" + (c < 10 ? "0" + c : "" + c) + ":" + (a < 10 ? "0" + a : "" + a);
return (b = (b === 0 ? "" : "" + b) + " " + (b === 0 ? "" : b === 1 ? "day" : "days")) ? b + " " + d : d
};
o.prototype.run = function (a) {
if (a = a.match(this.rx)) {
a = a.slice(1);
a = this.mapper(a);
return this.callback.apply(null, a)
} else return null
};
var q = false;
$(function () {
$("form").submit(function () {
var a = {};
$(this).find("#z,#t,#a").each(function () {
a[this.id] = $.trim($(this).val());
this.value = ""
});
a.created_at = f().toString();
if (s(a)) {
if (q) {
$("#e").children().fadeOut("slow", function () {
$(this).remove()
});
q = false
}
n()
} else {
t("Unusual time format. Try again!");
q = true
}
$("#type").focus();
return false
});
setInterval(function () {
$("#y li").each(function (a, b) {
$(b).data("timer").tick()
})
}, 500);
r()
})
})(window);