/**
 * @preserve Copyright (c) Shareaholic Inc (www.shareaholic.com).  All rights reserved.
 */
 
if (typeof(SHR4P)=="undefined") SHR4P = {};
if (typeof(SHR)=="undefined") SHR = {};
//SHR.debug_enabled = true;
SHR.enforceSSL = true;

if(typeof(SHRSB_Globals) == 'undefined') {
    window["SHRSB_Globals"] = {};
}
if(typeof(SHRSB_Globals.perfoption) == 'undefined') {
    SHRSB_Globals.perfoption = '1';
	// Add perfoption to SHRSB_Globals. This decides if Google analytics would be loaded or not
}
if(typeof(SHRSB_Globals.minJQueryVersion) == 'undefined') {
    SHRSB_Globals.minJQueryVersion = '1.5.2';
    // Add the minJqueryVersion in SHRSB_Globals variable if not present.
    // Will be used later to compare with pageJqueryVersion.
}

//Settings Base URL and CDN URL
SHR4P.host = (typeof(SHR['debug_enabled']) !== "undefined") ? "www.spreadaholic.com" : "www.shareaholic.com";
SHR4P.base_url = ( (SHR.enforceSSL) ?  "https:" : document.location.protocol) + '//'  + SHR4P.host;
SHR4P.cdn_url =  ( (SHR.enforceSSL || 'https:' == document.location.protocol) ? 'https://dtym7iokkjlif.cloudfront.net' : 'http://cdn.shareaholic.com');
SHR4P.cdn_url = (typeof(SHR['debug_enabled']) !== "undefined") ? SHR4P.base_url : SHR4P.cdn_url;

//SHR4P.shr_image = SHR4P.cdn_url + "/media/images/styles/tb/shareaholic-publishers-mini.png";
SHR4P.shr_twitter_image = SHR4P.cdn_url + "/media/images/styles/tb/twitter.png";
SHR4P.shr_twitter_template = '${title} - ${short_link} via @Shareaholic';
if(typeof(SHRSB_Settings) != "undefined" && typeof(SHRSB_Settings.twitter_template) != "undefined") SHR4P.shr_twitter_template = SHRSB_Settings.twitter_template;
if(typeof(SHRSB_Globals) != "undefined" && typeof(SHRSB_Globals.twitter_template) != "undefined") SHR4P.shr_twitter_template = SHRSB_Globals.twitter_template;

