atv.init.scroller = function(){
	if(atv.cufon){
		Cufon.replace('#highlight .tabs a,#highlight .panel a > .title,#highlight .panel a .show');
	}
	
	// Init UI
	if($("#highlight .scroller .panel.active ul").length > 1){
		$("#highlight .scroller > a").show();
	} else {
		$("#highlight .scroller > a").hide();
	}

	// Change on tab clicks
	$("#highlight .tabs .tab a").click(function(){
		var newTab = $(this);
		var oldTab = $("#highlight .tabs .tab.selected a");
		oldTab.parent().removeClass("selected");
		newTab.parent().addClass("selected");

		$("#highlight .scroller .panel.active").removeClass("active");
		$("#highlight .scroller .panel."+newTab.attr("href").substr(1)).addClass("active");

		if($("#highlight .scroller .panel.active ul").length > 1){
			$("#highlight .scroller > a").show();
		} else {
			$("#highlight .scroller > a").hide();
		}

		if(atv.cufon){
			Cufon.replace('#highlight .tabs a');
		}
		return false;
	});

	$("#highlight .scroller .panel").each(function(i){
		$(this).find("ul").each(function(n){
			$(this).attr("pos",n);
		});
	});

	$("#highlight .scroller a.next").click(function(){
		var from = $("#highlight .scroller .panel.active ul.active");
		var toIndex = 0;
		if(parseInt(from.attr("pos"),10)+1 < $("#highlight .scroller .panel.active ul").length){
			toIndex = parseInt(from.attr("pos"),10)+1;
		}
		var to = $("#highlight .scroller .panel.active ul:eq("+toIndex+")");

		to.css("left","100%").animate({left: "0%"}, 500, "linear", function(){
			$(this).addClass("active");
		});
		from.animate({left:"-100%"}, 500, "linear", function(){
			$(this).removeClass("active");
		});
		return false;
	});

	$("#highlight .scroller a.back").click(function(){
		var from = $("#highlight .scroller .panel.active ul.active");
		var toIndex = parseInt(from.attr("pos"),10)-1;
		if(toIndex == -1){
			toIndex = $("#highlight .scroller .panel.active ul").length-1;
		}
		var to = $("#highlight .scroller .panel.active ul:eq("+toIndex+")");

		to.css("left","-1000%").animate({left: "0%"}, 500, "linear", function(){
			$(this).addClass("active");
		});
		from.animate({left:"100%"}, 500, "linear", function(){
			$(this).removeClass("active");
		});
		return false;
	});

	// Mouseovers
	$("#highlight .scroller .panel ul li a").mouseover(function(){
		var popElm = $(this).find(".popup");
		var offset = $(this).offset();
		if(popElm.length > 0){
			$("#popup").html(popElm.clone()).show();
			if(atv.cufon){
				Cufon.replace('#popup .title');
			}
		}
	}).mousemove(function(e){
		var popup = $("#popup");
		var contentEdge = $("body").width() - (($("body").width()-$("#content").width())/2);
		if((e.pageX+popup.width()) > (contentEdge - 150)){
			popup.addClass("flip").css({'left':(e.pageX-266),'top':(e.pageY-(popup.height()+5))});
		} else {
			popup.removeClass("flip").css({'left':(e.pageX+20),'top':(e.pageY-(popup.height()+5))});
		}
	}).mouseout(function(){
		$("#popup").hide().empty();
	});
};
