jQuery(document).ready(function() {

	// xhtml 1.0 pour utiliser target="_blank"
	jQuery('.aster-bookmarks a.external').attr("target", "_blank");

	// Gère l'extension verticale en cas de plusieurs lignes.
	var asterBaseHeight=jQuery('.aster-bookmarks').height();
	var asterFullHeight=jQuery('.aster-bookmarks ul.socials').height();
	if (asterFullHeight>asterBaseHeight) {
		jQuery('.aster-bookmarks-expand').hover(
			function() {
				jQuery(this).animate({
						height: asterFullHeight+'px'
				}, {duration: 400, queue: false});
			},
			function() {
				jQuery(this).animate({
						height: asterBaseHeight+'px'
				}, {duration: 400, queue: false});
			}
		);
	}
	// Centrage automatique
	if (jQuery('.aster-bookmarks-center') || jQuery('.aster-bookmarks-spaced')) {
		var asterFullWidth=jQuery('.aster-bookmarks').width();
		var asterBookmarkWidth=jQuery('.aster-bookmarks:first ul.socials li').width();
		var asterBookmarkCount=jQuery('.aster-bookmarks:first ul.socials li').length;
		var numPerRow=Math.floor(asterFullWidth/asterBookmarkWidth);
		var asterRowWidth=Math.min(numPerRow, asterBookmarkCount)*asterBookmarkWidth;
		
		if (jQuery('.aster-bookmarks-spaced').length>0) {
			var asterLeftMargin=Math.floor((asterFullWidth-asterRowWidth)/(Math.min(numPerRow, asterBookmarkCount)+1));
			jQuery('.aster-bookmarks ul.socials li').css('margin-left', asterLeftMargin+'px');
		} else if (jQuery('.aster-bookmarks-center'.length>0)) {
			var asterLeftMargin=(asterFullWidth-asterRowWidth)/2;
			jQuery('.aster-bookmarks-center').css('margin-left', asterLeftMargin+'px');
		}
		
	}
	jQuery('.aster-bookmarks a.external').click(function() {
	// récupère l'URL courante et l'encode selon le standard URI
	var url = encodeURIComponent(window.location.href), desc = '';

	/* Utilise une méthode de jQuery pour parser la description de l'URL
	Il faut placer le texte avec l'ID="aster-bookmarks-content"
	On peut changer le contenant des la description par un autre tag ou une autre ID */
	if( jQuery('p.aster-bookmarks-content').length ) {
		desc = encodeURIComponent(jQuery('p.aster-bookmarks-content').text());
	}

	/*détecte le Réseau social vers lequel le visiteur veut publier en vérifiant le nom de la classe du site qu'on a déclaré dans le code HTML.
	On assigne ensuite l'URL et la Description dans l'URL et on redirige le lien cliqué
	Vous pouvez aussi utiliser la méthode window.open() pour ouvrir le lien dans une nouvelle fenêtre */
	var asterTwitterLogin='4G Moto';//indiquez votre compte Twitter
	switch(this.parentNode.className) {
		case 'aster-twittley':
			this.href += '?title=' + document.title + '&url=' + url + '&desc=' + desc + '&pcat=Internet&tags=';
			break;
		case 'aster-digg':
			this.href += '?phase=2&title=' + document.title + '&url=' + url + '&desc=' + desc;
			break;
		case 'aster-twitter':
			this.href += '?status='+ asterTwitterLogin +' : ' + document.title + '+-+' + url;
			break;
		case 'aster-scriptstyle':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'aster-reddit':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'aster-delicious':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'aster-stumbleupon':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'aster-mixx':
			this.href += '?title=' + document.title + '&page_url=' + url + '&desc=' + desc;
			break;
		case 'aster-technorati':
			this.href += '?add=' + url;
			break;
		case 'aster-blinklist':
			this.href += '?Action=Blink/addblink.php&Title=' + document.title + '&Url=' + url;
			break;
		case 'aster-diigo':
			this.href += '?title=' + document.title + '&url=' + url + '&desc=' + desc;
			break;
		case 'aster-yahoobuzz':
			this.href += '?submitHeadline=' + document.title + '&submitUrl=' + url + '&submitSummary=' + desc + '&submitCategory=science&submitAssetType=text';
			break;
		case 'aster-myspace':
			this.href += '?t=' + document.title + '&u=' + url;
			break;
		case 'aster-facebook':
			this.href += '?t=' + document.title + '&u=' + url;
			break;
		case 'aster-designfloat':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'aster-devmarks':
			this.href += '?posttitle=' + document.title + '&posturl=' + url + '&posttext=' + desc;
			break;
		case 'aster-newsvine':
			this.href += '?h=' + document.title + '&u=' + url;
			break;
		case 'aster-google':
			this.href += '?op=add&title=' + document.title + '&bkmk=' + url;
			break;
		case 'aster-googlebookmarks':
			this.href += '?op=add&title=' + document.title + '&bkmk=' + url;
			break;
	}
})
});