if(typeof(SHRSB_Globals) != "undefined" && typeof(SHRSB_Globals.src) != "undefined")  {
    SHR4P.shr_image = SHRSB_Globals.src + "/shareaholic-publishers-mini.png";
}
var SHR4P_init = function() {

  SHR4P.debug('SHR4P_init called');
  // only one please!
  if (SHR4P.init) {
    SHR4P.debug('SHR4P_init returning because already loaded');
    return;
  }
  SHR4P.init = true;
  if(typeof(sb_dont_noConflict) != "undefined" && sb_dont_noConflict) {
    SHR4P.jQuery = jQuery; // We didn't insert any jquery so shouldnot no conflict
  } else {
    SHR4P.jQuery = jQuery.noConflict(true);
  }

  SHR4P.debug("jquery version: " + SHR4P.jQuery().jquery);

  (function($) {
    SHR4P.debug('initializing shareaholic_publishers plugin');
    $.fn.shareaholic_publishers = function(options) {
      var config = $.extend({
        v: 1,              // api version(not used)
        src: SHR4P.base_url,  // where api calls are made
        mode: 'inject',    // (iframe|inject)
        service: '',       // comma seperated list of service ids
        apikey: '',        // developer key
        link: '',          // bookmark permalink
        title: '',         // bookmarked page's title
        notes: '',         // bookmarked page's notes
        expand: true,      // should iframe auto-expand?
        duration: 400,     // transition time for iframe expansion
        rel: 'nofollow',   // bookmark anchor's rel attr
        target: '_blank',  // bookmark anchor's target attr
        twitter_template: '${title} - ${short_link} via @Shareaholic', // tweet format
        dontShowShareCount: false,   // show facebook and twitter share counters
        fbLikeButton: false,   // show facebook like button
        fbButtonPos: "bottom-right",
        tags: '',          // comma seperated list of tags
                           // use double-quotes to escape commas
        allowExternalTags:  true,
        designer_toolTips: false, // use facebook style designer tooltips
        tip_bg_color: "black", // color of the background for tooltip
        tip_text_color: "white", // color of the text for tooltip
                            // allow shareaholic to pull descriptive tags from external services like delicious and stumbleupon
        category: '',      // bookmark category
        ctype: '',         // bookmark content type (flash|iframe|link|image)
        short_link: '',    // bookmark shortened URL
        shortener: 'google', // googl is the default shortener
        shortener_key: '', // user|apikey of bitly/supr or anyother shortener service
        // The url shortening has been moved to shareapi.
        // List of supported services  tinyurl|supr|bitly|jmp|google|none
        // Use "none" if you don't want the link shortened
        // Example shortener_key: 'shareaholic|R_83932e4c5d02d1f94aea0f40fbc557ec'
        // A provided short_link over rides everything and is the one used if provided.

        // Allows custom links that aren't provided by shareaholic.  use keys
        // like before_n and after_n where n is the position index, starting
        // with zero.
        //
        // Ex.
        // $('#mydiv').shareaholic_publishers({
        //   ...
        //   custom_link: {
        //     // first service
        //     before_0: {
        //       li_class: 'custom-link-class-1',
        //       link: 'http://myservice/add?url=http://myblog.com&title=My+Super+Blog'
        //     },
        //     // forth (really fifth, because we inserted one above with
        //     // before_0)
        //     after_3: {
        //       li_class: 'custom-link-class-2',
        //       link: 'http://myotherservice/add?url=http://myblog.com&title=My+Super+Blog'
        //     },
        //   },
        //   ...
        // });
        custom_link: {},
        bgimg: '',         // url to background image
        bgimg_padding: '0 0 0 0',
        center: false,     // center the bookmarks in the container
        spaced: false,     // space the bookmarks evenly in the container
        iframe_src: '/publishers',
        spriteimg: '',     // url of sprite, will be created if blank
        // This is where share links point to, this is seperate because we
        // need the share service for links, we can't use a cached static
        // version.
        share_src: SHR4P.base_url,
        // This causes api paths to have extentions added for cached copies
        // on your plain ordinary web server.
        // This is useful to reduce calls to the shareaholic domain, which
        // could slow down load times.
        // $src/api/sprite/ becomes $src/api/sprite.css
        // $src/publishers becomes $src/publishers.html
        // you should pass a proper spriteimg when you generate your localized
        // sprite.css as the path to your local copy.
        localize: false,
        // bgimg: 'shr',
        // These are set by the iframe api call shareaholic css, which we have no
        // way of of getting at.  We need them to calculate the iframe height,
        // colapsed and expanded
        li_margin: 0,
        'margin-top': 20,
        'margin-bottom': 20,
        'margin-left': 0,
        'bgimg-padding-top': 0,
        'bgimg-padding-left': 0,
        'icon-width': 60,
        'icon-height': 29,
        'icon-margin-top': 3,
		'promo-height' : options.shrlink ? 18 : 0 ,
        shrlink: false,      // show 'get shareaholic' text
				twitter_overlay : true
      }, options);

      var jThis = $(this) ;
      SHR4P.debug('$.fn.shareaholic_publishers called');
      SHR4P.debug(config);

      // ie6 tweak
      if ($.browser.msie && $.browser.version < '7.0') {
        config['icon-height'] += 4;
      }

      //Checks for the Post Link
      if (!config.link || (config.link && config.link === ''  )) {
          config.link = jThis.attr('data-shr_href') || document.location.href;  
      }
      //Checks for the Post Title
      if (!config.title || (config.title && config.title === ''  )) {
          config.title = jThis.attr('data-shr_title') || document.title;  
      }

      // adjust bgimg if bgimg is not null
      if (config.bgimg != null) {
        var parts = $.trim(config['bgimg_padding']).split(' ');
        config['bgimg-padding-top'] = parts[0]?Number(parts[0].replace(/[a-zA-Z]+/, '')):0;
        config['bgimg-padding-left'] = parts[3]?Number(parts[3].replace(/[a-zA-Z]+/, '')):0;
        config['margin-left'] = 10;
      }

      if (config.localize) {
        config.iframe_src = '/publishers.html';
      }

      /**
       * The following helper methods are used to calculate the appropriate
       * iframe heights for collapsed and expended bookmarks.
       */
      var self = this;
      var icon_count = function() {
        var custom_link_count = 0;
        if (!$.isEmptyObject(config.custom_link)) {
          custom_link_count = $(config.custom_link).length;
        }
        return config.service.split(',').length + custom_link_count;
      }

      var gutter_left = function() {
        return config['margin-left'] + config['bgimg-padding-left'];
      }

      var icons_per_row = function(width) {
        return Math.floor((width - gutter_left()) / config['icon-width']);
      }

      var row_count = function(width) {
        return Math.ceil(icon_count() / icons_per_row(width));
      }

      var url = function(path, params) {
        return [path, $.param(params)].join('?');
      }

      var init_height = function(width) {
        if (config.expand) {
          var ret = config['margin-top'] + config['bgimg-padding-top'] +
            config['icon-height'] + config['icon-margin-top'] +
			((row_count(width) == 1) ? config['promo-height'] : 0);
        } else {
          var ret = hover_height(width);
        }
        return ret;
      }

      var hover_height = function(width) {
		var ret = config['margin-top'] + config['bgimg-padding-top'] +
            (config['icon-height'] + config['icon-margin-top']) * row_count(width) +
			config['promo-height'];
        return ret;
      }

      var center_margin = function(width) {
        SHR4P.debug('centering');
        var ret = 0;
        if (row_count(width) == 1) {
          SHR4P.debug('one row! do centering');
          ret = (width - gutter_left() - (icon_count() * config['icon-width'])) / 2;
		  SHR4P.debug('returning '+ret+' margin');
        }
        return ret;
      }

      var spaced_margin = function(width) {
        SHR4P.debug('spacing');
        SHR4P.debug('rows: '+row_count(width));
        var ret = 0;
        if (row_count(width) == 1) {
          SHR4P.debug('one row! spacing icons');
          ret = Math.floor((width - gutter_left() - config['icon-width']*icon_count()) / icon_count());
          SHR4P.debug('returning '+ret+' margin');
        }
        return ret;
      }
      this.each(function() {
        if (config.spaced) {
          config.li_margin = spaced_margin($(this).width());
        }

        var params = {
          src: config.src,
          service: config.service,
          apikey: config.apikey,
          link: config.link,
          title: config.title,
          notes: config.notes,
          bgimg: config.bgimg,
          bgimg_padding: config.bgimg_padding,
          rel: config.rel,
          target: config.target,
          twitter_template: config.twitter_template,
          localize: config.localize,
          share_src: config.share_src,
          spriteimg: config.spriteimg,
          tags: config.tags,
          allowExternalTags:  config.allowExternalTags,
          designer_toolTips : config.designer_toolTips,
          tip_bg_color: config.tip_bg_color,
          tip_text_color: config.tip_text_color,
          category: config.category,
          ctype: config.ctype,
          custom_link: config.custom_link,
          li_margin: config.li_margin,
          short_link: config.short_link,
          shortener: config.shortener,
          shortener_key: config.shortener_key,
          shrlink: config.shrlink,
          expand: config.expand,
          dontShowShareCount: config.dontShowShareCount,
          fbLikeButton: config.fbLikeButton,
          fbButtonPos:  config.fbButtonPos,
          twitter_overlay: config.twitter_overlay
        };
        if (config.center) {
          $(this).css({'margin-left': center_margin($(this).width())});
        }
        if (config.mode == 'inject') {
			$(this).shareaholic(params);
        } else {
          $(this).append(
            // frameborder is for ie compatibility
            $('<iframe frameborder="0"/>').attr({
              src: url(config.src+config.iframe_src, params),
              height: init_height($(this).width()),
              width: $(this).width(),
              scrolling: 'no',
              'class': 'share-iframe'
            }).css({'height': hover_height($(this).width())})
          );
        }
        if (config.expand) {
          $(this).css({'overflow': 'hidden', 'height': init_height($(this).width())});
          $(this).hover(
            // mouse in, display all rows
            function() {
              $(this).animate(
                {height: hover_height($(this).width())},
                {duration: config.duration, queue: false}
              );
            },
            // mouse out, display one row
            function() {
              $(this).animate(
                {height: init_height($(this).width())},
                {duration: config.duration, queue: false}
              );
            }
          );
        }
      });
      return this;
    }

    /**
     * Bit.ly service to shorten urls using the bitly js client.
     */
    var bitly_service = function(config, callback) {
      var bitly_init = function() {
        SHR4P.debug('bitly javascript loaded');
        var link = config.link;
        BitlyCB.mycallback = function(response) {
          SHR4P.debug('bit.ly calls back with');
          SHR4P.debug(response);
          if (response.errorCode == 0) {
            SHR4P.debug('successfully shortened, calling callback with: ');
            var sl = response.results[link].shortUrl;
            SHR4P.debug('short_link: '+sl);
            SHR4P.debug('type: '+typeof(sl));
            callback(sl);
          }
          // TODO: add error handling
        }
        BitlyClient.call('shorten', {'longUrl': link}, 'BitlyCB.mycallback');
      };

      if (typeof(BitlyClient) == 'undefined') {
        SHR4P.debug('loading bit.ly');
        var head = document.getElementsByTagName('head')[0];
        if (typeof(head) != 'undefined') {
          var auth = config.shortener_key.split('|');
          var bitly_script = document.createElement('script');
          bitly_script.src = "http://bit.ly/javascript-api.js?version=latest&login="+
            auth[0]+"&apiKey="+auth[1];
          bitly_script.type = "text/javascript";
          bitly_script.charset = "utf-8";
          head.appendChild(bitly_script);
          bitly_script.onreadystatechange = function() {
            if (this.readyState == 'complete' || this.readyState == 'loaded') {
              SHR4P.debug('bit.ly loaded with onreadystatechange, init\'ing');
              bitly_init();
            }
          };
          bitly_script.onload = bitly_init;
        }
      } else {
        SHR4P.debug('bit.ly already loaded.  init\'ing');
        bitly_init();
      }
    }

    SHR4P.debug('initializing shareaholic plugin');
    $.fn.shareaholic = function(options) {
      // hide so we can wait for css updates before displaying the bookmarks.
      // Otherwise we get flicker.
      var config = $.extend({
        service: '',
        rel: 'nofollow',
        target: '_blank',
        poller_timeout: 200,
        link: '',
        title: '',
        notes: '',
        bgimg: '',
        bgimg_padding: '',
        twitter_template: '${title} - ${short_link}',
        tags: '',
        category: '',
        ctype: '',
        localize: false,
        custom_link: {},
        li_margin: 0, //  Sets left margin on bookmarks, used for sexy spacing
        // used for share api
        share_src: SHR4P.base_url,
        // used for other apis
        src: SHR4P.base_url,
        api: {
          share: {
            v: '1',
            url: '/api/share/',
            apitype: '1',
            source: 'Shareaholic-Publishers'
          },
          sprite: {
            v: '2',
            url: '/api/sprite/'
          }
        },
        short_link: '',
        shortener: 'google',
        shortener_key : '',
        // The user overrides these values to select their shortener.
        // The shortener service is only used when short_link is not
        // explicitly provided and a bookmark that requires short_link
        // is clicked.

        // Register new shorteners here.  They should be a method that accepts
        // two parameters.  config and callback.  Inside config you should find
        // config.shortener_key for authorization parameters.  It can be in
        // any format you like, but we encourage pipe delimited data with
        // identifier|key or just key, depending on the service.  Once the URL
        // is shortened, it should be passed back to the callback as the only
        // parameter.  The service can expect the full link to be passed as
        // config.link.
        //
        // The shortener is only when a link that requires a short_link is
        // clicked and config.short_link was not explicitly specified.
        shortener_services: {
          /*
          'stub': function(config, callback) {
            callback(SHR4P.base_url);
          },*/
          'bit.ly': function(config, service_callback) {
            bitly_service(config, service_callback);
          }
        }
      }, options);

      SHR4P.debug('$.fn.shareaholic called');
      SHR4P.debug(config);

      $(this).addClass('shareaholic-show-on-load');
	  //removed css display none, which is not needed , and was most probably a bug, as the css class is set to !important

      if (config.localize == true || config.localize == "true") {
        config.localize = true;
      }

      /**
       * Short hand to create urls.
       *
       * ex.
       * console.log(url('http://www.google.com/', {q: 'shareaholic',z: 'something'}))
       * > http://www.google.com/?s=shareaholic&z=something
       */
      var url = function(path, params) {
        return [path, $.param(params)].join('?');
      };

      /**
       * Algorithm for finding unique items in an array.
       * Taken from http://www.shamasis.net/2009/09/fast-algorithm-to-find-unique-items-in-javascript-array/
       * Thanks Shamasis Bhattacharya
       */
      var unique = function(arr) {
        var a = [], l = arr.length;
        for(var i=0; i<l; i++) {
          for(var j=i+1; j<l; j++)
            if (arr[i] === arr[j]) j = ++i;
          a.push(arr[i]);
        }
        return a;
      };

      /**
       * Create custom link
       *
       * @place (before|after)
       * @i position
       * @config plugin config
       * @parent the parent <ul>
       */
      var get_custom_link = function(place, i, config) {
        var titleAttrib = config.designer_toolTips ? "orig_title" : "title";
        var clink = config.custom_link[place+'_'+i];
        SHR4P.debug('adding link '+place+' '+i);
        return (
          $('<li/>').addClass(clink.li_class).append(
            $('<a/>').attr({
              href: clink.link,
              rel: config.rel,
              target: config.target,
              'class': 'external'
            }).attr(titleAttrib,clink.tooltip).text(clink.tooltip)
          ).attr('style', clink.style+';margin-left:'+config.li_margin+'px !important;')
        );
      }

      /**
       * Creates a short_link
       *
       * @config plugin config
       */
      var get_short_link = function(config, callback) {
        config.shortener_services[config.shortener](config, callback);
      }

      /**
       * Generate sprite png URL.  If not localized, we'll using CDN friendly
       * grouping.
       */
      var sprite_url = function(config) {
        if (config.spriteimg != '')  {
          return config.spriteimg;
        } else if (config.localize) {
          return config.src+'/sprite.png';
        } else {
          var numSort = function(a,b){return a-b};
          var services = unique(config.service.split(',')).sort(numSort);
          SHR4P.debug('checking services: ');
          SHR4P.debug(services);
          var req_services = [];

          $(SHR4P.img_group).each(function() {
            var img_group = this;
            SHR4P.debug('checking img_group: ');
            SHR4P.debug(img_group);
            $(services).each(function() {
              SHR4P.debug('checking service: '+this);
              if ($.inArray(Number(this), img_group) > -1) {
                SHR4P.debug('found! adding img_group');
                $.merge(req_services, img_group);
                return false;
              }
            });
            SHR4P.debug('req_services so far: ');
            SHR4P.debug(req_services);
          });

          SHR4P.debug('final req_services: ');
          req_services = req_services.sort(numSort);
          SHR4P.debug(req_services.join(','));

          return url(
            config.src+config.api.sprite.url,
            {
              v: config.api.sprite.v,
              apikey: config.apikey,
              apitype: 'png',
              service: req_services.join(',')
            }
          );
        }
      }

      if (config.localize) {
        var sprite_css = config.src+'/sprite.css';
      } else {
        var sprite_css = url(
          config.src+config.api.sprite.url,
          {
            v: config.api.sprite.v,
            apikey: config.apikey,
            service: unique(config.service.split(',')).sort().join(',')
          }
        )
      }

      /**
       * Adds css
       */
      if ($('#shareaholic-publisher-css').length == 0) {
        $('head').append(
          $('<link rel="stylesheet" media="screen" '+
            'id="shareaholic-publisher-css" href="'+sprite_css+'"/>')
        );
      }

      var bookmarks_div = (
        $('<div/>').addClass('shr-bookmarks').append(
          $('<ul/>').addClass('shr-socials')
        )
      );
	  if(config.shrlink) {
		  var sBrowser = $.getBrowser();
		  if(sBrowser != '') {
			bookmarks_div.append(
				$('<div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div>')
			);
			bookmarks_div.find('.shr-getshr a').text('Get Shareaholic for ' + sBrowser);
			$(this).hover(function() {
				bookmarks_div.find('.shr-getshr').css('visibility','visible');
			}, function () {
				bookmarks_div.find('.shr-getshr').css('visibility','hidden');
			});
		  }
	  }
      if (config.bgimg != 'undefined' && config.bgimg != '') {
        bookmarks_div.addClass('shr-bookmarks-bg-shr').css({
          'margin-left': '10px',
          height: '100%',
          'overflow-x': 'hidden',
          'overflow-y': 'hidden',
          display: 'block',
          padding: config.bgimg_padding,
          'background': 'transparent url('+config.bgimg+') no-repeat'
        });
      }

      var socials_ul = bookmarks_div.find('.shr-socials');

      if(config.fbLikeButton) {
          setTimeout("SHR4P.fbUtil.addFBConnect()",0);
          var shrLikeBtnCotainer = $('<div class="shareaholic-like-buttons"><br/></div>');
          var fbCotainer = $('<a class="shareaholic-fb-like" style="margin-top:5px; margin-bottom:5px;"></a>');

          SHR4P.fbUtil.addLikeButton(fbCotainer,config.link);
          shrLikeBtnCotainer.prepend(fbCotainer);

          if(config.fbButtonPos.indexOf("bottom") != -1) {
            shrLikeBtnCotainer.insertAfter(this);
          } else {
            shrLikeBtnCotainer.insertBefore(this);
          }

          if(config.fbButtonPos.indexOf("right") != -1) {
            fbCotainer.css("float","right");
          }
      }

      $(config.service.split(',')).each(function(i,v) {
        var template = '';
        // TODO: come up with a generic way to override config for a single
        // service.  This would also be useful for Yahoo! Buzz categories+tags
        // and Twittley categories.
        //
        // 7 = twitter
        if (v == '7') {
          template = config.twitter_template;
        }
        // Allow custom links that aren't supported by shareaholic
        if (config.custom_link['before_'+i]) {
          get_custom_link('before', i, config).appendTo(socials_ul);
        }
        var titleAttrib = config.designer_toolTips ? "orig_title" : "title";
        var browserLocale = SHR4P.utils.getBrowserLocale();

        browserLocale = browserLocale.split("-")[0];
        if(typeof(SHR4P.locales) !== "undefined"   && (typeof(SHR4P.locales[browserLocale]) == "undefined" || !SHR4P.locales[browserLocale])) {
            browserLocale = 'en';
        }
        if(typeof(SHR4P.locales) !== "undefined"){
            var tipText = SHR4P.locales[browserLocale][SHR4P.tooltips_prefix_map[v]] + ' ' + SHR4P.tooltips_suffix[v]/*SHR4P.tooltips[v]*/;
        }else{
            var tipText = "";
        }
        
        //Adding social action render
        SHR4P.ga.socialAction({serviceId:v, serviceAction:'render', link:config.link})
        
        var liObj =$('<li/>');
        liObj.addClass('shr-'+v).addClass('shareaholic').attr('style', 'margin-left:'+config.li_margin+'px !important;')
        .bind("click", {serviceId:v, serviceAction:'share', link:config.link} ,SHR4P.ga.trackAction)
        
        var o = {
          title: config.title,
          link: config.link,
          notes: config.notes,
          short_link: config.short_link,
          shortener: config.shortener,
          shortener_key : config.shortener_key,
          v: config.api.share.v,
          apitype: config.api.share.apitype,
          apikey: config.apikey,
          source: config.api.share.source,
          template: template,
          service: v,
          //tags: config.tags,
          ctype: config.ctype
        }
        
         if (v == '7' && config.twitter_overlay && !SHR4P.utils.isMobileBrowser()) {
          (
            liObj.append(
              $('<a/>').attr({
                rel: config.rel,
                target: config.target,
                'class': 'external'
              }).attr(titleAttrib,tipText).text(tipText).click(function(e) {
                    SHR4P.utils.showServiceLet(config,"twitter");
                    e.preventDefault();
              })
            )
          ).appendTo(socials_ul);
        } else {
          (
            liObj.append(
              $('<a/>').attr({
                href: url(config.share_src+config.api.share.url, o),
                rel: config.rel,
                target: config.target,
                'class': 'external'
              }).attr(titleAttrib,tipText).text(tipText)
            )
          ).appendTo(socials_ul);
        }
        
        if(v == '309' || v == '304'){
            liObj.click(function(e) {
                    SHR4P.utils.runBookmarklet(o);
                    e.preventDefault();
              })
        }

		if(!config.dontShowShareCount &&
				(v == 5 || v== 7 || v == 2)) {// get the sharecount and lay it out in case of fb/twitter
			var dispCount = function (obj) {
                var count = obj.count;
				if(count >0 || ( count != '0' && count !=  0)) {
					var cntDiv = $('<div/>').addClass('shr-count').appendTo(socials_ul.find('.shr-'+v));
					for(var i=0; i<9; i+=1) {
						if(i!=4) {
							cntDiv.append(
								$('<div>'+count+'</div>').addClass('shr-count-outline').css({
                                    left: (10 + (i%3)-1) + 'px',
                                    top: '-' + (11 + parseInt(i/3) -1) + 'px'
                                })
                                .attr("aria-hidden", "true") // for screen reader accessibilty
							);
						}
					}
					cntDiv.append(
						$('<div>'+count+'</div>').addClass('shr-count-center').css({
                            left: '10px',
                            top: '-11px'
                        })
                        .attr("aria-label","Number of times this webpage has been shared")
					);
				}
			};
			if(v == 5) { //facebook
				SHR4P.utils.getFbShrCnt(config.link, dispCount);
			} else if(v == 7) { //twitter
				SHR4P.utils.getTwitShrCnt(config.link, dispCount);
			} else if(v== 2) { // Delicious
                SHR4P.utils.getDeliciousShrCnt(config.link, dispCount);
            } 
		}
        // Allow custom links that aren't supported by shareaholic
        if (config.custom_link['after_'+i]) {
          get_custom_link('after', i, config).appendTo(socials_ul);
        }
      });

      var show_hide_tooltips = (function (obj) {
            var toolTipContainer = $("<div style='position:absolute !important; background: transparent !important; z-index:101 !important;'/>");
            var toolTipTextDiv = $("<div class = 'shareaholic-tip-text'></div>");
            var toolTipArrow = $("<div class = 'shareaholic-arrow-down'/>");
            toolTipContainer.append(toolTipTextDiv);
            toolTipContainer.append(toolTipArrow);

            return {
                show : function(obj) {
                    if($("body").find('.shareaholic-tip-text').length) {
                       return;
                    }
                    var anchor = $(obj).find("a");
                    var toolTipText = anchor.attr("orig_title");
                    toolTipTextDiv.text(toolTipText);
                    var coOrds = $(obj).offset();
                    toolTipContainer.appendTo(document.body);
                    var myWidth = toolTipContainer.width();
                    var objWidth = $(obj).width();
                    var left = (coOrds.left - myWidth/2 + objWidth/2);
                    toolTipContainer.css({
                                    left:left,
                                    top:(coOrds.top - 32)
                    });
                    toolTipContainer.css({opacity:0.9});
                },
                hide : function (obj) {
                    toolTipContainer.remove();
                }
            };
        })();

        if(config.designer_toolTips) {
            $("<style type='text/css'>.shareaholic-arrow-down{ position: absolute !important; left:45% !important; width: 0 !important; height: 0 !important; border-left: 6px solid transparent !important; border-right: 6px solid transparent !important; border-top: 6px solid " + config.tip_bg_color+ " !important; }.shareaholic-tip-text{font-size:12px !important; line-height:120% !important; background: " + config.tip_bg_color + " !important; color: "+ config.tip_text_color + " !important; padding: 5px !important; border-radius: 5px !important; -webkit-border-radius:5px; !important; -moz-border-radius:5px; !important}</style>").appendTo("head");


            socials_ul.find('li').mouseenter(function(a) {
                                       show_hide_tooltips.show(a.currentTarget);
                                }).mouseleave(function(a) {
                                        show_hide_tooltips.hide(a.currentTarget);
                                });
        }

      var modify_links = function (tags) {
            $(socials_ul).find("li a").each( function () {
                this.href = this.href + "&tags=" + tags;
            });
      };

      if(config.allowExternalTags) {
            SHR4P.utils.getTags(config.link, config.tags, modify_links);
      } else {
            modify_links(config.tags);
      }

      var pngurl = sprite_url(config);
      bookmarks_div.append(
        $('<style type="text/css">ul.shr-socials li.shareaholic{background-image:url('+pngurl+') !important;}</style>')
      );
      bookmarks_div.appendTo(this);
      return this;
    };

	$.extend({
		getBrowser : function() {
			var sUA = navigator.userAgent;
			var sName = "";
			if(sUA.indexOf("MSIE") != -1 ) {
				sName = "Internet Explorer";
			} else if(sUA.indexOf("Firefox") != -1 ) {
				sName = "Firefox";
			} else if(sUA.indexOf("Flock") != -1 ) {
				sName = "Flock";
			} else if(sUA.indexOf("Chrome") != -1 ) {
				sName = "Google Chrome";
			} else if(sUA.indexOf("Safari") != -1 ) {
				sName = "Safari";
			} else if(sUA.indexOf("Opera") != -1 ) {
				sName = "Opera";
			} else if(sUA.indexOf("Songbird") != -1 ) {
				sName = "Songbird";
			}
			return sName;
		}
	});
  })(SHR4P.jQuery);
  SHR4P.ready = true;
  if (typeof(SHR4P.onready) != 'undefined') {
    SHR4P.onready();
  }
}

