// socialtags.js

// 'ajouter un bookmark' ne marche que sous IE
// les tuyaux trouves pour FF ou Opera sont creves
;var socialtags_addfavorite = function(u,t){
	if(document.all)window.external.AddFavorite(u,t);
};
(function($) { $(function(){
var selector = $('#contenu');
if (!selector.length) return;
var socialtags = [
{ a: 'facebook', n: 'Facebook', i: 'plugins/socialtags/socialtags/images/facebook.png', u: 'http://www.facebook.com/sharer.php?u=%u&t=%t' },
{ a: 'google', n: 'Google', i: 'plugins/socialtags/socialtags/images/google.png', u: 'http://www.google.com/bookmarks/mark?op=edit&bkmk=%u&title=%t' },
{ a: 'live', n: 'Live', i: 'plugins/socialtags/socialtags/images/live.png', u: 'https://favorites.live.com/quickadd.aspx?marklet=1&add=%u&title=%t' },
{ a: 'myspace', n: 'MySpace', i: 'plugins/socialtags/socialtags/images/myspace.png', u: 'http://www.myspace.com/Modules/PostTo/Pages/?u=%u&t=%t' },
{ a: 'yahoobookmarks', n: 'Yahoo! Bookmarks', i: 'plugins/socialtags/socialtags/images/yahoobookmarks.png', u: 'http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&u=%u&t=%t' },
{ a: 'buzzyahoo', n: 'Yahoo! Buzz', i: 'plugins/socialtags/socialtags/images/buzzyahoo.png', u: 'http://buzz.yahoo.com/submit?submitUrl=%u&submitHeadline=%t&submitSummary=%d' },
{ a: 'yahoomyweb', n: 'Yahoo! MyWeb', i: 'plugins/socialtags/socialtags/images/yahoomyweb.png', u: 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=%u&t=%t' }
];
var title = $('title').text() ||'';
// [@attr] style selectors removed in jQuery 1.3 (voir http://docs.jquery.com/Selectors)
// si besoin, rendre compatible avec anciennes versions de jQuery (SPIP 192x)
var jqss = (jQuery.fn.jquery <= '1.2.6') ? '@' : '';
var description = ($('meta['+jqss+'name=description]').attr('content') || '').substr(0,250);
var cano = $('link['+jqss+'rel=canonical]')[0];
var url = cano ? cano.href : document.location.href;
var ul = $('<ul><\/ul>');
var esc = function(x){return encodeURIComponent(x).replace(/\s/g,' ');};

$.each(socialtags, function(){ if (this.u) {
	if (this.a == 'bookmark' && !document.all) return;

	$('<a rel="nofollow"><img class="socialtags-hovers" src="'+ this.i +'"\/><\/a>')
	.attr('href',
		this.u
		.replace(/%u/g, esc(url))
		.replace(/%t/g, esc(title))
		.replace(/%d/g, esc(description))
	)
	.attr('title', this.n)
	.wrap('<li><\/li>')
	.parent().appendTo(ul);
}});

selector.after(ul.wrap('<div class="socialtags"><\/div>').parent());

}); })(jQuery);
