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://www.'+domain+'/__bookmarkImgs/';

  var sites = [
    {name: 'Google', 
     img: urlroot+'google.png',
     url: 'http://www.google.com/bookmarks/mark?op=edit&bkmk='+ u +'&title=' +t},
    {name: 'Buzz',
     img: urlroot+'yahoo.png',
     url: 'http://buzz.yahoo.com/submit?submitUrl='+ u +'&amp;t=' + t},
    {name: 'Facebook',
     img: urlroot+'facebook.png',
     url: 'http://www.facebook.com/share.php?u='+ u +'&amp;t=' + t},
    {name: 'Myspace',
     img: urlroot+'myspace.png',
     url: 'http://www.myspace.com/Modules/PostTo/Pages/?u='+ u +'&amp;t=' + t},
    {name: 'StumbleUpon', 
     img: urlroot+'stumbleupon.png',
     url: 'http://www.stumbleupon.com/submit?url=' + u + '&amp;title=' + t},
    {name: 'Technorati',
     img: urlroot+'technorati.png',
     url: 'http://technorati.com/faves/?add=' + u},
    {name: 'del.icio.us',
     img: urlroot+'delicious.png',
     url: 'http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=' + u + '&amp;title=' + t},
    {name: 'Twitter',
     img: urlroot+'twitter.png',
     url: 'http://twitter.com/home?status=Reading%20about%20this:%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:0px; width:500px;"><tbody><tr><td rowspan="0" style="padding:0px; vertical-align:left;">';
   html += '</td>';
  // visually want two rows of links
  var midpoint = Math.floor((sites.length-1)/1);
  var iCols= ((1 + midpoint) <ilen)? 1 + 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 += '<th><a href="#share_on_'+site+'" onclick="window.open(socializeit.getURL(\''+site+'\'), \'sharer\', \'toolbar=0,status=0,width=500,height=625,resizable=no,scrollbars=no\');return false;"><img src="'+imgURL+'" alt="'+site+'" style="border:0; padding:0px; float:left;"></a></th>';
    if ((i == midpoint) && (i+1)<ilen) {
      html += '</tr><tr>';
    }
  }
  html += '</tr>';
  
  html += '</tbody></table>';
  
  document.writeln(html);
};


