var homeanimation = function () {


    var imgwidth;
    var imgheight;

    var interval = 300;
    var duration = 10000;


    this.construct = function () {
        imgwidth = $('.bganimationhome').width();
        imgheight = $('.bganimationhome').height();
        console.log(imgwidth);
        console.log(imgheight);
        //$('.bghome').css('height', imgheight);

    };

    this.start = function () {
        this.init();

        setInterval(this.animateElement, interval);
    };


    this.init = function() {
        for (i = 0; i < 15; i++) {
            var el = $('.animationelements img').eq(i);
            var rand = Math.random();
            $(el).css('top', (imgheight - (imgheight / 3)) * rand);
            $(el).css('left', (imgwidth - 40) * Math.random());
            $(el).addClass('active');

            $(el).animate({
                top: -100
            }, (duration * rand) + 1000, function () {
                $(this).removeClass('active');
            });
        }

    };
    /*
     * Private method
     * Can only be called inside class
     */
    this.animateElement = function () {

        var el = $('.animationelements img').not('.active').eq(0);
        $(el).css('top', imgheight - (imgheight / 3));
        $(el).css('left', (imgwidth - 40) * Math.random());
        $(el).addClass('active');

        $(el).animate({
            top: -100
        }, duration + (1000 * Math.random()), function () {
            $(this).removeClass('active');
        })

    };


    /*
     * Pass options when class instantiated
     */
    this.construct();

};
