﻿var monthEventsSliderHeight = 0;
var monthEventsSlider = null;

var actualEventsSliderHeight = 0;
var actualEventsSlider = null;

var newsTickerHeight = 0;
var newsTicker = null;
var newsTickerTimer = null;

var initMonthEventsSlider = function() {

    monthEventsSliderHeight = $(".eventBox.month").length * 72;
    monthEventsSlider = $("#month-events-slider");
    monthEventsSlider.css("height", monthEventsSliderHeight + "px");
}

var monthEventsUp = function() {

    if (monthEventsSlider == null)
        return false;

    $("#month-events-down").unbind("click", monthEventsUp);

    var top = parseInt(/[0-9\-]+/.exec(monthEventsSlider.css("top")));
    var step = monthEventsSliderHeight + top == 144 ? 0 : 72;

    monthEventsSlider.animate({ top: top - step }, function() {
        $("#month-events-down").bind("click", monthEventsUp);
    });

}

var monthEventsDown = function() {

    if (monthEventsSlider == null)
        return false;

    $("#month-events-up").unbind("click", monthEventsDown);

    var top = parseInt(/[0-9\-]+/.exec(monthEventsSlider.css("top")));
    var step = top == 0 ? 0 : 72;

    monthEventsSlider.animate({ top: top + step }, function() {
        $("#month-events-up").bind("click", monthEventsDown);
    });

}

var initActualEventsSlider = function() {

    actualEventsSliderHeight = Math.ceil($(".eventBox.actual").length / 2) * 72;
    actualEventsSlider = $("#actual-events-slider");
    actualEventsSlider.css("height", actualEventsSliderHeight + "px");    
}

var actualEventsUp = function() {

    if (actualEventsSlider == null)
        return false;

    $("#actual-events-down").unbind("click", actualEventsUp);

    var top = parseInt(/[0-9\-]+/.exec(actualEventsSlider.css("top")));
    var step = actualEventsSliderHeight + top == 144 ? 0 : 72;

    actualEventsSlider.animate({ top: top - step }, function() {
        $("#actual-events-down").bind("click", actualEventsUp);
    });

}

var actualEventsDown = function() {

    if (actualEventsSlider == null)
        return false;

    $("#actual-events-up").unbind("click", actualEventsDown);

    var top = parseInt(/[0-9\-]+/.exec(actualEventsSlider.css("top")));
    var step = top == 0 ? 0 : 72;

    actualEventsSlider.animate({ top: top + step }, function() {
        $("#actual-events-up").bind("click", actualEventsDown);
    });

}

var newsTickerUp = function() {

    if (newsTicker == null)
        return false;

    clearInterval(newsTickerTimer);

    $("#news-ticker-up").unbind("click", newsTickerUp);

    var top = parseInt(/[0-9\-]+/.exec(newsTicker.css("top")));
    var step = newsTickerHeight + top == 40 ? 0 : 40;

    newsTicker.animate({ top: top - step }, function() {
        $("#news-ticker-up").bind("click", newsTickerUp);
        newsTickerTimer = setInterval(newsTickerUp, 4000);
    });

}

var newsTickerDown = function() {

    if (newsTicker == null)
        return false;

    clearInterval(newsTickerTimer);

    $("#news-ticker-down").unbind("click", newsTickerDown);

    var top = parseInt(/[0-9\-]+/.exec(newsTicker.css("top")));
    var step = top == 0 ? 0 : 40;

    newsTicker.animate({ top: top + step }, function() {
        $("#news-ticker-down").bind("click", newsTickerDown);
        newsTickerTimer = setInterval(newsTickerUp, 4000);
    });

}

var initNewsTicker = function() {

    newsTickerHeight = $("#newsTicker li").length * 40;
    newsTicker = $("#newsTicker");
    newsTicker.css("height", monthEventsSliderHeight + "px");
}

$().ready(function() {

    initMonthEventsSlider();
    $("#month-events-up").bind("click", monthEventsDown);
    $("#month-events-down").bind("click", monthEventsUp);

    initActualEventsSlider();
    $("#actual-events-up").bind("click", actualEventsDown);
    $("#actual-events-down").bind("click", actualEventsUp);

    initNewsTicker();
    $("#news-ticker-down").bind("click", newsTickerDown);
    $("#news-ticker-up").bind("click", newsTickerUp);
    newsTickerTimer = setInterval(newsTickerUp, 4000);
       

});
