// Execute when DOM is ready
$(document).ready(function () {
	// Article carousel - automatic rotation
	$("div.article-carousel").each(function () {
		this.timer = setInterval(function () {
			var list = $("div.article-carousel li");
			list.each(function (i) {
				if ($(this).attr('class').indexOf('active') >= 0) {
					next = list.get(i == list.length - 1 ? 0 : i + 1);
					$(this).removeClass("active");
					$($(this).find("a").get(0).hash).removeClass("active").show().fadeOut(1000);
					$(next).addClass("active");
					$($(next).find("a").get(0).hash).addClass("active").hide().fadeIn(1000);
					return false;
				}
			});
		}, 10000);
	});

	// Article carousel - manual rotation
	$("div.article-carousel li a").click(function () {
		clearTimeout(this.parentNode.parentNode.parentNode.timer);
                if ($(this.parentNode).attr('class').indexOf('active') < 0) {
			$("div.article-carousel li.active").removeClass("active");
			$(this.parentNode).addClass("active");
			$("div.article-carousel div.article.active").removeClass("active").show().fadeOut(500);
			$(this.hash).addClass("active").hide().fadeIn(500);
		}
		return false;
	});

	// Moo
	$("#form-search-head input.text").each(function () {
		if (this.value == "") {
			this.value = this.title;
		}
		$(this).focus(function () {
			if (this.value == this.title) {
				this.value = "";
			}
		});
		$(this).blur(function () {
			if (this.value == "") {
				this.value = this.title;
			}
		});
	});
});
