/*
 * jQuery Socialize plugin
 * Version 1.0  (12/09/2008)
 * @requires jQuery v1.1.1+
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/*
 * Thanks to the following plugin authors for some ideas and especially the URLs:
 *
 * Keith Wood, Sharing bookmarks
 * David Zhou, jQuery ShareHelper
 *
 */

;(function($) {
// adds social bookmarks to a blog entry
var idCounter = 0;
$.fn.socialize = function(options) {
  var opts = $.extend({}, $.fn.socialize.defaults, options),
      siteInfo = $.extend($.socialSites, $.moreSites),
      sites = opts.sites;
      if (typeof sites == 'string') {
        sites = sites.replace(/,\s+/g,',').split(',');
      }
      var sitesLength = sites.length;
  return this.each(function(index) {
    var siteLinks = [];
    for (var i=0; i < sitesLength; i++) {
      var site = siteInfo[sites[i]];
      if (site === undefined) continue;
      var urlKey = site.urlKey ? site.urlKey + '=': '';
      var siteLink = '<a title="post to ' + sites[i] + '" ';     
      siteLink += 'href="' + site.url + urlKey + encodeURIComponent(window.location.href) + '&amp;' + site.titleKey + '=' + encodeURIComponent(document.title) + '" ';
      siteLink += 'class="' + opts.linkClass + ' ' + sites[i] + '">';
      siteLink += sites[i];
      siteLink += '</a>';
      siteLinks[i] = siteLink;
    }
    
    var cid = opts.containerId + '-' + (++idCounter) + '-' + index,
        cclass = opts.containerClass;
    $('<div id="' + cid + '" class="' + cclass + '">' + siteLinks.join('') + '</div>')[opts.insertion](this);
    $.each(opts.events, function(key, func) {
      var handler = key + '.socialize';
      if (typeof func == 'function') {
        $('a', '#'+cid).bind(handler, function(evt) {
          func.call(this, evt);
          evt.preventDefault();
        });
      }
    });
  });

};

// default options
$.fn.socialize.defaults = {
  // default set of sites; more can be found in jquery.socialize.moresites.js
  sites: ['delicious', 'digg', 'dzone', 'reddit', 'stumbleupon'],
  containerId: 'social-icons',
  containerClass: 'group',
  linkClass: 'social-icon',
  insertion: 'appendTo',
  events: {
    /*
    click: function(event) { },
    mouseover: function(event) { }
    */
  }
};

// social media/bookmarking sites
$.socialSites = {
  delicious: {
    url: 'http://del.icio.us/post?v=2&amp;',
    urlKey: 'url',
    titleKey: 'title'
  },
  digg: {
    url: 'http://digg.com/submit?',
    urlKey: 'url',
    titleKey: 'title'    
  },
  dzone: {
    url: 'http://www.dzone.com/links/add.html?',
    urlKey: 'url',
    titleKey: 'description'
  },
  reddit: {
    url: 'http://reddit.com/submit?',
    urlKey: 'url',
    titleKey: 'title'
  },
  stumbleupon: {
    url: 'http://www.stumbleupon.com/refer.php?',
    urlKey: 'url',
    titleKey: 'title'
  }
};
$.moreSites = $.moreSites || {};
})(jQuery);


/* 
 *
 * This file contains the information for additional social media / bookmarking sites
 * This file can be used in its entirety or piecemeal. 
 * It must be used along with jquery.socialize.js (and the core jQuery file).
 *
 * The following sites are represented here:
 * bebo, blinklist, bloglines, blogmarks, facebook, friendfeed, furl, google, magnolia, 
 * myspace, newsvine, simpy, slashdot, spurl, squidoo, yahoo
 *
 * Feel free to add your own
 */
 
/* To use any of these bookmarks, add their names to the sites option array
 * For example:
 * $('#container').socialize({sites: ['delicious', 'digg', 'facebook', 'myspace']});
 */
$.moreSites = {};

$.moreSites.bebo = {
  url: 'http://bebo.com/c/share?',
  urlKey: 'Url',
  titleKey: 'Title'
};

$.moreSites.blinklist = {
  url: 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;',
  urlKey: 'Url',
  titleKey: 'Title'
};

$.moreSites.bloglines = {
  url: 'http://www.bloglines.com/citations?',
  urlKey: 'url',
  titleKey: 'title'
};

$.moreSites.blogmarks = {
  url: 'http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;',
  urlKey: 'url',
  titleKey: 'title'
};

$.moreSites.facebook =   {
  url: 'http://www.facebook.com/sharer.php?',
  urlKey: 'u',
  titleKey: 'title'
};

$.moreSites.friendfeed = {
  url: 'http://friendfeed.com/share?',
  urlKey: 'url',
  titleKey: 'title'
};

$.moreSites.furl = {
  url: 'http://www.furl.net/storeIt.jsp?',
  urlKey: 't',
  titleKey: 'u'
};

$.moreSites.google = {
  url: 'http://www.google.com/bookmarks/mark?op=edit&amp;',
  urlKey: 'bkmk',
  titleKey: 'title'
};

$.moreSites.magnolia = {
  url: 'http://ma.gnolia.com/bookmarklet/add?',
  urlKey: 'url',
  titleKey: 'title'
};

$.moreSites.myspace = {
  url: 'http://www.myspace.com/Modules/PostTo/Pages/?',
  urlKey: 'c',
  titleKey: 't'
};

$.moreSites.newsvine = {
  url: 'http://www.newsvine.com/_wine/save?',
  urlKey: 'u',
  titleKey: 'h'
};

$.moreSites.simpy = {
  url: 'http://www.simpy.com/simpy/LinkAdd.do?',
  urlKey: 'href',
  titleKey: 'title'
};

$.moreSites.slashdot = {
  url: 'http://slashdot.org/bookmark.pl?',
  urlKey: 'url',
  titleKey: 'title'
};

$.moreSites.spurl = {
  url: 'http://www.spurl.net/spurl.php?',
  urlKey: 'url',
  titleKey: 'title'
};

$.moreSites.squidoo = {
  url: '://www.squidoo.com/lensmaster/bookmark?',
  urlKey: '',
  titleKey: 'title'
};

$.moreSites.yahoo = {
  url: 'http://myweb2.search.yahoo.com/myresults/bookmarklet?',
  urlKey: 't',
  titleKey: 'u'
};

/*
bebo, blinklist, bloglines, blogmarks, facebook, friendfeed, furl, google, magnolia, 
 * myspace, newsvine, simpy, slashdot, spurl, squidoo, yahoo
*/ 

