var base = $('.tile').clone();
var selectedGames = new Array();
Array.prototype.remove = function() {
    var what, a = arguments, L = a.length, ax;
    while (L && this.length) {
        what = a[--L];
        while ((ax = this.indexOf(what)) !== -1) {
            this.splice(ax, 1);
        }
    }
    return this;
};
$(document).ready(function() {
    var options = {
        callback: function() {
            var searchString = $('#search').val();
            var api = '/api/games?name=' + searchString;
            if (searchString == "") {
                api = '/api/games?limit=42';
            }

            $.getJSON(api, Metro_Gallery.init).complete(function() {
                jQuery("time.timeago").timeago();
            });
        },
        wait: 500,
        highlight: false,
        captureLength: 2
    };

    $.getJSON('/api/games?limit=42&start=' + Math.floor(Math.random() * 1901), Metro_Gallery.init).complete(function() {
        $('#search').typeWatch(options);
    });
    //$(window).scroll(function () {
    //    var scrollPos;
    //    //Find the pageHeight and clientHeight(the no. of pixels to scroll to make the scrollbar reach max pos)
    //    var pageHeight = document.documentElement.scrollHeight;
    //    var clientHeight = document.documentElement.clientHeight;
    //    //Handle scroll position in case of IE differently
    //    scrollPos = window.pageYOffset;
    //    //Check if scroll bar position is just 50px above the max, if yes, initiate an update
    //    if(pageHeight - (scrollPos + clientHeight) < 50){
    //    //if ($(window).scrollTop() == $(document).height() - $(window).height()) {

    //        $.getJSON('/api/games?limit=48&start=' + Math.floor(Math.random() * 1901), function (data) {
    //            var games = Metro_Gallery.build(data);
    //            grid.append(games).masonry('appended', games, true);

    //        });
    //    }
    //});
});