﻿var i = 0;
var h = 0;
var divs = 0;
var delay = 1500;
var animation = 750;

$(document).ready(function()
{
    var quote = $("div.quotes").size();
    if (quote > 0)
    {
        delay = 4500;
        animation = 1000;
    }

    setTimeout("StartScrolling()", delay);
});

function StartScrolling()
{
    divs = $("#scroll > div").size();
    i = i + 1;
    if (i < (divs - 1))
    {
        h = $("#scroll div:nth-child(" + i + ")").height() + 10;
        $("#scroll div:nth-child(" + i + ")").animate({marginTop: -h}, animation);
        setTimeout("ScrollUp()", delay);
    }
}

function ScrollUp()
{
    if (i < (divs - 1))
    {
        i = i + 1;
        if (i < 1) { i = 1; }
        h = $("#scroll div:nth-child(" + i + ")").height() + 10;
        $("#scroll div:nth-child(" + i + ")").animate({ marginTop: -h }, animation);
        setTimeout("ScrollUp()", delay);
    }
    else
    {
        ScrollDown();
    }
}

function ScrollDown()
{
    if (i > 0)
    {
        $("#scroll div:nth-child(" + i + ")").animate({ marginTop: 0 }, 200);
        i = i - 1;
        setTimeout("ScrollDown()", 250);
    }
    else
    {
        ScrollUp();
    }
}

