/**
 * The Syn.SocialBookmarkingPopup Component Class
 */

/**
 * Create a Syn.SocialBookmarkingPopup component instance
 * @contructor
 */
Syn.SocialBookmarkingPopup = Syn.Component.extend (
{
	/**
	 * Initialize the component class -- called automatically the default constructor
	 *
	 * @member Syn.SocialBookmarkingPopup
	 * @param {Object} config The configuration data structure
	 */
	init: function(config)
	{
		this._super(config);

		this.url = window.location;
		if (/\?/.test(this.url))
                {
                        this.url += '&src=';
                }
                else
                {
                        this.url += '?src=';
                }

		this.url = encodeURIComponent(this.url);
		this.title = encodeURIComponent(document.title);
		this.networks = config.networks.split('|');
		this.portal = Syn.Config.Domain;

		this.uniqueElmt('links').find('a').connect('click', this, 'openLink');		

		/* set up tracking here */
		for (var i = 0; i < this.networks.length; i++)
		{
			this.uniqueElmt(this.networks[i]).track({
				'event':  'click',
				'module': 'Image',
				'args':   {'network': this.networks[i], 'portal': this.portal}
			});
		}
	},

	/**
	 * Opens the share link in a new window after inserting the title of the article
	 *
	 * @member Syn.SocialBookmarkingPopup
	 * @param {Object} target
	 * @param {Object} event
	 */
	openLink: function(target, event)
	{
		var network = $(target).attr('rel');
		var page_url = this.url + network;

		var out_url = String(target).replace('{title}', this.title).replace('{url}', page_url);
		window.open(out_url);
		return false;
	}
});
