﻿var quotesRotatorIntervalID;

$(function() {
StartRotation();
    $("#quotesContainer").hover(StopRotation, ResumeRotation);
});

function StartRotation() {
    StopRotation();
    $("#quotesContainer").css("top", "0px");
    quotesRotatorIntervalID = window.setInterval(SwitchQuote, 10000);
}

function StopRotation() {
    window.clearInterval(quotesRotatorIntervalID);
}

function ResumeRotation() {
    StopRotation();
    SwitchQuote();
    quotesRotatorIntervalID = window.setInterval(SwitchQuote, 10000);
}

function SwitchQuote() {
    var quotesFadingSpeed = 2000;
    var quoteHeight = 170;

    var container = $("#quotesContainer")[0];
    var containerTop = parseInt(container.style.top);
    var containerHeight = container.clientHeight;
    var newTop = ((quoteHeight - containerTop) < containerHeight) ? containerTop - quoteHeight : 0;

    $("#quotesContainer").fadeOut(quotesFadingSpeed, function() {
        $("#quotesContainer").css("top", newTop);
        $("#quotesContainer").fadeIn(quotesFadingSpeed);
    });
}

