$(document).ready(function() {

	$("#news-homepage a.more").click(function() {
		$("#news-homepage-content").css("height", "auto");
		$(this).animate({"opacity": 0});
		return false;
	});
	
	$("#topsearch input.text").focus(function() {
		if ($(this).val() == $(this).attr("rel")) {
			$(this).val("");
		};
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val($(this).attr("rel"));
		};
	});
	
	if ($("#ticker")) {
		newsTicker();
		$("#ticker li a").mouseenter(function() {
			clearTimeout(newsTickerTimeout);
			newsTickerTimeout = 0;
		}).mouseleave(function() {
			newsTickerTimeout = setTimeout("newsTicker()", 1000);
		});
	};
	
	$("#topsearch .text").attr("rel", $("#topsearch .text").val());

});

$(window).ready(function() {
	var pageHeight = $(window).height();
	var bodyHeight = $("body").height();
	
	
	if (bodyHeight < pageHeight) {
		//increase content area
		var newIncrease = pageHeight-bodyHeight;
		if ($("#side").height() > $("#content").height()) {
			$("#side").css("paddingBottom", newIncrease+"px");
		} else {
			$("#content").css("paddingBottom", newIncrease+"px");
		};
	};
});

function getCalendar(month, year) {

	$.get("/inc/calendar.php?month="+month+"&year="+year, function(data) {
		$("#calendar").html(data);
	});
	
	return false;
};

var newsTickerCurrent = 0;
var newsTickerTimeout;
function newsTicker() {	

	if (newsTickerCurrent == 0) {
		var newsTickerPrev = $("#ticker li").size()-1;
	} else {
		var newsTickerPrev = newsTickerCurrent-1;
	};
	$("#ticker li:eq("+newsTickerPrev+")").fadeOut(500, function() {
		//alert(newsTickerCurrent);
		$("#ticker li:eq("+newsTickerCurrent+")").fadeIn(500);
		newsTickerCurrent++;
		if (newsTickerCurrent == $("#ticker li").size()) {
			newsTickerCurrent = 0;
		};
		newsTickerTimeout = setTimeout("newsTicker()", 3000);
	});
	
};