if (typeof(SHR4P) == 'undefined') {
  SHR4P = {};
}
SHR4P.ready = false;
SHR4P.init = false;

// TODO: memoize
SHR4P.params = function() {
  var params = {};
  var href_parts = document.location.href.split('?');
  if (href_parts.length == 2) {
    var query = href_parts[1];
    var query_parts = query.split('&');
    for (var i = 0; i < query_parts.length; i++) {
      var param_parts = query_parts[i].split('=');
      if (param_parts.length == 2) {
        params[unescape(param_parts[0])] = unescape(param_parts[1]);
      }
    };
  }
  return params;
}

SHR4P.debug = function(str) {
  if (SHR['debug_enabled']) {
    if (typeof(console) != 'undefined' && console) {
      console.log(str);
    } else {
      alert(str);
    }
  }
}


SHR4P.load = function() {

    //Loading scripts for tracking
    setTimeout("SHR4P.dough()",0);
    setTimeout("SHR4P.prefetch()",0);
    
    // Always load jQuery to ensure we are working with the version we want to.
    if(typeof(jQuery)!="undefined" && jQuery) {
        // jQuery is already present in the page.. Check if version number requirements are met
        var pageVersion = jQuery().jquery;
        if(SHRSB_Globals.minJQueryVersion <= pageVersion) {
            window["sb_dont_noConflict"] = true;
            SHR4P_init();
            return;
        }
    }

    SHR4P.debug('loading jquery');
    var head = document.getElementsByTagName('head')[0];
    if (typeof(head) != 'undefined') {
      var params = SHR4P.params();
      var jq_script = document.createElement('script');
      if (SHR['debug_enabled']) {
        jq_script.src = "//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js";
      } else {
        jq_script.src = "//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js";
      }
      jq_script.type = "text/javascript";
      head.appendChild(jq_script);
      jq_script.onreadystatechange = function() {
        if (this.readyState == 'complete' || this.readyState == 'loaded') {
          SHR4P.debug('jQuery loaded with onreadystatechange, init\'ing');
          SHR4P_init();
        }
      };
      jq_script.onload = SHR4P_init;
    }
};

SHR4P.onready = function () {
  if (/(loaded|complete)/.test(document.readyState)) {
      SHR4P.readyHandler();
    } else {
      SHR4P.jQuery(document).ready(function(){
        SHR4P.readyHandler();
      });
    }
};




SHR4P.readyHandler = function() {
    SHR4P.utils.init(SHR4P.jQuery);

    SHR4P.jQuery.each(SHRSB_Settings, function(k) {
	    // we need this silly hack because if we set it to
	    // false in public.php, wordpress won't send it here
	    // and we need to override the default true value of
	    // expand
	    if (this['expand'] == 'false') {
	      this['expand'] = false;
	    }
	    SHR4P.jQuery('.'+k).shareaholic_publishers(this);
  });
  SHR4P.renderLikeButtons();
};


// Grouping of images for CDN.  If you request one of the services in the
// group, you get them all.
// Making less groups gives better CDN, but worse performance.  Making more
// groups gives better browser performance but worse CDN performance.
// I've tried to order the services by popularity to ensure as few gruops as
// possible are requested. The numbers in each group are sorted to speed up searching.
SHR4P.img_group = [];
SHR4P.img_group[0] = [2, 3, 4, 5, 6, 7, 10, 24, 38, 39, 40, 52, 54, 74, 88, 201, 219, 257];
SHR4P.img_group[1] = [27, 33, 41, 43, 45, 46, 53, 73, 78, 195, 196, 205, 207, 210, 236, 247, 264];
SHR4P.img_group[2] = [44, 48, 61, 80, 100, 105, 140, 191, 202, 218, 238, 240, 266, 269, 280, 289];
SHR4P.img_group[3] = [1, 14, 21, 89, 98, 102, 106, 243, 267, 268, 277, 278, 283, 284, 285, 286, 288];
SHR4P.img_group[4] = [20, 59, 92, 188, 190, 192, 204, 246, 263, 265, 279, 281, 282, 287, 290, 291, 292, 293, 294];

