/**
 * Endless Scroll plugin for jQuery
 *
 * v1.3
 *
 * Copyright (c) 2008 Fred Wu
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

/**
 * Usage:
 * 
 * // using default options
 * $(document).endlessScroll();
 *
 * // using some custom options
 * $(document).endlessScroll({
 *   fireOnce: false,
 *   fireDelay: false,
 *   loader: "<div class=\"loading\"><div>",
 *   callback: function(){
 *     alert("test");
 *   }
 * });
 *
 * Configuration options:
 *
 * bottomPixels  integer          the number of pixels from the bottom of the page that triggers the event
 * fireOnce      boolean          only fire once until the execution of the current event is completed
 * fireDelay     integer          delay the subsequent firing, in milliseconds. 0 or false to disable delay.
 * loader        string           the HTML to be displayed during loading
 * data          string|function  plain HTML data, can be either a string or a function that returns a string
 * insertAfter   string           jQuery selector syntax: where to put the loader as well as the plain HTML data
 * callback      function         callback function, accepets one argument: fire sequence (the number of times 
 *                                the event triggered during the current page session)
 * resetCounter  function         resets the fire sequence counter if the function returns true, this function
 *                                could also perform hook actions since it is applied at the start of the event
 * ceaseFire     function         stops the event (no more endless scrolling) if the function returns true
 *
 * Usage tips:
 *
 * The plugin is more useful when used with the callback function, which can then make AJAX calls to retrieve content.
 * The fire sequence argument (for the callback function) is useful for 'pagination'-like features.
 */

(function(a){a.fn.endlessScroll=function(b){var c={bottomPixels:50,fireOnce:true,fireDelay:150,loader:"<br />Loading...<br />",data:"",insertAfter:"div:last",resetCounter:function(){return false},callback:function(){return true},ceaseFire:function(){return false}};var b=a.extend(c,b);var d=true;var e=false;var f=0;if(b.ceaseFire.apply(this)===true){d=false}if(d===true){a(window).scroll(function(){if(a(document).height()-a(window).height()<=a(window).scrollTop()+b.bottomPixels){if(b.fireOnce==false||b.fireOnce==true&&e!=true){if(b.resetCounter.apply(this)===true){f=0}e=true;f++;a(b.insertAfter).after('<div id="endless_scroll_loader">'+b.loader+"</div>");if(typeof b.data=="function"){data=b.data.apply(this)}else{data=b.data}if(data!==false){a("div#endless_scroll_loader").remove();a(b.insertAfter).after('<div id="endless_scroll_data">'+data+"</div>");a("div#endless_scroll_data").hide().fadeIn();a("div#endless_scroll_data").removeAttr("id");var c=new Array;c[0]=f;b.callback.apply(this,c);if(b.fireDelay!==false||b.fireDelay!==0){a("body").after('<div id="endless_scroll_marker"></div>');a("div#endless_scroll_marker").fadeTo(b.fireDelay,1,function(){a(this).remove();e=false})}else{e=false}}}}})}}})(jQuery)
