var Getter = new Class({
  Implements : Options,
  options: {
    getter: "getnext.php",
    imggetter: "getimg.php?f="
  },
  
  initialize: function(globalID, loaderID, options) 
  {
    this.global = $(globalID);
    this.loader = $(loaderID);
    
    this.images = [];
    this.pos = 0;
    this.more = true;
    window.addEvent('scroll', this.grub.bind(this));

    this.req = new Request.JSON({
                      url:this.options.getter, 
                      onSuccess: 
                        (function(images)
                        { 
                            this.images = this.images.concat(images); 
                            if (images.length == 0) 
                            { 
                              this.more = false; 
                              window.removeEvent('scroll', this.grub.bind(this)); 
                            }; 
                            this.doing = false; 
                            this.readnext(); 
                        }).bind(this)});
    this.req.get();
  },

  readnext: function()
  {
    if (this.doing)
      return;
    this.doing = true;
    
    this.loader.setStyle('display','block');
    if (this.more && this.pos > this.images.length-4)
    {
      this.req.get();
      return;
    }
    
    new Asset.image(this.options.imggetter+this.images[this.pos][0], {onload: this.loadnext.bind(this)});
  },
  
  loadnext: function(img)
  {
    w = img.get('width') / 1;
    h = img.get('height') / 2;
    d = new Element('div',{'class':'h', 'styles':{'width':w,'height':h,'opacity':0}});
    
    if (this.images[this.pos][1] != "")
    {
      a = new Element('a',{'href':this.images[this.pos][1],'target':'_blank'});
      img.inject(a);
      a.inject(d);
    }
    else
      img.inject(d);

    d.inject(this.global.getElement('br'),'before');
    d.get('morph').start({opacity:1});

    ++this.pos;
    this.doing = false;
    
    this.grub();
  },
  
  grub: function()
  {
    if ( (document.getScroll().y+document.window.getSize().y > this.global.getSize().y-1500 || !this.more) && this.pos<this.images.length)
      this.readnext();
    else
      this.loader.setStyle('display','none');
  }
});



var g;
var m1 = 'creative'+'@'+'georgesetmonbizarre'+'.'+'com';
var m2 = 'photography'+'@'+'georgesetmonbizarre'+'.'+'com';
window.addEvent('domready',function()
  {
    g = new Getter('global','loader');
    $('a').set('html', m1);
    $('p').set('html', m2);
    document.oncontextmenu = function(){return false}
  });



function mm(m)
{
  f = 'm';
  l = 'lto';
  y = "subject=[G%26MB]";
  window.location.href = f+'ai'+l+':'+m+'?'+y;
}