// Services that require short_links
SHR4P.wants_shortlink = [7];
SHR4P.utils = (function(w,d){
    
    var $;
    
    var apiKey = '0747414f47c2b684cf5480c36b2478689' // Generic Publisher
    
    // Share API Defaults
    var defaults = {
      v: 1
      , apikey: apiKey // TODO: Right Key
      , apitype: 1
      , title: ''       // TODO: Update these
      , link: ''        // TODO: Update these
      , short_link: ''
      , shortener: 'google'
      , shortener_key : ''
      , template: '${title} - ${short_link}'
      , service: false              // Required
      , source: 'Shareaholic-Publishers'
      , tags: ''
      , ctype: ''
      , notes: ''
    };
    
    /**
     * Short hand to create urls.
     *
     * ex.
     * console.log(url('http://www.google.com/', {q: 'shareaholic',z: 'something'}))
     * > http://www.google.com/?s=shareaholic&z=something
     */
    function url(path, params) {
        return [path, $.param(params)].join('?');
    }
    
    /*
     * Used to dynamic execute/append script tag to the page
     * src: <url>
     *  source of the script tag
     * id: <string>
     *  id of the script tag
     * cache: true | false, 
     *  Fetch the latest script from server or not
     * aync: true  | false
     *  mode is async or not 
     */
    function appendScript(o){
        
        if(!o.src){
            throw 'Invalid source';
        }
        
        var defaults = {
            async: true
            , cache: false
            , src: false
            , id: ''
        };

        o = $.extend({}, defaults, o);
        
        // Append the random string to always fetch the latest code 
        if(!o.cache){
            o.r = Math.floor(Math.random()*9999999999);
            o.src += '&_='+o.r;
            o.id += o.r;
        }
        
        // Creating the new script tag to append
        var s = d.createElement('script');
        s.setAttribute('language','javascript');
        s.id = o.id;
        s.async = o.async;
        s.setAttribute('src', o.src);
        d.body.appendChild(s);
        
        // Return the script parameters
        return o;
    }
    
    function init(o){
        $ = o;
    }
    
    function runBookmarklet(o) {

        if(typeof(o.service) == "undefined" || !o.service) {
            return;
        }
        o.apitype =  4;

        var u = SHR4P.base_url + '/api/share';
        var params = $.extend({}, defaults, o);
        
        appendScript({
            src: url(u, params)
            , cache: false
            , id: o.service + '_shareaholic_'
        });
    }

    return {
        init : init,
        url : url,
        appendScript: appendScript,
        runBookmarklet : runBookmarklet,
        
        getFbShrCnt : function (url,handler) {
            url = "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&format=json&urls="
                    + encodeURIComponent(url);
            SHR4P.jQuery.getJSON(url+'&callback=?',function (obj) {
                var count = 0;
                if(obj.length > 0) {
                    count = obj[0].total_count;
                    if (count != 0) {
                        if (count > 1000) {
                            count = Math.floor(count/1000) + 'K';
                        }
                    }
                }

                handler({count:count});
            });
        },

        getTwitShrCnt : function (url,handler) {
            url = "https://cdn.api.twitter.com/1/urls/count.json?url="
                    + encodeURIComponent(url);
            SHR4P.jQuery.getJSON(url+'&callback=?',function (obj) {
                    var count = obj.count;
                    if (count != 0) {
                        if (count > 1000) {
                            count = Math.floor(count/1000) + 'K';
                        }
                    }
                    handler({count:count});
                });
        },

        getDeliciousShrCnt : function (url,handler) {
            url = "http://feeds.delicious.com/v2/json/urlinfo/data?url="
                    + encodeURIComponent(url);

            SHR4P.jQuery.getJSON(url+'&callback=?',function (obj) {
                    var count = 0;
                    //var del_tags = '';
                    if(obj.length > 0) {
                        count = obj[0].total_posts;
                        if (count != 0) {
                            if (count > 1000) {
                                count = Math.floor(count/1000) + 'K';
                            }
                        }
                        //del_tags = obj[0].top_tags;
                        // ToDo: Some processing for formatting the tag as we need it.
                    }
                    handler({count:count});//, del_tags:del_tags});

                });
        },

        getTags : function (url, origTags, callback) {

            var pending_requests = 1;
            // Total number of services from which we may request the

            // Pending: Add locks for collisions when multiple services are there
            var update_tags = function(newTags) {
                origTags += newTags;
                if(--pending_requests == 0) {
                    callback(origTags);
                }
            };

            SHR4P.utils.getDeliciousTag(url,update_tags);

        },

        getDeliciousTag : function (url,handler) {
            url = "http://feeds.delicious.com/v2/json/urlinfo/data?url="
                    + encodeURIComponent(url);

            SHR4P.jQuery.getJSON(url+'&callback=?',function (obj) {
                if(obj.length > 0) {
                    top_tags = obj[0].top_tags;
                    del_tags = "";
                    // ToDo: Some processing for formatting the tag as we need it.
                    SHR4P.jQuery.each(top_tags, function(index, value) {
                          del_tags += encodeURIComponent(index) + "|" + value + "|" + "delicious,";
                        });
                    if(del_tags != "") {
                        // get rid of the extra comma
                        del_tags = del_tags.substr(0,del_tags.length - 1);
                    }
                    handler(del_tags);
                }

            });
        },
        showServiceLet : function(params,service) {
            if(typeof(service) == "undefined" || !service) {
                return;
            }

            if(typeof(SHR_config) == "undefined" || !SHR_config) {
                window["SHR_config"] = {};
            }

            w["__shr_service"] = service;
            w["__shr_log"] = true; // changing to bool. however 'true' is treated as true too.
            w["__shr_center"] = true;


            SHR_config['shortener'] = params.shortener ? params.shortener : "google",
            SHR_config['shortener_key'] = params.shortener_key ? params.shortener_key : "",
            SHR_config['apikey'] = params.apikey ? params.apikey : "0747414f47c2b684cf5480c36b2478689", // Generic Publisher Key
            SHR_config['twitter_template'] = params.twitter_template ? params.twitter_template:'${title} - ${short_link}',
            SHR_config["link"] = params.link ? params.link : d.location.href;
            SHR_config["title"] = params.title ? params.title : (params.link ? "" : d.title);
            SHR_config["short_link"] = params.short_link ? params.short_link : "" ;

            if(w.SHR && w.SHR.Servicelet) {
                SHR.Servicelet.show();
            } else{
                appendScript({
                    src: (params.share_src ? params.share_src : SHR4P.cdn_url ) + '/media/js/servicelet.min.js'
                    , cache: true
                    , id: 'shr-servicelet'
                })
            }
        },
        isMobileBrowser : function () {
                var searchStr = navigator.userAgent||navigator.vendor||window.opera;
                var isMobile = /android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(searchStr)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(searchStr.substr(0,4));
                return isMobile;
        },
        getBrowserLocale : function () {
            var locale = "en-us";
            if ( navigator ) {
                if ( navigator.language ) {
                    locale = navigator.language;
                }
                else if ( navigator.browserLanguage ) {
                    locale = navigator.browserLanguage;
                }
                else if ( navigator.systemLanguage ) {
                    locale = navigator.systemLanguage;
                }
                else if ( navigator.userLanguage ) {
                    locale = navigator.userLanguage;
                }
            }
            return locale.toLowerCase();
        },
        trackAction : function (o) {

             // This function is used currently by like button set only. Therefore the default tracking key is for likebutton set. 
             // Provide the apikey if its called from other than likebuttonset
             var apiKey = o.apikey || "73868baef9de9b15b8cff648e686124de"; // LikebuttonSet Key
            SHR4P.jQuery('<img/>').attr({
                src : ("//www.shareaholic.com/api/share/?v=1&apikey="+apiKey+"&apitype=3&service="+o.serviceId+"&link=" + encodeURIComponent(o.href) + (o.title !== "" ? "&title="+o.title :"" ) ),
                width  : "1",
                height : "1"
            }).appendTo("body");
        }
    }
})(window, document);

SHR4P.ga = (function () {
    
    var initStatus = false;
    
    //Publisher settings
    var pubGaKey;
    var pubGaSocial = true;
    var trackingPrefix = "Shareaholic_";
    var trackActions = {
          render : false
        , like : true
        , unlike : true
        , send : true
        , share : true
        , unknown : false
    }
    
    //For Avoiding conflicts related to multiple ga accounts on the page
    var pubGaPrefix = '';
    
    function logSharingAction (data){
        
        !initStatus && init();
        if(!pubGaSocial) return false;
        
        var serviceId = data.serviceId
        var serviceAction = data.serviceAction || "unknown";
        var track = typeof (trackActions[serviceAction]) !== "undefined" ? trackActions[serviceAction] : true;
        var link = data.link;
        var serviceInfo = trackingPrefix + (SHR4P.tooltips_suffix[serviceId] || "");
        serviceInfo = serviceInfo.replace(/(\s|\r\n|\n|\r)/gm,"_");
        serviceAction = serviceAction.charAt(0).toUpperCase() + serviceAction.slice(1);
        
        track && _gaq.push(
            [pubGaPrefix+'_trackSocial', serviceInfo, serviceAction, link]
        );
        return track;
    };
    
    function initScript(){
        if(typeof(SHRSB_Globals) != 'undefined' && SHRSB_Globals['perfoption'] == '1' ) {

            (function() {
              var ga = document.createElement('script');ga.type = 'text/javascript';ga.async = true;
              ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
              var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga, s);
            })();
        }
    };
    function init(){

        if(typeof(_gaq) == "undefined" || !_gaq) {
            window["_gaq"] = [];
        }
            
        //Initializing the shareaholic Account
        _gaq.push(
              ['shr._setAccount', 'UA-12964573-5']
            , ['shr._trackPageview']
         );
        
        //Initializing the publisher Account
        if(typeof(SHRSB_Globals) !== 'undefined') {
            
            //Check for public key
            pubGaKey = SHRSB_Globals.pubGaKey || false;
            //execute everything in new space so as to avoid and conflicts
            if(pubGaKey){
                pubGaPrefix = 'shrpub.'
            }
            
            //Check social tracking enabled or not
            pubGaSocial = typeof (SHRSB_Globals.pubGaSocial) !== "undefined" ? SHRSB_Globals.pubGaSocial : pubGaSocial;
            
            if(pubGaKey && pubGaSocial){
                _gaq.push(
                      [pubGaPrefix+'_setAccount', pubGaKey]
                );
            }
        }
        //Updating the intit status
        initStatus = true;

        //Initializing the script in Async mode
        initScript();
    };
    
    return {
        init : init,
        socialAction : logSharingAction,
        trackAction : function(e){
            logSharingAction(e.data);
        }
    }
})();
SHR4P.dough = function () {
    if(typeof(SHRSB_Globals) != 'undefined' && SHRSB_Globals['perfoption'] == '1' ) {

        (function() {
            var dgh = document.createElement('script');
            dgh.type = 'text/javascript';
            dgh.async = true;
            dgh.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'dtym7iokkjlif.cloudfront.net/dough/1.0/recipe.js';
            var s = document.getElementsByTagName('script')[0]; 
            s.parentNode.insertBefore(dgh, s);
        })();
    }
};

