// Cufon replacements
Cufon.replace("nav#menu a", {hover: true});
Cufon.replace("h1, h2, h3, h4, h5, h6");
Cufon.replace("#newsSlider .itemDescriptionTitle, #newsSlider .itemDate, #newsSlider .itemTitle", {hover: true});
Cufon.replace(".twitter .follow", {hover: true});
Cufon.replace("div.block.volgendeWedstrijd .footer, div.block.volgendeWedstrijd .club, div.block.volgendeWedstrijd .matchDate");

Shadowbox.init();


// News Slider
$(function() {
	$("#newsSlider .itemTitle").bind("mouseover", function() { 
		toggleSlide($(this));
	});
});

function doSlider() {
		$next = $("#newsSlider .selected").next();
		if ($next.length <= 0) {
			$next = $("#newsSlider .item:first");
		}
		toggleSlide($next.find(".itemTitle"));
		sliderTimeout = window.setTimeout(doSlider, 5000);
}

function toggleSlide(e) {
	if ($(e).parent().hasClass("selected")) {
	} else {
		$("#newsSlider .selected").removeClass("selected");
		$(e).parent().addClass("selected");
		Cufon.replace("#newsSlider .itemTitle");
	}

	window.clearTimeout(sliderTimeout);

}

var sliderTimeout = window.setTimeout(doSlider, 5000);


// Twitter slider 
$(function() {
	$(".twitter .tweet:first").addClass("top");
});

function scrollTweet() {
	$content = $(".twitter .content");
	$tweets = $(".twitter .tweets");
	$next = $(".twitter .top").next();
	if ($next.length <= 0) {
		$next = $(".twitter .tweet:first");
	}
	$content.scrollTo($next, 500);
	$(".twitter .top").removeClass("top");
	$next.addClass("top");
	var twitterTimeout = window.setTimeout(scrollTweet, 5000);
}

var twitterTimeout = window.setTimeout(scrollTweet, 5000);

// Equal heights for program and results
$(function() {

	$("div.blockRow").each(function() {
		var maxHeight = 0;
		$(this).find("div.block").each(function() {
			if ($(this).height() > maxHeight)
				maxHeight = $(this).height();
		});
		$(this).find("div.block:not(.banner):not(.volgendeWedstrijd, .twitter)").css({"min-height": maxHeight});
	});

});


// Clickable title
$(function() {
	$("div.block .title .readMore a").each(function() {
		var link = $(this).attr("href");
		$(this).closest("div.title").click(function() {
			document.location = link;
		}).css({"cursor": "pointer"});
	});
});

// Replace email addresses
$(function() {
	$("a.email").each(function() {
		$(this).attr("href", $(this).attr("href").replace("-at-", "@")).text($(this).text().replace("-at-", "@"));
	});
});


// Dynamically load Picasa-albums
$(function() {
	$(".picasa").each(function() {
		$(this).addClass("loading").load("/picasa.php?album=" + $(this).attr("data-id"), function() {
			$(this).removeClass("loading").find("div.thumbnail:nth-child(3n)").css({"margin-right": 0});
			Shadowbox.setup("div.picasa a", {
				gallery:		"Fotoalbum",
				autoplayMovies:	true
			});
		});
	});
});
