var rotationCounter = 0;
var rotationTimer;
var rotation_interval = 5000;
var dont_rotate = false;

function startRotation(clicked) {

    if ((!clicked) && dont_rotate) {
        rotationTimer = setTimeout ("startRotation(0)", rotation_interval);
	return;
    }

    $(".map .image img:eq(" + rotationCounter + ")").fadeOut();
    $("#research" + (rotationCounter + 1)).hide();

    if (clicked) {
        var clickedElement = $(".map .lights a").index($(clicked));
        rotationCounter = clickedElement;
    }
    else {
        rotationCounter = rotationCounter + 1;
        if (rotationCounter >= $(".map .image img").length)
            rotationCounter = 0;
    }

    if ($('#tooltip_inner').css("display") == 'block') {
        var msg = $("#sample_for_" + (rotationCounter + 1) + "_" + hover_state).html();
        $('#tooltip_inner').html(msg);
    }

    $(".map .lights a.selected").removeClass("selected");
 
    var active_image = $(".map .image img:eq(" + rotationCounter + ")");
    var width = active_image.attr("width");
    var height = active_image.attr("height");
    if ((width > 0) && (width < 601))
	active_image.css("margin-left", ((601 - width) / 2) + 'px');
    if ((height > 0) && (height < 375))
	active_image.css("margin-top", ((375 - height) / 2) + 'px');

    $(".map .image img:eq(" + rotationCounter + ")").fadeIn();
    $("#research" + (rotationCounter + 1)).show();

    $(".map .lights a:eq(" + rotationCounter + ")").addClass("selected");
    $(".map span.alt").html($(".map .image img:eq(" + rotationCounter + ")").attr("alt"));
	
    rotationTimer = setTimeout ("startRotation(0)", rotation_interval);
}
	
$(document).ready(function() {
	$(".fixcolumn").each(function()
	{
		$(this).find(".block-bar .post:first").height($(this).find("h2:first").height() + 7);
	});
	
	$(".map .image img:first").show();
	$(".map .lights a:first").addClass("selected");
	$(".map span.alt").html($(".map .image img:first").attr("alt"));
	
	$(".map .lights a").click(function()
	{
		clearTimeout(rotationTimer);
                startRotation(this);
		return false;
	});

	$(".map").mouseover(function() {
	   dont_rotate = true;
	});

	$(".map").mouseout(function() {
	   dont_rotate = false;
	});

        if ($(".map .image img").length > 1)
	   rotationTimer = setTimeout ("startRotation(0)", rotation_interval);
});