SHR4P.prefetch = function () {
    if(typeof(SHRSB_Globals) != 'undefined' && typeof(SHRSB_Globals['src']) != 'undefined' ) {
        var spriteImg = new Image();
        spriteImg.src = SHRSB_Globals['src'] + "/sprite.png";
    }
};

SHR4P.renderLikeButtons = function () {
    if(SHR4P.jQuery('.shareaholic-fblike,.shareaholic-fbsend','.shareaholic-like-buttonset').length > 0) {
        setTimeout("SHR4P.fbUtil.addFBConnect()",0);
    }
    if(SHR4P.jQuery('.shareaholic-googleplusone','.shareaholic-like-buttonset').length > 0) {
        setTimeout("SHR4P.googPlusOneUtil.addGoogScript()",0);
    }
    if(SHR4P.jQuery('.shareaholic-tweetbutton','.shareaholic-like-buttonset').length > 0) {
        setTimeout("SHR4P.twitterUtil.addTwitterScript()",0);
    }
};

SHR4P.googPlusOneUtil = {
    addGoogScript: function(){
        if(SHR4P.jQuery("#googplusonescript").length == 0) {
            var e = document.createElement('script');e.async = true;
            e.src = "https://apis.google.com/js/plusone.js";
            e.id = "googplusonescript";
            e.text = '{"parsetags": "explicit"}';

            document.getElementsByTagName("head")[0].appendChild(e);


            e.onreadystatechange = function() {
                if (this.readyState == 'complete' || this.readyState == 'loaded') {
                  SHR4P.googPlusOneUtil.renderPlusOnes();
                }
            };
            e.onload = SHR4P.googPlusOneUtil.renderPlusOnes;
        }
    },
    renderPlusOnes: function () {
        SHR4P.jQuery('.shareaholic-googleplusone','.shareaholic-like-buttonset').each(function() {
            var jThis = SHR4P.jQuery(this);

            var alreadyProcessed = jThis.attr('data-shr_status') || false;
            if(alreadyProcessed == "1" ) return;
            
            //Get value from html
            var targ = jThis.attr('data-shr_href') || jThis.attr('shr_href');
            var title = jThis.attr('data-shr_title') || jThis.attr('shr_title');
            var size = jThis.attr('data-shr_size') || jThis.attr('shr_size');
			var count = jThis.attr('data-shr_count') || jThis.attr('shr_count');
            
            //New Api parameters
            var annotation = jThis.attr('data-shr_annotation');
            var width = jThis.attr('data-shr_width');
            var expandto = jThis.attr('data-shr_expandto');
            var onstartinteraction = jThis.attr('data-shr_onstartinteraction');
            var onendinteraction = jThis.attr('data-shr_onendinteraction');

            
            //Depriciated by google plusone api
            //For Count
            if(typeof(count) == "undefined" || !count) {
                count = "true";
            }
            
            //For Title and href
            if((typeof(targ) == "undefined" || !targ) && (typeof(title) == "undefined" || !title )){
                targ = encodeURIComponent(document.location.href);
                title = document.title;
            }else{
                if(typeof(targ) == "undefined" || !targ) {
                    targ = encodeURIComponent(document.location.href);
                }

                if(typeof(title) == "undefined" || !title) {
                    title = "";
                }
            }

            //For the size
            if(typeof(size) == "undefined" || !size) {
                size = "standard";
            }
            
            //For annotation - none, bubble, inline
            if(typeof(annotation) == "undefined" || !annotation) {
                annotation = "inline";
                if(typeof(count) !== "undefined" && (count &&  count !== "false")){
                    annotation = "inline";
                }else{
                    annotation = "none";
                }
            }
            
            //For width
            if((typeof(width) == "undefined" || !width)){
                 width = "450px";
            }

            //For expandto
            if((typeof(expandto) == "undefined" || !expandto)){
                 expandto = "";
            }

            //For onstartinteraction
            if((typeof(onstartinteraction) == "undefined" || !onstartinteraction)){
                 onstartinteraction = "";
            }

            //For onendinteraction
            if((typeof(onendinteraction) == "undefined" || !onendinteraction)){
                 onendinteraction = "";
            }
            
            //For padding - not related to googleplus api
            var padding = "";
            if(size == 'medium') {
                padding = 'padding-top:1px !important;';
            }
            
            //Adding the status field
            jThis.attr("data-shr_status","1");

            //For container in which we render google plus
            var container = SHR4P.jQuery("<div style='float:left; "+ padding +" margin:0px 0px 0px 10px !important;'/>").get(0);
            jThis.replaceWith(container);
            SHR4P.jQuery(container).append("<div/>");
            container = SHR4P.jQuery(container).find(':first-child').get(0);

            //Calling plusone api
            gapi.plusone.render(
                container,
                {
                    "size": size,
                    "annotation": annotation, 
                    "width":width, 
                    "expandto": expandto, 
                    "onstartinteraction":onstartinteraction, 
                    "onendinteraction":onendinteraction, 
                    "href":decodeURIComponent(targ), 
                    "callback" :function(obj){
                        SHR4P.googPlusOneUtil.trackPlusOneClick(obj,title) 
                    }
                }
            );
            SHR4P.ga.socialAction({serviceId:304, serviceAction:'render', link:targ});
        });
        
    },
    //tracking function, registered as a callback in plusone api
    trackPlusOneClick: function (obj, title) {
        
        if(obj.state == "on") {
            SHR4P.utils.trackAction({
                serviceId : 304
                , href : obj.href
                , title : title
            })
            SHR4P.ga.socialAction({serviceId:304, serviceAction:'like', link:obj.href});
        }else{
            SHR4P.ga.socialAction({serviceId:304, serviceAction:'unlike', link:obj.href})
        }
    }
};

