var autoPanelTimeout = -1;

$(function() {
	
	$("a.download").click(function(evt) { pageTracker._trackPageview($(this).attr("href")); });
	
	$("a.new-window").click(function(evt) { window.open($(this).attr("href")); return false; });
	
	$("a.animation").click(function(evt) {
		
		$("#content").prepend("<div id='animation-holder'></div>");
		$("#animation-holder").load($(this).attr("href"));
		
		return false;
		
	});
	
	$("a#close-animation").live("click", function(evt) {
		
		$("#animation-holder").remove();
		
		return false;
		
	});
	
	$(".panels .panel:not(:first)").hide();
	$(".panels .panel:first").addClass("active");
	
	$(".next-panel").click(function(evt) {
		
		clearTimeout(autoPanelTimeout);
		
		var a				= $(this);
		//var panels			= $(a.attr("href"));
		var panels			= a.parent(".panel").parent(".panels");
		
		showNextPanel(panels);
		
		return false;
		
	});
	
	autoPanelTimeout = setTimeout('moveAutoPanels()', 3500);
	
});

function showNextPanel(panels) {
	
	var currentPanel	= panels.children(".panel.active");

	var nextPanel		= currentPanel.next(".panel").size() == 1 ? currentPanel.next(".panel") : currentPanel.siblings(".panel:first");
	
	currentPanel.removeClass("active").fadeOut("fast");
	nextPanel.addClass("active").fadeIn("fast", function(evt) {
		
		autoPanelTimeout = setTimeout('moveAutoPanels()', 3500);
		
	});
	
}

function moveAutoPanels() {
	
	clearTimeout(autoPanelTimeout);
	
	//$(".auto-panels .active a.next-panel").click();
	showNextPanel($(".auto-panels"));
	
	autoPanelTimeout = setTimeout('moveAutoPanels()', 3500);
	
}