//============================== ShareThis ==============================
(function(jQuery) {
	  // Create the ShareThis element queue and the ShareThis API URL default.
	  jQuery.sharethisQueue = [];
	  jQuery.sharethisUrl = "http://w.sharethis.com/button/sharethis.js#";

	  // The $().sharethis() function.
	  jQuery.fn.sharethis = function(sharethisUrl) {
	    // Add the elements to the queue.
	    jQuery.sharethisQueue = jQuery.sharethisQueue.concat(this);

	    // Set a kill switch so that the API isn't loaded twice.
	    if (!jQuery.fn.sharethis.loaded || false) {
	      jQuery.fn.sharethis.loaded = true;

	      // Use the provided URL, or the default one.
	      jQuery.sharethisUrl = sharethisUrl || jQuery.sharethisUrl;

	      // Make the AJAX call to get the ShareThis API.
	      jQuery.ajax( {
	        type :'GET',
	        url : jQuery.sharethisUrl + '&amp;button=false',
	        dataType :'script',
	        cache :true,
	        success : function() {
	          // Prepare the ShareThis API and state that it's ready.
	          SHARETHIS.toolbar = true;
	          SHARETHIS.onReady();
	          jQuery.fn.sharethis.loadedShareThis = true;

	          // Process the element queue once the ShareThis API is loaded.
	          jQuery.shareThis();
	        }
	      });
	    }
	    // If the library has been loaded, then just process the elements.
	    else if (jQuery.fn.sharethis.loadedShareThis || false) {
	      jQuery.shareThis();
	    }
	    return this;
	  };

	  /**
	   * The jQuery.sharethis() function will process through the queue
	   * and create the elements.
	   */
	  jQuery.shareThis = function() {

	    // Loop through the process queue.
	    jQuery.each(jQuery.sharethisQueue, function(i, objects) {
	      jQuery.each(objects, function(i, object) {
	        // Construct the options from the element.
	        var element = jQuery(object);

			var url = window.location.href;
	        var options = {
	          'url' : 	url,
	          'title' : element.attr('title')
	        };
	        // Create the entry and attach it to the link.
	        var share = SHARETHIS.addEntry(options, {button:false});
	        share.attachButton(element.get(0));

	        // Deactivate the default click event.
	        element.click( function() {
	          return false;
	        });
	      });
	    });
	    // Clear the process queue.
	    jQuery.sharethis = [];
		jQuery.sharethisQueue = [];
	  }
	})(jQuery);