/*
 * Insert social bookmarking icons in a web page.
 * Refactored after from Hugo Haas (http://larve.net/people/hugo/)
 * Images from Kirk Montgomery
 * Sample usage (both tytle and url params are optionals and default to current
 * title and URL.
 *
 *       <html>
 *         <head>
 *           <title>Some title</title>
 *           <script type="text/javascript" src="SocialBookmarking.js"> </script>
 *         </head>
 *         <body>
 *           <p>bla bla bla </p>
 *           <script type="text/javascript"> (new SocialBookmarking("title", "url")).insert();</script>
 *         </body>
 *       </html> 
 *    
 */
 
var SocialBookmarking = function () {
  if (arguments.length >= 1)
    this.title = arguments[0];
  else
    this.title = encodeURIComponent(document.title);
  if (arguments.length >= 2)
    this.url = arguments[1];
  else
    this.url = encodeURIComponent(document.URL);
  this.image_dir="http://goals4sure.com:8080/roller/shared/images";
  this.inserta = function() {
    alert('meaow');
  }
  this.socialHistory = new SocialHistory();
}

SocialBookmarking.prototype.addIcon = function(icon, name, url) {
  var re = new RegExp("^mailto:.*");
  var doesVisit = this.socialHistory.doesVisit(name) === true || url.match(re);
  if (doesVisit)
    document.write('<span class="socialAddButton" id="socialAddButton-' + icon + '"><a href="' + url + '" title="Add to ' + name +'"><img border="0" src="' + this.image_dir + '/' + icon + '.png" alt="' + name + ' icon" /></a></span> ');
}

SocialBookmarking.prototype.insert = function() {
  this.addIcon('blinklist', 'BlinkList', 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=' + this.url + '&amp;Title=' + this.title);
  this.addIcon('blogmarks', 'BlogMarks', 'http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('delicious', 'Del.icio.us', 'http://del.icio.us/post?url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('digg', 'Digg', 'http://digg.com/submit?phase=2&amp;url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('dzone', 'Dzone', 'http://www.dzone.com/links/add.html?url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('fark', 'Fark', 'http://cgi.fark.com/cgi/fark/edit.pl?new_url=' + this.url + '&amp;new_comment=' + this.title + '&amp;linktype=');
  this.addIcon('furl', 'Furl', 'http://www.furl.net/storeIt.jsp?u=' + this.url + '&amp;t=' + this.title);
  this.addIcon('google', 'Google Bookmarks', 'http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=' + this.url + '&amp;title=' + this.title);
  this.addIcon('magnolia', 'Ma.gnolia', 'http://ma.gnolia.com/bookmarklet/add?url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('netvouz', 'Netvouz', 'http://www.netvouz.com/action/submitBookmark?url=' + this.url + '&amp;title=' + this.title + '&amp;popup=no');
  this.addIcon('newsvine', 'Newsvine', 'http://www.newsvine.com/_tools/seed&amp;save?u=' + this.url + '&amp;h=' + this.title);
  this.addIcon('reddit', 'Reddit', 'http://reddit.com/submit?url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('segnalo', 'Segnalo', 'http://segnalo.com/post.html.php?url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('simpy', 'Simpy', 'http://www.simpy.com/simpy/LinkAdd.do?href=' + this.url + '&amp;title=' + this.title);
  this.addIcon('slashdot', 'Slashdot', 'http://slashdot.org/bookmark.pl?title=' + this.title + '&amp;url=' + this.url);
  this.addIcon('smarking', 'Smarking', 'http://smarking.com/editbookmark/?url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('spurl', 'Spurl.net', 'http://www.spurl.net/spurl.php?url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('stumbleupon', 'StumbleUpon', 'http://www.stumbleupon.com/submit?url=' + this.url + '&amp;title=' + this.title);
  this.addIcon('technorati', 'Technorati', 'http://technorati.com/faves?add=' + this.url);
  this.addIcon('twitter', 'Twit this', 'http://twitter.com/home?status=' + this.url);
  this.addIcon('wists', 'Wists', 'http://wists.com/r.php?c=&amp;r=' + this.url + '&amp;title=' + this.title);
  this.addIcon('yahoomyweb', 'Yahoo! My Web', 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' + this.url + '&amp;t=' + this.title);

  this.addIcon('email_link', 'E-mail this link to a friend', 'mailto:?subject=' + this.title + '&body=' + this.url);
  
}