SHR4P.twitterUtil = {
    addTwitterScript: function(){
//        if(SHR4P.jQuery("#tweetbuttonscript").length == 0) {
//            var e = document.createElement('script');e.async = true;
//            e.src = "//platform.twitter.com/widgets.js";
//            e.id = "tweetbuttonscript";
////            e.text = '{"parsetags": "explicit"}';
//
//            document.getElementsByTagName("head")[0].appendChild(e);
//
//
//            e.onreadystatechange = function() {
//                if (this.readyState == 'complete' || this.readyState == 'loaded') {
//                  SHR4P.twitterUtil.renderTweetButton();
//                }
//            };
//            e.onload = SHR4P.twitterUtil.renderTweetButton();
//        }
//        var jThis = SHR4P.jQuery(this);
//        SHR4P.jQuery.getScript("//platform.twitter.com/widgets.js", function(){
//           twttr.events.bind('tweet', SHR4P.twitterUtil.trackTweetButtonClick);
//         });
//         SHR4P.twitterUtil.renderTweetButton();
         SHR4P.twitterUtil.renderShareaholicTweetButton();
    },
        renderShareaholicTweetButton: function(){
        SHR4P.jQuery('.shareaholic-tweetbutton','.shareaholic-like-buttonset').each(function() {

            var $ = SHR4P.jQuery;
            var  jThis = $(this);
                
            var alreadyProcessed = jThis.attr('data-shr_status') || false;
            if(alreadyProcessed == "1" ) return;
                
           var url = function(path, params) {
                    return [path, $.param(params)].join('?');
                },
                service = 7, // Twitter
            
            //Get value from html
                targ = jThis.attr('data-shr_href') || jThis.attr('shr_href'),
                title = jThis.attr('data-shr_title') || jThis.attr('shr_title'),
                size = jThis.attr('data-shr_size') || jThis.attr('shr_size'),
                count = jThis.attr('data-shr_count') || jThis.attr('shr_count'),
                lang = jThis.attr('data-shr_lang'),
            
            //Code to provide the different UI for the share buttons
                className = "shr-" + service,
                genericClassName = "shr-generic",
                show_count = true,
                is_compact = true;

            SHR4P.debug(jThis);
            
            //For Count
            if(typeof(count) == "undefined" || !count) {
                count = "horizontal";                
            }
            
            //For Title and href
            if((typeof(targ) == "undefined" || !targ) && (typeof(title) == "undefined" || !title )){
                targ = encodeURIComponent(document.location.href);
                title = document.title;
            }else{
                if(typeof(targ) == "undefined" || !targ) {
                    targ = encodeURIComponent(document.location.href);
                }

                if(typeof(title) == "undefined" || !title) {
                    title = "";
                }
            }

            //For the size
            if(typeof(size) == "undefined" || !size) {
                size = "standard";
            }
            
            //For padding - not related to tweet button api
            var padding = "";
            if(size == 'medium') {
                padding = 'padding-top:1px !important;';
            }
            
            if(typeof(lang) == "undefined" || !lang) {
                lang = "en";
            }
            switch(count){
                case "horizontal":
                    show_count = true;
                    is_compact = true;
                    break;
                case "vertical":
                    show_count = true;
                    is_compact = false;
                    break;
                case "none" :
                    show_count = false;
                    is_compact = false;
                    break;
            }
            if(show_count) {
                className += "-count";
                genericClassName += "-count";
            }
            if(show_count && is_compact ) {
                className += "-compact";
                genericClassName += "-compact";
            }
            
            if(show_count) {
                var countDiv = this;

                if(is_compact){
                    this.style.marginRight = "0px";

                    var tickDiv = document.createElement("div");

                    countDiv = document.createElement("div");
                    var parNode = this.parentNode;
                    parNode.appendChild(countDiv);
                    countDiv.className = "shr_compact_div";
                    tickDiv.className = "shr_compact_tick";
                    tickDiv.appendChild(document.createElement("s"));
                    tickDiv.appendChild(document.createElement("i"));
                    parNode.insertBefore(tickDiv,countDiv);
                }
                var dispCount = function (obj) {
                    countDiv.innerHTML = obj.count;
                };

                if(show_count && service == 7) { //twitter
                    SHR4P.utils.getTwitShrCnt(targ, dispCount);
                }
            }
            
            var link = targ,
                short_link = "",
                params = {
                  title: title,
                  link: link,
                  short_link: short_link,
                  shortener: SHRSB_Globals.shortener ? SHRSB_Globals.shortener : "google",
                  shortener_key : SHRSB_Globals.shortener_key ? SHRSB_Globals.shortener_key : "",
                  v: 1,
                  apitype: 1,
                  apikey: SHR4P.shr_apiKey,
                  twitter_template: SHR4P.shr_twitter_template ? SHR4P.shr_twitter_template:'${title} - ${short_link}',
                  service: service
                },

                //Background Image for the style
                pngDiv = $(this),
                pngUrl = SHR4P.shr_image || SHR4P.shr_twitter_image,
                pngCss = SHR4P.shr_image ? ".shr-7-count{background-position:-57px -80px;}.shr-7-count-compact,.shr-7{height:14px;width:55px;background-position:-228px -79px;}.shr-7-count-compact:hover,.shr-7:hover{height:14px;width:55px;background-position:-228px -100px;}.shr-7-count-compact:active,.shr-7:active{height:14px;width:55px;background-position:-228px -121px;}" : ".shr-7-count{background-position:-57px -80px;}.shr-7-count-compact,.shr-7{height:14px;width:55px;background-position:0px 0px;}.shr-7-count-compact:hover,.shr-7:hover{height:14px;width:55px;background-position:0px -21px;}.shr-7-count-compact:active,.shr-7:active{height:14px;width:55px;background-position:0px -41px;}";
                
                // Adding the css to show the twitter counter
                pngCss += '.shr_compact_div{background:#EFEFEF;border:1px solid #C1C1C1;float:left;font-weight:normal;height:14px;margin-left:1px;min-width:15px;padding:1px 2px 1px 2px;text-align:center;font-size:11px;display:block;margin-top:2px;margin-right:15px;}.shr_compact_tick{float:left;position:relative;z-index:2;width:5px;top:5px;left:2px;border-collapse:separate;border-spacing:2px 2px;margin-top:2px;}.shr_compact_tick i{left:2px;top:-6px;border-right-color:#EFEFEF;font-style:italic;}.shr_compact_tick s{text-decoration:line-through;text-align:left;}.shr_compact_tick s,i{border:solid transparent;border-right-color:#C7C7C7;display:block;position:relative;border-width:5px 5px 0 0;}'
                
            pngDiv.before($('<style type="text/css"> div.shareaholic a{background-image:url('+pngUrl+') !important;}.shr-generic-count{height:53px;width:57px;font-weight:bold;font-size:14px;padding-top:7px;text-align:center;background:transparent no-repeat scroll;background-position:0px -80px;color:black;cursor:pointer;text-decoration:none;display:block;}.shr-generic-count-compact,.shr-generic{height:23px;width:63px;font-weight:bold;font-size:14px;padding-top:7px;text-align:center;background:transparent no-repeat scroll;background-position:0px -50px;color:black;cursor:pointer;text-decoration:none;display:block;} '+pngCss+'</style>'));
            //jThis.wrap('<div class="shr-'+service+' shareaholic "></div>');
            jThis.wrap('<div class="shr-'+service+' shareaholic" style="float:left; '+ padding +' margin:0px 0px 0px 10px !important;"></div>');
            //For container in which we render tweet button
//            var container = SHR4P.jQuery("<div style='float:left; "+ padding +" margin:0px 0px 0px 10px !important;'/>").get(0);
//            jThis.replaceWith(container);
//            SHR4P.jQuery(container).append("<div/>");
            
            jThis.parent().removeClass('shr-' + service);


            //Add the required classes
            jThis.addClass(genericClassName);
            jThis.addClass(className);
            SHR4P.debug(jThis);
            
            SHR4P.ga.socialAction({serviceId:7, serviceAction:'render', link:link})
                    
            if (!SHR4P.utils.isMobileBrowser()) {
                var service_name = "twitter";

                jThis.click(function(e) {
                    SHR4P.ga.socialAction({serviceId:7, serviceAction:'share', link:link})
                    SHR4P.utils.showServiceLet(params,service_name);
                    e.preventDefault();
                });
            }
            
            //Adding the status field
            jThis.attr("data-shr_status","1");
            
        });
    }
//    renderTweetButton: function () {
//        SHR4P.jQuery('.shareaholic-tweetbutton','.shareaholic-like-buttonset').each(function() {
//            var jThis = SHR4P.jQuery(this);
//
//            //Get value from html
//            var targ = jThis.attr('data-shr_href') || jThis.attr('shr_href');
//            var title = jThis.attr('data-shr_title') || jThis.attr('shr_title');
//            var size = jThis.attr('data-shr_size') || jThis.attr('shr_size');
//			var count = jThis.attr('data-shr_count') || jThis.attr('shr_count');
//            var lang = jThis.attr('data-shr_lang');
//            
//            //For Count
//            if(typeof(count) == "undefined" || !count) {
//                count = "horizontal";
//            }
//            
//            //For Title and href
//            if((typeof(targ) == "undefined" || !targ) && (typeof(title) == "undefined" || !title )){
//                targ = encodeURIComponent(document.location.href);
//                title = document.title;
//            }else{
//                if(typeof(targ) == "undefined" || !targ) {
//                    targ = encodeURIComponent(document.location.href);
//                }
//
//                if(typeof(title) == "undefined" || !title) {
//                    title = "";
//                }
//            }
//
//            //For the size
//            if(typeof(size) == "undefined" || !size) {
//                size = "standard";
//            }
//            
//            //For padding - not related to tweet button api
//            var padding = "";
//            if(size == 'medium') {
//                padding = 'padding-top:1px !important;';
//            }
//            
//            if(typeof(lang) == "undefined" || !lang) {
//                lang = "en";
//            }
//
//            //For container in which we render tweet button
//            var container = SHR4P.jQuery("<div style='float:left; "+ padding +" margin:0px 0px 0px 10px !important;'/>").get(0);
//            jThis.replaceWith(container);
//            SHR4P.jQuery(container).append("<div/>");
//            container = SHR4P.jQuery(container).find(':first-child').get(0);
//
//            SHR4P.jQuery('<a class="twitter-share-button" href="https://twitter.com/share"'
//                    + 'data-url="'+targ+'"'
//                    + 'data-via="Shareaholic"'
//                    + 'data-text="'+title+'"'
//                    + 'data-related="Shareaholic"'
//                    + 'data-count="'+count+'"'
//                    + 'data-lang="'+lang+'"'
//                    + 'data-counturl"'+targ+'"'
//                    + '>Tweet</a>').appendTo(container);
//            
//        });
//    },
    //tracking function, registered as a callback for tweet button
//    trackTweetButtonClick: function (event) {
//        if (event.type = "tweet") {
//            SHR4P.jQuery('<img/>').attr({
//                src : ( SHR4P.base_url + "/api/share/?v=1&apikey=172809fde4d12743cc4a1ec894142b97f&apitype=3&service=7&link=" + encodeURIComponent(event.target.baseURI) + (event.target.title !== "" ? "&title="+event.target.title :"" ) ),
//                width  : "1",
//                height : "1"
//            }).appendTo("body");
//        }
//    }
};


SHR4P.fbUtil = {
    fbConnectAdd : 0,
    renderFBWidgetCalled: false,
    likeButtonsToRender : [],
    // An array containing like button tags to parse that were formed before FB script was inserted

    /*renderFBWidgetHandlerAttached: false,*/// This code should be inserted back once fb fixes parse bug

    hasFB : function () {
        return (typeof (window.FB) == "object" && FB.Event && typeof (FB.Event.subscribe) == "function");
    },

    addLikeButton : function (par, href) {
        if(SHR4P.fbUtil.hasFBNameSpace()) {
            var likeBtn = SHR4P.jQuery('<fb:like href="'+ href +'"layout="button_count" show_faces="true" width="60" font=""></fb:like>').appendTo(par);

            if(typeof(window.FB) != "undefined" && FB.XFBML && FB.XFBML.parse) {
                FB.XFBML.parse(likeBtn.get(0));
            } else {
                SHR4P.fbUtil.likeButtonsToRender.push(likeBtn.get(0));
            }
        } else {
          SHR4P.jQuery('<iframe src="https://www.facebook.com/plugins/like.php?app_id=207766518608&amp;'
            + 'href='+ href + '&amp;send=false&amp;layout=button_count&amp;'
            + 'width=90&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" '
            + 'style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe>').appendTo(par);
        }


    },

/*    addSendButton : function (par, href) {
        var likeBtn = SHR4P.jQuery('<fb:send href="'+ href +'"layout="button_count" show_faces="true" width="60" font=""></fb:send>').appendTo(par);

        if(typeof(window.FB) != "undefined" && FB.XFBML && FB.XFBML.parse) {
            FB.XFBML.parse(likeBtn.get(0));
        }
    },
*/
    renderFBWidgets: function () {
        if(!SHR4P.fbUtil.renderFBWidgetCalled) {
            setTimeout('SHR4P.fbUtil.renderFBLikeButtons()',0);
            setTimeout('SHR4P.fbUtil.renderFBSendButtons()',0);

            for(var i=0; i<SHR4P.fbUtil.likeButtonsToRender.length; ++i){
                if(typeof(window.FB) != "undefined" && FB.XFBML && FB.XFBML.parse) {
                    FB.XFBML.parse(SHR4P.fbUtil.likeButtonsToRender[i]);
                }
            }
            SHR4P.fbUtil.renderFBWidgetCalled = true;
        }
    },

    renderFBSendButtons : function () {
        SHR4P.jQuery('.shareaholic-fbsend','.shareaholic-like-buttonset').each(function() {
            if(SHR4P.fbUtil.hasFBNameSpace()) {
                var jThis = SHR4P.jQuery(this);
                var targ = jThis.attr('data-shr_href');
                if(typeof(targ) == "undefined" || !targ) {
                    targ = encodeURIComponent(document.location.href);
                }

                var container = SHR4P.jQuery("<div style='float:left;padding-top:0px !important; margin:0px 5px !important;'/>").get(0);
                jThis.replaceWith(container);
                SHR4P.ga.socialAction({serviceId:5, serviceAction:'render', link:targ})
                var sendBtn = SHR4P.jQuery('<fb:send href="'+ targ +'" width="60" font=""></fb:send>').appendTo(container);

                if(typeof(window.FB) != "undefined" && FB.XFBML && FB.XFBML.parse) {
                    FB.XFBML.parse(sendBtn.get(0));
                }
            }

        });
    },

    renderFBLikeButtons : function () {
        SHR4P.jQuery('.shareaholic-fblike','.shareaholic-like-buttonset').each(function() {
            var jThis = SHR4P.jQuery(this);
            var targ = jThis.attr('data-shr_href');
            if(typeof(targ) == "undefined" || !targ) {
                targ = encodeURIComponent(document.location.href);
            }
            var layout = jThis.attr('data-shr_layout');
            if(typeof(layout) == "undefined" || !layout) {
                layout = "button_count";
            }

            var show_faces = jThis.attr('data-shr_showfaces');
            if(typeof(show_faces) == "undefined" || !show_faces) {
                show_faces = "true";
            }

            var send = jThis.attr('data-shr_send');
            if(typeof(send) == "undefined" || !send) {
                send = "false";
            }

            var action = jThis.attr('data-shr_action');
            if(typeof(action) == "undefined" || !action
                        || (action.toLowerCase() != 'recommend' && action.toLowerCase() != 'like')
                        ) {
                action = "like";
            }

            var container = SHR4P.jQuery("<div style='float:left;padding-top:0px !important; margin:0px 5px !important;'/>").get(0);
            jThis.replaceWith(container);
            if(SHR4P.fbUtil.hasFBNameSpace()) {
                var likeBtn = SHR4P.jQuery('<fb:like action="'+ action +'" send = "' + send + '" href="'+ targ +'"layout="'+layout+'" show_faces="'+ show_faces +'" width="60" font=""></fb:like>').appendTo(container);

                if(typeof(window.FB) != "undefined" && FB.XFBML && FB.XFBML.parse) {
                    FB.XFBML.parse(likeBtn.get(0));
                }
            } else {
                var heightFB = "30";
                var widthFB = "60";
                switch(layout) {
                    case "button_count":
                        widthFB = "90";
                        heightFB = "21";
                        break;
                    case "box_count":
                        widthFB = "60";
                        heightFB = "90";
                        break;
                    default:
                        widthFB = "60";
                        heightFB = "80";
                }

                  SHR4P.jQuery('<iframe src="https://www.facebook.com/plugins/like.php?app_id=207766518608&amp;'
                    + 'href='+ targ + '&amp;send=false&amp;layout=' + layout + '&amp;width=' + widthFB + '&amp;show_faces='+ show_faces
                    +'&amp;action='+ action + '&amp;colorscheme=light&amp;font&amp;height='+ heightFB +
                    '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:' + widthFB + 'px; height:' + heightFB +
                    'px;" allowTransparency="true"></iframe>').appendTo(container);
            }
            SHR4P.ga.socialAction({serviceId:5, serviceAction:'render', link:targ})
        });

    },

    addFBConnect: function () {
        SHR4P.fbUtil.addFBNameSpace();
        if(/*!SHR4P.fbUtil.hasFB() && */ !SHR4P.fbUtil.fbConnectAdd) { // this readding of FB script should be removed once fb fixes parse bug
            SHR4P.jQuery('<div id="fb-root"></div>').appendTo('body');
            window.fbAsyncInit = function() {
                FB.init({appId: '207766518608', status: true, cookie: true,
                xfbml: true});
                SHR4P.fbUtil.tryAddFBSubscription();
                // start rendering the fb widgets as FB APIs have been initialized
            };
            SHR4P.fbUtil.renderFBWidgetHandlerAttached = true;
            (function() {
                var e = document.createElement('script');e.async = true;
                e.src = document.location.protocol +
                        '//connect.facebook.net/en_US/all.js';
                e.onload = SHR4P.fbUtil.renderFBWidgets;
                e.onreadystatechange = function() {
                    if (this.readyState == 'complete' || this.readyState == 'loaded') {
                      SHR4P.fbUtil.renderFBWidgets();
                    }
                };

                document.getElementById('fb-root').appendChild(e);

            }());
            SHR4P.fbUtil.fbConnectAdd = 1;
        }/* else if(!SHR4P.fbUtil.fbConnectAdd) {
            SHR4P.fbUtil.tryAddFBSubscription();
            SHR4P.fbUtil.fbConnectAdd = 1;
            if(!SHR4P.fbUtil.renderFBWidgetHandlerAttached) {
                SHR4P.fbUtil.renderFBWidgets();
            }

        } */ // This code should be inserted back once fb fixes parse bug
    },

    tryAddFBSubscription : function () {
        if(SHR4P.fbUtil.hasFB() && FB.XFBML && FB.XFBML.parse) {
            SHR4P.fbUtil.addFBSubscription();
        } else {
             setTimeout(SHR4P.fbUtil.tryAddFBSubscription,500);
        }

    },

    addFBSubscription : function() {
        try {
            FB.Event.subscribe('edge.create', function(href, widget) {
                    SHR4P.ga.socialAction({serviceId:303, serviceAction:'like', link:href})
                    SHR4P.utils.trackAction({
                        serviceId : 303
                        , href : href
                    })
            });
            FB.Event.subscribe('edge.remove', function(href,widget) {
                 SHR4P.ga.socialAction({serviceId:303, serviceAction:'unlike', link:href})
            });
            FB.Event.subscribe('message.send', function(href, widget) {
                SHR4P.ga.socialAction({serviceId:305, serviceAction:'send', link:href})
                SHR4P.utils.trackAction({
                    serviceId : 305
                    , href : href
                })
            });
        } catch (e) {
            SHR4P.debug(e);
        }
    },


    addFBNameSpace : function () {
        var htmlRoot = SHR4P.jQuery(SHR4P.jQuery("html").get(0));
	    if(typeof(htmlRoot.attr("xmlns:fb")) == "undefined"
             && (!SHR4P.jQuery.browser.msie || SHR4P.jQuery.browser.version >= '9.0' )) {
            htmlRoot.attr("xmlns:fb",'https://www.facebook.com/2008/fbml');
            htmlRoot.attr("xmlns:og",'http://opengraphprotocol.org/schema/');
	    }
    },

    hasFBNameSpace : function () {
        var htmlRoot = SHR4P.jQuery(SHR4P.jQuery("html").get(0));
	    return (typeof(htmlRoot.attr("xmlns:fb")) != "undefined");
    }
    
};

