/*
	click handler for socialBookmarks
	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('.social-bookmarks a.external').attr("target", "_blank");

	// this block sets the auto vertical expand when there are more than 
	// one row of bookmarks.
	var socialBaseHeight=jQuery('.social-bookmarks').height();
	var socialFullHeight=jQuery('.social-bookmarks ul.socials').height();
	if (socialFullHeight>socialBaseHeight) {
		jQuery('.social-bookmarks-expand').hover(
			function() {
				jQuery(this).animate({
						height: socialFullHeight+'px'
				}, {duration: 400, queue: false});
			},
			function() {
				jQuery(this).animate({
						height: socialBaseHeight+'px'
				}, {duration: 400, queue: false});
			}
		);
	}
	// autocentering
	if (jQuery('.social-bookmarks-center') || jQuery('.social-bookmarks-spaced')) {
		var socialFullWidth=jQuery('.social-bookmarks').width();
		var socialBookmarkWidth=jQuery('.social-bookmarks:first ul.socials li').width();
		var socialBookmarkCount=jQuery('.social-bookmarks:first ul.socials li').length;
		var numPerRow=Math.floor(socialFullWidth/socialBookmarkWidth);
		var socialRowWidth=Math.min(numPerRow, socialBookmarkCount)*socialBookmarkWidth;
		
		if (jQuery('.social-bookmarks-spaced').length>0) {
			var socialLeftMargin=Math.floor((socialFullWidth-socialRowWidth)/(Math.min(numPerRow, socialBookmarkCount)+1));
			jQuery('.social-bookmarks ul.socials li').css('margin-left', socialLeftMargin+'px');
		} else if (jQuery('.social-bookmarks-center'.length>0)) {
			var socialLeftMargin=(socialFullWidth-socialRowWidth)/2;
			jQuery('.social-bookmarks-center').css('margin-left', socialLeftMargin+'px');
		}
		
	}
	
	/*
		click handler for socialBookmarks
		Credit: Cao Phong - http://www.JavaScriptBank.com
		Please keep this creadit when you use this code
	*/
	jQuery('.social-bookmarks a.external').click(function() {
		var url = encodeURIComponent(window.location.href), desc = '';
		if( jQuery('p.social-bookmarks-content').length ) {
			desc = encodeURIComponent(jQuery('p.social-bookmarks-content').text());
		}
		switch(this.parentNode.className) {
			case 'social-twittley':
				this.href += '?title=' + document.title + '&url=' + url + '&desc=' + desc + '&pcat=Internet&tags=';
				break;
			case 'social-digg':
				this.href += '?phase=2&title=' + document.title + '&url=' + url + '&desc=' + desc;
				break;
			case 'social-twitter':
				this.href += '?status=RT+@etcsports:+Sports Surfaces ~ Supply and Installation ~ ETC Sports Surfaces Limited +-+' + url;
				break;
			case 'social-scriptstyle':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'social-reddit':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'social-delicious':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'social-stumbleupon':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'social-mixx':
				this.href += '?title=' + document.title + '&page_url=' + url + '&desc=' + desc;
				break;
			case 'social-technorati':
				this.href += '?add=' + url;
				break;
			case 'social-blinklist':
				this.href += '?Action=Blink/addblink.php&Title=' + document.title + '&Url=' + url;
				break;
			case 'social-diigo':
				this.href += '?title=' + document.title + '&url=' + url + '&desc=' + desc;
				break;
			case 'social-yahoobuzz':
				this.href += '?submitHeadline=' + document.title + '&submitUrl=' + url + '&submitSummary=' + desc + '&submitCategory=science&submitAssetType=text';
				break;
			case 'social-myspace':
				this.href += '?t=' + document.title + '&u=' + url;
				break;
			case 'social-facebook':
				this.href += '?t=' + document.title + '&u=' + url;
				break;
			case 'social-designfloat':
				this.href += '?title=' + document.title + '&url=' + url;
				break;
			case 'social-devmarks':
				this.href += '?posttitle=' + document.title + '&posturl=' + url + '&posttext=' + desc;
				break;
			case 'social-newsvine':
				this.href += '?h=' + document.title + '&u=' + url;
				break;
			case 'social-google':
				this.href += '?op=add&title=' + document.title + '&bkmk=' + url;
				break;
		}
	})
});

