/*jslint indent:4 */
/*global $, document, console, alert, log, user_avatar_filename, record_event, window, jQuery, SHOW */

var SC = SC || {};

SC.autoload = (function ($) {

    var my, $load_more, reachedBottomTrigger, autoload_autoclick;

    my = {};


    reachedBottomTrigger = function () {
        if (typeof window.SHOW === 'undefined' || window.SHOW !== 'recent') {
            $load_more = $('#load_more_questions_all');
        } else {
            $load_more = $('#load_more_questions_recent');
        }

        var attr = $load_more.attr('disabled');

        if ((typeof attr === 'undefined' || attr === false)) {
            $load_more.click();
        }

    };

    autoload_autoclick = function () {

//        if (($(window).scrollTop() + $(window).height()) >= 85 / 100 * $(document).height()) {

        if (Math.abs($(window).scrollTop() + $(window).height() - $(document).height()) < 300) {
            // TODO: Instead of percentage, kick in within 100-200 pixels from the bottom
            SC.autoload.reachedBottomTrigger();
        }


        if ($(window).scrollTop() > 300) {
            $('.fixedtotop').addClass('fixmebottom').removeClass('fixmetop');
        } else {
            $('.fixedtotop').addClass('fixmetop').removeClass('fixmebottom');
        }


    };

    my.reachedBottomTrigger = reachedBottomTrigger;
    my.autoload_autoclick = autoload_autoclick;


    return my;

}(jQuery));



