$(function () {
	$(".email").each(function (){
		$(this).html($(this).html().replace(/ at /, "@").replace(/ dot /, "."));
		$(this).attr('href', "mailto:" + $(this).html());
	});
	
	if ($("#slider").length) {
		$("#slide-controls a").click(function () {
			clearInterval(gotoNextFrame);
			
			$(this).parent().siblings().removeClass("active");
			$(this).parent().addClass("active");
			
			$('#slider ul').animate({
				scrollLeft: $('#slider ul').width() * $(this).attr('href').substr(-1)
			});
			
			$($(this).attr('href')).siblings().removeClass("active");
			$($(this).attr('href')).addClass("active");
			
			return false;
		});
		
		gotoNextFrame = setInterval(nextFrame, 10000)
	}
	
	$(".delete-link").click(function () {
		if (!confirm("Are you sure you want to delete this affiliate? This cannot be undone.")) return false;
	});
});

nextFrame = function() {
	if ($("#slider ul .active").next().length) {
		target = $("#slider ul .active").next();
		targedNumber = target.attr('id').substr(-1);
	} else {
		target = $("#slide0").first();
		targedNumber = 0;
	}
	
	$("#slider ol li").removeClass("active");
	$("[href='#slide" + targedNumber + "']").parent().addClass("active");
	
	$('#slider ul').animate({
		scrollLeft: $('#slider ul').width() * targedNumber
	});
	
	target.siblings().removeClass("active");
	target.addClass("active");
}