// TODO: some sane way to keep this up-to-date.  Once there is a CDN.
// Everything below this line should be generated dynamically with a long
// cache time(except load(), which must be called last).



SHR4P.tooltips_prefix_map = {1:10,2:0,3:0,4:0,5:0,6:1,7:0,8:1,9:1,10:1,11:1,12:1,13:1,14:0,15:1,16:1,17:1,18:1,19:1,20:1,21:1,22:1,23:1,24:1,25:1,26:1,27:0,28:1,29:1,30:1,31:1,32:1,33:1,34:1,35:1,36:1,37:1,38:0,39:1,40:1,41:1,42:1,43:1,44:1,45:1,46:1,47:1,48:1,49:1,50:1,51:10,52:10,53:10,54:10,55:10,56:1,57:1,58:1,59:1,60:1,61:0,62:1,63:1,64:1,65:1,66:1,67:1,68:1,69:1,70:1,71:1,72:1,73:1,74:1,75:1,76:1,78:1,79:1,80:1,81:1,82:1,83:1,84:1,85:1,86:1,87:1,88:1,89:1,90:1,91:1,92:1,93:1,94:1,95:1,96:1,97:1,98:1,99:1,100:1,101:1,102:1,103:1,104:1,105:1,106:1,107:1,108:1,109:1,110:1,111:1,112:1,113:1,114:1,115:1,116:1,117:1,118:1,119:1,120:1,121:1,122:1,123:1,124:1,125:1,126:1,127:1,128:1,129:1,130:1,131:1,132:1,133:1,134:1,135:1,136:1,137:1,138:1,139:1,140:1,141:1,142:1,143:1,144:1,145:1,146:1,147:1,148:1,149:1,150:1,151:1,152:1,153:1,154:1,155:1,156:1,157:1,158:1,159:1,160:1,161:1,162:1,163:1,164:1,165:1,166:1,167:1,168:1,169:1,170:1,171:1,172:1,173:1,174:1,175:1,176:1,177:1,178:1,179:1,180:1,181:1,182:1,183:1,184:9,185:9,186:9,187:0,188:2,189:1,190:1,191:1,192:1,193:0,194:1,195:3,196:1,197:1,198:1,199:1,200:1,201:10,202:0,203:0,204:2,205:0,206:0,207:3,208:7,209:0,210:0,211:0,212:0,213:0,214:7,215:0,216:0,217:0,218:0,219:0,220:0,221:0,222:0,223:7,224:7,225:0,226:0,227:0,228:7,229:0,230:0,231:0,232:7,233:0,234:7,235:0,236:4,237:2,238:2,239:1,240:1,241:1,242:1,243:1,244:1,245:1,246:0,247:3,248:7,249:7,250:6,251:9,252:2,253:0,254:1,255:1,256:1,257:5,258:0,259:0,260:1,261:0,262:1,263:0,264:0,265:0,266:0,267:0,268:0,269:0,270:1,271:1,272:1,273:1,274:1,275:1,276:1,277:0,278:0,279:0,280:0,281:0,282:3,283:0,284:2,285:0,286:0,287:0,288:0,289:0,290:0,291:0,292:0,293:0,294:6,295:11,296:11,297:11,298:1,299:1,300:1,301:1,302:1,303:11,304:11,305:11,306:11,307:11,308:0,309:0,310:0};


