﻿/*
sharing plugin
v1.0 (06/08/2009)

USAGE
-----
$("selector").sharing();

*/

jQuery.fn.sharing = function (settings) {
  // if the selector does not contain any elements, return the jQuery object
  if (this.length == 0) return this;

  // default settings
  var share = new Object();
  share.selector = jQuery(this);

  // let css know this is JS driven
  jQuery(share.selector).addClass("sharingWrapperAdv");
  jQuery(share.selector).find("div.share p.title").remove();

  // create new nav ul
  jQuery(share.selector).prepend(
    "<ul class=\"shareNav clearfix\">" +
      "<li class=\"print\"><a href=\"#\" title=\"Print this page\">Print</a></li>" +
      "<li class=\"email\"><a href=\"#\" title=\"Email this page to a friend\">Email</a></li>" +
      "<li class=\"share\"><a href=\"#\" title=\"Add a link to this page\">Share</a></li>" +
      "<li class=\"rss\"><a href=\"#\" title=\"Let our news come to you via an RSS feed\">RSS</a></li>" +
    "</ul>"
  );

  // make the nav work
  jQuery(share.selector).find("ul.shareNav li a").live("click", function () {
    if (jQuery(this).parent().hasClass("email")) { init(); jQuery(this).addClass("active"); jQuery(share.selector).find("div.shareEmail").show(); }
    else if (jQuery(this).parent().hasClass("share")) { init(); jQuery(this).addClass("active"); jQuery(share.selector).find("div.shareLinks").show(); }
    else if (jQuery(this).parent().hasClass("rss")) { init(); jQuery(this).addClass("active"); jQuery(share.selector).find("div.shareRss").show(); }
    else if (jQuery(this).parent().hasClass("print")) window.print();
    return false;
  });

  function init() {
    jQuery(share.selector).find("div.share").hide();
    jQuery(share.selector).find("ul.shareNav li a.active").removeClass("active");
  } // init()

  init();

  // return the jQuery object
  return this;
}  // $.sharing()
