(function() {
    window.elementLottery = window.elementLottery || {};

    var elementIDs;
    var $lottery;
    var ticketCount = 30;

    elementLottery.init = function() {
        elementIDs = [];
        $lottery = $('#lottery').empty();
        elementLottery.add(ticketCount);
        $('#lotteryTicketButton').on('click', elementLottery.pick);
    };

    elementLottery.add = function(n) {
        for (var i = 0; i < n; i++) {
            var id = this.uidProvider.get();
            elementIDs.push(id);
            $lottery.append(this.ticket.createHtml(id));
        }
    };

    elementLottery.pick = function() {
        var index = Math.floor(Math.random() * elementIDs.length);
        var result = $lottery.find('#' + elementIDs[index]).text();
        alert(result);
        return result;
    };

    $(document).ready(elementLottery.init);
})();