SHR4P.tooltips_suffix = {
    1:'Buzzster!',
    2:'Delicious',
    3:'Digg',
    4:'Mixx',
    5:'Facebook',
    6:'Mister-Wong',
    7:'Twitter',
    8:'Netlog',
    9:'Pownce',
    10:'Technorati Favorites',
    11:'Furl',
    12:'Shoutwire',
    13:'CiteULike',
    14:'Jumptags',
    15:'Windows Live Spaces',
    16:'Hemidemi',
    17:'FunP',
    18:'Instapaper',
    19:'PhoneFavs',
    20:'Xerpi',
    21:'Netvouz',
    22:'Wink',
    23:'Ma.gnolia',
    24:'Diigo',
    25:'BibSonomy',
    26:'Taggly',
    27:'BlogMarks',
    28:'Tailrank',
    29:'StartAid',
    30:'Kledy',
    31:'Khabbr',
    32:'Yahoo My Web',
    33:'Meneame',
    34:'Yoolink',
    35:'Bookmarks.fr',
    36:'Technotizie',
    37:'Windows Live Favorites',
    38:'StumbleUpon',
    39:'MySpace',
    40:'Reddit',
    41:'NewsVine',
    42:'Multiply',
    43:'FriendFeed',
    44:'Plaxo Pulse',
    45:'Ping',
    46:'Squidoo',
    47:'Protopage Bookmarks',
    48:'Blinklist',
    49:'Faves',
    50:'AIM',
    51:'E-mail program',
    52:'Gmail',
    53:'Hotmail',
    54:'Yahoo Mail',
    55:'AOL Mail',
    56:'YiGG',
    57:'Webnews',
    58:'Segnalo',
    59:'Pusha',
    60:'YouMob',
    61:'Slashdot',
    62:'Fark',
    63:'Allvoices',
    64:'Jamespot',
    65:'Imera Brazil',
    66:'Twiddla',
    67:'LinkaGoGo',
    68:'MindBodyGreen',
    69:'Feedmarker Bookmarks',
    70:'unalog',
    71:'Hugg',
    72:'Diglog',
    73:'Yahoo Buzz',
    74:'Google Bookmarks',
    75:'NowPublic',
    76:'Yahoo Bookmarks',
    78:'Tumblr',
    79:'LiveJournal',
    80:'Current',
    81:'HelloTxt',
    82:'Spurl',
    83:'Yample',
    84:'Oneview',
    85:'Linkatopia',
    86:'Simpy',
    87:'Yahoo Messenger',
    88:'LinkedIn',
    89:'Global Grind',
    90:'BuddyMarks',
    91:'Ask.com MyStuff',
    92:'Viadeo',
    93:'Maple',
    94:'Wists',
    95:'Gravee',
    96:'Connotea',
    97:'Backflip',
    98:'MyLinkVault',
    99:'SiteJot',
    100:'Sphinn',
    101:'Health Ranker',
    102:'DZone',
    103:'Symbaloo Feeds',
    104:'Care2 News',
    105:'Hyves',
    106:'Design Float',
    107:'Sphere',
    108:'Bitty Browser',
    109:'My Yahoo',
    110:'Google',
    111:'Excite MIX',
    112:'iTunes',
    113:'Zune',
    114:'FeedM8',
    115:'PodNova',
    116:'WINKsite',
    117:'NewsGator',
    118:'Hubdog',
    119:'BUZmob',
    120:'NewsIsFree',
    121:'KlipFolio',
    122:'NETime Channel',
    123:'Feed Mailer',
    124:'Symbaloo Bookmarks',
    125:'Rocket RSS Reader',
    126:'Blogger',
    127:'Flurry',
    128:'FireAnt',
    129:'Sofomo',
    130:'Netomat HUB',
    131:'FeedMarker',
    132:'FeedBucket',
    133:'SendMeRSS',
    134:'Bloglines',
    135:'Windows Live',
    136:'Protopage News Feeds',
    137:'My AOL',
    138:'The Free Library',
    139:'The Free Dictionary',
    140:'Wikio',
    141:'BlogRovR',
    142:'Webwag',
    143:'Daily Rotation',
    144:'Outlook',
    145:'Google Toolbar',
    146:'Bitty Browser Preview',
    147:'RSS 2 PDF',
    148:'LiteFeeds',
    149:'Gritwire',
    150:'FeedLounge',
    151:'FeedReader',
    152:'FeedOnSite',
    153:'i metaRSS',
    154:'RssFwd',
    155:'SimplyHeadlines',
    156:'Zhua Xia',
    157:'Xian Guo',
    158:'mobilerss',
    159:'Netvibes',
    160:'Pageflakes',
    161:'My MSN',
    162:'Odeo',
    163:'AideRSS',
    164:'Fwicki',
    165:'RapidFeeds',
    166:'Miro',
    167:'Shyftr',
    168:'ZapTXT',
    169:'Newgie',
    170:'NewsAlloy',
    171:'Plusmo',
    172:'Yourminis',
    173:'Eskobo',
    174:'Alesti',
    175:'Rasasa',
    176:'AvantGo',
    177:'FeedShow',
    178:'Xanga',
    179:'MySpace Profile',
    180:'Friendster',
    181:'Hi5',
    182:'FeedBlitz',
    183:'Gabbr',
    184:'MSDN',
    185:'Microsoft TechNet',
    186:'Microsoft Expression',
    187:'Tagza',
    188:'Tipd',
    189:'Agregator',
    190:'Strands',
    191:'Evernote',
    192:'Stumpedia',
    193:'Foxiewire',
    194:'Arto',
    195:'Netvibes',
    196:'Bebo',
    197:'Folkd',
    198:'VodPod',
    199:'NewsTrust',
    200:'Amazon (US) Wish List',
    201:'E-mail program',
    202:'YC Hacker News',
    203:'Truemors',
    204:'Techmeme Tip',
    205:'Identi.ca',
    206:'SmakNews',
    207:'Google Reader',
    208:'Bit.ly',
    209:'Kaboodle',
    210:'Posterous',
    211:'TipJoy',
    212:'I Heart It',
    213:'Google Notebook',
    214:'Tr.im',
    215:'Streakr',
    216:'Twine',
    217:'Soup',
    218:'Plurk',
    219:'Blogger',
    220:'TypePad',
    221:'AttentionMeter',
    222:'Smush.it',
    223:'TinyURL',
    224:'Digg',
    225:'BzzScapes',
    226:'Tweetie',
    227:'Diigo',
    228:'Is.gd',
    229:'vi.sualize.us',
    230:'WordPress Blog',
    231:'Mozillaca',
    232:'Su.pr',
    233:'TBUZZ',
    234:'Hub.tm',
    235:'Followup.cc',
    236:'PrintFriendly',
    237:'DailyMe',
    238:'NUjij',
    239:'Read It Later',
    240:'Box.net',
    241:'Balatarin',
    242:'Favoriten',
    243:'Oknotizie',
    244:'diHITT',
    245:'Svejo',
    246:'Hatena',
    247:'Orkut',
    248:'Clicky',
    249:'j.mp',
    250:'ReadWriteWeb',
    251:'Dwellicious',
    252:'Google Translate',
    253:'Yammer',
    254:'Yahoo Buzz India',
    255:'Boxee',
    256:'Pinboard',
    257:'Google Buzz',
    258:'Readability',
    259:'Social.com',
    260:'Google Apps Email',
    261:'HootSuite',
    262:'Google Wave',
    263:'iZeby',
    264:'Ning',
    265:'SpringPad',
    266:'BobrDobr',
    267:'Yandex',
    268:'Moemesto',
    269:'Memori.ru',
    270:'Amazon (UK) Wish List',
    271:'Amazon (CA) Wish List',
    272:'Amazon (DE) Wish List',
    273:'Amazon (FR) Wish List',
    274:'Amazon (JP) Wish List',
    275:'Google Sidewiki',
    276:'Marginize',
    277:'Twittley',
    278:'Script & Style',
    279:'PFBuzz',
    280:'Fwisp',
    281:'100 bookmarks',
    282:'Design Bump',
    283:'eKudos',
    284:'Web Blend',
    285:'Wykop',
    286:'BlogEngage',
    287:'FAQpal',
    288:'Bitacoras',
    289:'N4G',
    290:'Kaevur',
    291:'Virb',
    292:'BonzoBox',
    293:'Zabox',
    294:'ToMuse',
    295:'BuzzFeed',
    296:'Amazon Universal Registry',
    297:'TwitThat',
    298:'Mister-Wong DE',
    299:'Mister-Wong CN',
    300:'Mister-Wong ES',
    301:'Mister-Wong FR',
    302:'Mister-Wong RU',
    303:'Facebook Like',
    304:'Google +1',
    305:'Facebook Send',
    306:'Shareaholic More',
    307:'Shareaholic All',
    308:'Buffer',
    309:'Pinterest',
    310:'Quora'
};


//tooltip prefix mapping
//iso codes: http://www.w3schools.com/tags/ref_language_codes.asp
SHR4P.locales = {
    en:{
        0:"Post to", // english (default)
        1:"Add to",
        2:"Submit to",
        3:"Share on",
        4:"Print with",
        5:"Post on",
        6:"Suggest this article to",
        7:"Shorten URL with",
        8:"Push this on",
        9:"Bookmark on",
        10:"Send via",
        11:""
    },
    es:{
        0:"Publicarlo a", // spanish
        1:"Añadirlo a",
        2:"Enviar a",
        3:"Compartir con",
        4:"Imprimir con",
        5:"Publicarlo en",
        6:"Sugiere este artículo a",
        7:"Acortar URL con",
        8:"Pulse este en",
        9:"Agregar a marcador en",
        10:"Enviar via",
        11:""
    },
    fr:{
        0:"Publiez-le sur", // french
        1:"Ajoutez ce lien à",
        2:"Soumettez ce lien à",
        3:"Partagez-le sur",
        4:"Imprimez-le avec",
        5:"Publiez-le sur",
        6:"Suggérer cet article à",
        7:"Raccourcir l'URL avec",
        8:"Poussez cet article sur",
        9:"Ajoutez-le à vos favoris sur",
        10:"Envoyez-le avec",
        11:""
    },
    de:{
        0:"Senden an", // german
        1:"Hinzufügen zu",
        2:"Übertragen zu",
        3:"Teilen bei",
        4:"Drucken mit",
        5:"Veröffentlichen bei",
        6:"Empfehlen bei",
        7:"URL kürzen mit",
        8:"Schiebe dies auf",
        9:"Lesezeichen speichern auf",
        10:"Senden mit",
        11:""
    },
    tr:{
        0:"Bunu postala:", // turkish
        1:"Bunu ekle:",
        2:"Bu makaleyi paylaş:",
        3:"Bunu paylaş:",
        4:"Baskı ile",
        5:"Bunu postala:",
        6:"Bu makaleyi öner:",
        7:"Kısaltmak Url ile",
        8:"Bunu paylaş:",
        9:"Bookmark on",
        10:"Send via",
        11:""
    },
    it:{
        0:"Pubblicalo su", // italian
        1:"Aggiungilo a",
        2:"Invia questa storia a",
        3:"Condividi su",
        4:"Stampa con",
        5:"Pubblicalo su",
        6:"Suggerisci questo articolo a",
        7:"Accorciare URL con",
        8:"Sparalo in",
        9:"Bookmark on",
        10:"Send via",
        11:""
    },
    pt:{
        0:"Publicar no", // portuguese
        1:"Adicionar ao",
        2:"Enviar história para o",
        3:"Compartilhar no",
        4:"Imprima com",
        5:"Publicar no",
        6:"Sugerir este artigo para",
        7:"Encurtar url com",
        8:"Publicar no",
        9:"Favoritar no",
        10:"Enviar via",
        11:""
    },
    pt_BR:{
        0:"Postar no", // portuguese - brazil
        1:"Adicionar ao",
        2:"Enviar para",
        3:"Compartilhar com",
        4:"Imprimir com",
        5:"Postar no",
        6:"Sugerir este artigo para",
        7:"Encurtar a URL com",
        8:"Enviar no",
        9:"Favoritar no",
        10:"Enviar via",
        11:""
    },
    et:{
        0:"Postita", // estonian
        1:"Lisa",
        2:"Saada",
        3:"Jaga",
        4:"Prindi",
        5:"Postita",
        6:"Soovita seda artiklit",
        7:"Lühenda URL",
        8:"Sparalo in",
        9:"Bookmark on",
        10:"Send via",
        11:""
    },
    hu:{
        0:"Elküldés:", // hungarian
        1:"Hozzáadás:",
        2:"Továbbküldés:",
        3:"Megosztás:",
        4:"Nyomtatás:",
        5:"Publikálás:",
        6:"Ajánlás valakinek:",
        7:"Cím (URL) rövidítése:",
        8:"Kiküldés:",
        9:"Könyvjelző felvétele:",
        10:"Küldés:",
        11:""
    },
    bg:{
        0:"Публикувай в", // bulgarian
        1:"Прибави към",
        2:"Представи към",
        3:"Сподели по",
        4:"Принтирай с",
        5:"Публикувай на",
        6:"Предложи тази статия на",
        7:"Съкратен URL с",
        8:"Бутни това към",
        9:"Отбележи в",
        10:"Изпрати чрез",
        11:""
    },
    el:{
        0:"Αναρτήστε στο", // greek
        1:"Προσθέστε στο",
        2:"Υποβάλλετε στο",
        3:"Μοιραστείτε στο",
        4:"Εκτυπώστε με",
        5:"Αναρτήστε στο",
        6:"Προτείνετε αυτό το άρθρο σε",
        7:"Συντομεύστε το URL με",
        8:"Προωθήστε στο",
        9:"Προσθέστε σελιδοδείκτη στο",
        10:"Αποστείλετε μέσω",
        11:""
    },
    lt:{
        0:"Paskelbti", // lithuanian
        1:"Pridėti į",
        2:"Pateikti",
        3:"Dalintis",
        4:"Spausdinti per",
        5:"Įrašyti",
        6:"Pasiūlyti šį straipsnį į",
        7:"Trumpinti URL su",
        8:"Kilstelėti",
        9:"Pasižymėti per",
        10:"Siųsti per",
        11:""
    },
	he:{
        0:"הפץ ל", // hebrew
        1:"הוסף ל",
        2:"אשר ל",
        3:"שתף ב",
        4:"הדפס עם",
        5:"הפץ ב",
        6:"הצע מאמר זה ל",
        7:"קצר URL עם",
        8:"דחף את זה ב",
        9:"שמור כמועדף ב",
        10:"שלח דרך",
        11:""
    },
    nl:{
        0:"Publiceer op",  // dutch
        1:"Voeg toe aan",
        2:"Stuur in op",
        3:"Deel op",
        4:"Print met",
        5:"Publiceer op",
        6:"Suggereer dit artikel op",
        7:"Verkort de URL met",
        8:"Push dit op",
        9:"Maak een bladwijzer op",
        10:"Verzend met",
        11:""
    }
};
SHR4P.ga.init();
SHR4P.load();
