var twitterfill = function(){
  var config,but;
  function init(o){
    config = o;
    var m = document.getElementById(config.mailfield);
    if(m){
      but = document.createElement('input');
      but.type = 'button';
      but.value = o.label;
      but.onclick = function(){
        if(m.value.indexOf('@')===-1){
          m.value = o.mailplease;
          m.focus();
        } else {
          var url = 'http://twitter.com/users/show/show.json?'+
                    'email='+m.value+'&callback=twitterfill.seed'+
                    '&suppress_response_codes';
          var s = document.createElement('script');
          but.value = o.loading;
          s.src = url;
          s.type = 'text/javascript';
          document.getElementsByTagName('head')[0].appendChild(s);
        }
      }
      m.parentNode.insertBefore(but,m.nextSibling);
    }        
  };
  function seed(o){
    but.value = config.label;
    if(!o.error){
      fill(config.name,o.name);
      fill(config.location,o.location);
      fill(config.url,o.url);
    }
  };
  function fill(field,value){
    var x = document.getElementById(field);
    if(x){
      x.value = value;
    }
  }
  return {seed:seed,init:init}
}();

