var socializeit = function(options) {
  if (!options || !options.domain) {
    throw new Error('Error: must pass socializeit a domain (e.g. socializeit({domain:"www.example.com"})).')
  }

  var d = document,
      l = d.location,
      e = encodeURIComponent,
      u = e(l.href),
      t = e(d.title),
      domain = options.domain,
      urlroot = 'http://'+domain+'/objects/';

  var sites = [
    {name: 'Google', 
     img: urlroot+'google.gif',
     url: 'http://www.google.com/ig/adde?moduleurl=www.google.com/ig/modules/bookmarks.xml&amp;hl=en/u='+ u +'&amp;t=' + t},
    {name: 'Buzz',
     img: urlroot+'yahoobuzz1.gif',
     url: 'http://buzz.yahoo.com/submit?submitUrl='+ u +'&amp;t=' + t},
    {name: 'Facebook',
     img: urlroot+'Facebook.gif',
     url: 'http://www.facebook.com/share.php?u='+ u +'&amp;t=' + t},
    {name: 'Myspace',
     img: urlroot+'myspace.gif',
     url: 'http://www.myspace.com/Modules/PostTo/Pages/?u='+ u +'&amp;t=' + t},
    {name: 'StumbleUpon', 
     img: urlroot+'StumbleUpon.gif',
     url: 'http://www.stumbleupon.com/submit?url=' + u + '&amp;title=' + t},
    {name: 'Technorati',
     img: urlroot+'Technorati.gif',
     url: 'http://technorati.com/faves/?add=' + u},
    {name: 'del.icio.us',
     img: urlroot+'del.gif',
     url: 'http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=' + u + '&amp;title=' + t},
    {name: 'Twitter',
     img: urlroot+'twitter.gif',
     url: 'http://twitter.com/home?status=Reading%20about%20'+t+'%20-%20' + u}
  ];

  arguments.callee.getURL = function(which) {
    for (var i=0, ilen=sites.length; i<ilen; i++) {
      var site = sites[i];
      if (site.name == which) {
        return site.url;
      }
    }
  };

  var html = '<table  align="left" style="border: 0px solid #ccc;padding:2px;width:430px;"><tbody><tr><td style="white-space:nowrap;"><p>Spread the word:&nbsp;</p>';
  if (options.whatIsThisUrl) {
    html += '<br><span style="font-size:11px;"><a href="#" onclick="window.open\(\''+options.whatIsThisUrl+'\', \'sharer\',\'toolbar=0,status=0,width=700,height=500,resizable=yes,scrollbars=yes\'\); return false;">What\'s This?</a></span>';
  }
  html += '</td>';
  // visually want two rows of links
  var midpoint = Math.floor((sites.length-1)/1);
  var iCols= ((2 + midpoint) <ilen)? 2 + midpoint: ilen;

  for (var i=0, ilen=sites.length; i<ilen; i++) {
    var site = sites[i].name;
    var imgURL = sites[i].img;
    var url = sites[i].url;
    html += '<td><a href="#share_on_'+site+'" onclick="window.open(socializeit.getURL(\''+site+'\'), \'sharer\', \'toolbar=0,status=0,width=700,height=500,resizable=yes,scrollbars=yes\');return false;"><img src="'+imgURL+'" alt="'+site+'" title="'+site+'" style="border:0"></a></td>';
    if ((i == midpoint) && (i+1)<ilen) {
      html += '';
    }
  }
  
  html += '</tr></tbody></table>';
  
  document.writeln(html);
};

