﻿var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var future_headline = 0;

$(document).ready(function() {
    headline_count = $("div.headline").size();
    if (headline_count == 1) {
        $("div.headline:eq(" + current_headline + ")").css('top', '15px');

        headline_interval = setInterval(no_headline_rotate, 0);

        $('#scrollup').hover(function() {
            clearInterval(headline_interval);
        }, function() {
            headline_interval = setInterval(no_headline_rotate, 0);

        });
    }

    else {
        $("div.headline:eq(" + current_headline + ")").css('top', '5px');
        $("div.headline:eq(" + (current_headline + 1) + ")").css('top', '185px');

        if (headline_count > 2) {
            headline_interval = setInterval(headline_rotate, 6000);
        }
        $('#scrollup').hover(function() {
            clearInterval(headline_interval);
        }, function() {
            headline_interval = setInterval(headline_rotate, 6000);
            //headline_rotate();
        });
    }
});


function headline_rotate() {
    current_headline = (old_headline + 1) % headline_count;
    future_headline = (current_headline + 1) % headline_count;

    $("div.headline:eq(" + old_headline + ")")
    .animate({ top: -185 }, 1800, function() {
        $(this).css('top', '400px');
    });
    $("div.headline:eq(" + current_headline + ")")
    .animate({ top: 5 }, 2500);

    $("div.headline:eq(" + future_headline + ")")
    .animate({ top: 185 }, 3000);


    old_headline = current_headline;

}
function no_headline_rotate() {

}
