var timer = null;
var done = true;

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function iteration(ep)
{
	 $('ajax-loader').style.display = '';
	 $(ep.morebutton).hide();
   new Ajax.Request(ep.url, {onComplete: function(){done = true}, onCreate: function(){done = false}, 
	             parameters: {asynchronous: true, evalScripts: true, authenticity_token: ep.auth_token, sort_by: ep.sort_by, 
							               container: ep.container, partial: ep.partial, page: ep.page, 
														 last_value: ep.last_value, append: 'true', morebutton :ep.morebutton, q: ep.search, tab: ep.tab, object: ep.name}});
}

function start_endless_page_listener(ep)
{
  timer = setTimeout(function(){iteration(ep)}, ep.period);
}

function stop_endless_page_listener()
{
  timer = null;
}

function EPConfig()
{
  this.offset = 0.5; // part of the scroller panel above scroller needed for new items adding
  this.period = 1000; // period of scroller state checking
  this.sort_by = 'id'; // field in DB that contains data that list is sorted by
  this.container = 'container'; // id of HTML component that contains data items shown in list. plugin will add new items to the bottom of this container
}