/*
	click handler for shrBookmarks
	Credit: Phong Thai Cao - http://www.JavaScriptBank.com
	Please keep this creadit when you use this code
*/
jQuery(document).ready(function() {

	// xhtml 1.0 strict way of using target _blank
	jQuery('.shr-bookmarks a.external').attr("target", "_blank");

	// this block sets the auto vertical expand when there are more than 
	// one row of bookmarks.
	var shrBaseHeight=jQuery('.shr-bookmarks').height();
	var shrFullHeight=jQuery('.shr-bookmarks ul.socials').height();
	if (shrFullHeight>shrBaseHeight) {
		jQuery('.shr-bookmarks-expand').hover(
			function() {
				jQuery(this).animate({
						height: shrFullHeight+'px'
				}, {duration: 400, queue: false});
			},
			function() {
				jQuery(this).animate({
						height: shrBaseHeight+'px'
				}, {duration: 400, queue: false});
			}
		);
	}
	// autocentering
	if (jQuery('.shr-bookmarks-center') || jQuery('.shr-bookmarks-spaced')) {
		var shrFullWidth=jQuery('.shr-bookmarks').width();
		var shrBookmarkWidth=jQuery('.shr-bookmarks:first ul.socials li').width();
		var shrBookmarkCount=jQuery('.shr-bookmarks:first ul.socials li').length;
		var numPerRow=Math.floor(shrFullWidth/shrBookmarkWidth);
		var shrRowWidth=Math.min(numPerRow, shrBookmarkCount)*shrBookmarkWidth;
		
		if (jQuery('.shr-bookmarks-spaced').length>0) {
			//var shrLeftMargin=Math.floor((shrFullWidth-shrRowWidth)/(Math.min(numPerRow, shrBookmarkCount)+1));
			var shrLeftMargin=0;
			jQuery('.shr-bookmarks ul.socials li').css('margin-left', shrLeftMargin+'px');
		} else if (jQuery('.shr-bookmarks-center'.length>0)) {
			//var shrLeftMargin=(shrFullWidth-shrRowWidth)/2;
			var shrLeftMargin=0;
			jQuery('.shr-bookmarks-center').css('margin-left', shrLeftMargin+'px');
		}
		
	}
	
	/*
		click handler for shrBookmarks
		Credit: Cao Phong - http://www.JavaScriptBank.com
		Please keep this creadit when you use this code
	*/
	jQuery('.shr-bookmarks a.external').click(function() {
		var url = encodeURIComponent(window.location.href), desc = '';
		if( jQuery('p.shr-bookmarks-content').length ) {
			desc = encodeURIComponent(jQuery('p.shr-bookmarks-content').text());
		}
		switch(this.parentNode.className) {
			case 'shr-twittley':
				this.href += '?title=' + document.title + '&url=' + url + '&desc=' + desc + '&pcat=Internet&tags=';
				break;
			case 'shr-digg':
				this.href += '?phase=2&title=' + document.title + '&url=' + url + '&desc=' + desc;
				break;
			case 'shr-twitter':
				this.href += '?status=RT+@your_twitter_id:+' + document.title + '+-+' + url;
				break;
			case 'shr-scriptstyle':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'shr-reddit':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'shr-delicious':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'shr-stumbleupon':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'shr-mixx':
				this.href += '?title=' + document.title + '&page_url=' + url + '&desc=' + desc;
				break;
			case 'shr-technorati':
				this.href += '?add=' + url;
				break;
			case 'shr-blinklist':
				this.href += '?Action=Blink/addblink.php&Title=' + document.title + '&Url=' + url;
				break;
			case 'shr-diigo':
				this.href += '?title=' + document.title + '&url=' + url + '&desc=' + desc;
				break;
			case 'shr-yahoobuzz':
				this.href += '?submitHeadline=' + document.title + '&submitUrl=' + url + '&submitSummary=' + desc + '&submitCategory=science&submitAssetType=text';
				break;
			case 'shr-myspace':
				this.href += '?t=' + document.title + '&u=' + url;
				break;
			case 'shr-facebook':
				this.href += '?t=' + document.title + '&u=' + url;
				break;
			case 'shr-designfloat':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'shr-devmarks':
				this.href += '?posttitle=' + document.title + '&posturl=' + url + '&posttext=' + desc;
				break;
			case 'shr-newsvine':
				this.href += '?h=' + document.title + '&u=' + url;
				break;
			case 'shr-google':
				this.href += '?op=add&title=' + document.title + '&bkmk=' + url;
				break;
		}
	})
});


