var mainFlowerTimer = function()
{
    this.active_flower_number = 1;

    this.timeout = null;

    this.interval = null;


    this.getNextFlowerNumber = function()
    {
        if (this.active_flower_number == 5)
        {
            return 1;
        }
        else
        {
            return ++this.active_flower_number;
        }
    }
    

    this.setNextFlower = function()
    {
        $('#flower_link_' + this.active_flower_number).removeClass('active');

        this.active_flower_number = this.getNextFlowerNumber();

        this.changeFlower(this.active_flower_number);
    }


    this.changeFlower = function(flower_number)
    {
        $('#flower_link_' + flower_number).addClass('active');

        $('#header1').css('background-image', 'url(/img/site/flowers/header' + flower_number + '.png)');

        var flower_label = $('#banner_label_' + flower_number).html();

        $('#banner_label').html(flower_label);
    }


    this.setActiveFlower = function(flower_number)
    {
        $('#flower_link_' + this.active_flower_number).removeClass('active');

        this.active_flower_number = flower_number;

        this.changeFlower(flower_number);
    }


    this.start = function()
    {
        var this_obj = this;

        var next_f = function()
        {
            this_obj.setNextFlower();
        }

        this.interval = setInterval(next_f, 5000);
    }


    this.stop = function(millisec)
    {
        clearInterval(this.interval);

        clearTimeout(this.timeout);

        var this_obj = this;

        var start = function start()
        {
            this_obj.start();
        }

        this.timeout = setTimeout(start, millisec);
    }
    
}


$(function()
{
    var timer = new mainFlowerTimer();

    timer.start();

    $('.flower_link').click(function()
    {
        var flower_number = $(this).attr('id').replace('flower_link_', '');

        timer.setActiveFlower(flower_number);

        timer.stop(10000);
    });
});



