/**
 * name:          jquery-floatAds-0.1.js
 * author:        Challen Wong
 * version:       0.1
 * last update:   2009/11/21
 * category:      jQuery plugin
 * copyright:     (c) 2009 Challen Wong
 * license:       GNU GPLv3
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * next test: 
    //var window_width = $(window).width();
    //var document_width = $(document).width();
    //var equal_width = (window_width >= document_width) ? true : false;
    //var lower_width = (window_width < document_width) ? true : false;
 */
(function($) {
  $.fn.floatAds = function(settings) {

    settings = jQuery.extend({
		parent: 'body',
        align: 'right',
		space: 20,
        distance: 50,
	    width: 0,
		height: 0,
        speed: 500
      }, settings);
	var obj = $(this);
    var scroll_top = $(document).scrollTop();
	var width = (settings.width == 0) ? $(obj).width() : settings.width;

    $(obj).css({'position':'absolute',
        'top':settings.distance,
	    'width':width
    });
	if (settings.align=='left') { $(obj).css('left',settings.space); } else { $(obj).css('right',settings.space); }
    
    if(scroll_top) move();

    $(window).scroll(function(){
      move();
    });

    function move(){
		if (typeof window.pageYOffset != 'undefined') {
			scroll_top = window.pageYOffset;
		}
		else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
		{
			scroll_top = $(document).scrollTop();
		}
		else if (typeof $(parent).scrollTop != 'undefined') {
			scroll_top = $(parent).scrollTop;
		}
		$(obj).animate({ top: settings.distance + scroll_top },{queue:false}, settings.speed);
    }
  }
})(jQuery);
