jQuery(document).ready(function () {
    jQuery(".shr-bookmarks a.external").attr("target", "_blank");
	
	var c = jQuery(".shr-bookmarks").height(),
        d = jQuery(".shr-bookmarks ul.socials").height(),
		h = jQuery(".shr-bookmarks div.shr-getshr").outerHeight(true);
		
	d > c && jQuery(".shr-bookmarks-expand").hover(function () {
        jQuery(this).animate({
            height: (d + h) + "px"
        }, {
            duration: 400,
            queue: false
        })
    }, function () {
        jQuery(this).animate({
            height: c + "px"
        }, {
            duration: 400,
            queue: false
        })
    });
    if (jQuery(".shr-bookmarks-center") || jQuery(".shr-bookmarks-spaced")) {
        var a = jQuery(".shr-bookmarks").width(),
            b = jQuery(".shr-bookmarks:first ul.socials li").width(),
            e = jQuery(".shr-bookmarks:first ul.socials li").length,
            f = Math.floor(a / b);
        b = Math.min(f, e) * b;
        if (jQuery(".shr-bookmarks-spaced").length > 0) {
            a = Math.floor((a - b) / (Math.min(f, e) + 1));
            jQuery(".shr-bookmarks ul.socials li").attr("style", 'margin-left:' + a + 'px !important')
        } else if (jQuery(true)) {
            a = (a - b) / 2;
            jQuery(".shr-bookmarks-center").attr("style", 'margin-left:' + a + 'px !important')
        }
    }
	
	if( h > 0 &&  (jQuery(".shr-bookmarks-expand").length == 0
					|| !(d>c))) {
		jQuery(".shr-bookmarks").height(c+h);
	}
	
	var sText = getShareText();
	if(sText != "") {
		jQuery(".shr-bookmarks div.shr-getshr a").text(sText);
		jQuery(".shr-bookmarks").hover(function() {
			jQuery(".shr-bookmarks div.shr-getshr").css('visibility','visible');
		}, function () {
			jQuery(".shr-bookmarks div.shr-getshr").css('visibility','hidden');
		});
	}
});

function getShareText() {
	var sName = getBrowser();
	var sText = "";
	if(sName != "") {
		sText = "Get Shareaholic for " + sName;
	}
	return sText;
}

function getBrowser() {
	var sUA = navigator.userAgent;
	var sName = "";
	if(sUA.indexOf("MSIE") != -1 ) {
		sName = "Internet Explorer";
	} else if(sUA.indexOf("Firefox") != -1 ) {
		sName = "Firefox";
	} else if(sUA.indexOf("Flock") != -1 ) {
		sName = "Flock";
	} else if(sUA.indexOf("Chrome") != -1 ) {
		sName = "Google Chrome";
	} else if(sUA.indexOf("Safari") != -1 ) {
		sName = "Safari";
	} else if(sUA.indexOf("Opera") != -1 ) {
		sName = "Opera";
	} else if(sUA.indexOf("Songbird") != -1 ) {
		sName = "Songbird";
	} 
	return sName;
}

/*
	click handler for SexyBookmarks
	Credit: Phong Thai Cao - http://www.JavaScriptBank.com
	Please keep this creadit when you use this code
*/
jQuery('.sexy-bookmarks a.external').click(function() {
	// get the current URL & encode it into the standard URI
	var url = encodeURIComponent(window.location.href), desc = '';

	// parse the description for the above URL by the text() method of jQuery
	// the text must be placed in the P tag with ID="sexy-bookmarks-content"
	// so you can change the container of description with another tag and/or another ID
	if( jQuery('p.sexy-bookmarks-content').length ) {
		desc = encodeURIComponent(jQuery('p.sexy-bookmarks-content').text());
	}

	// detect the social bookmark site user want to share your URL
	// by checking the className of site that we'll declare in the HTML code
	// and assign the URL & description we got into the current anchor
	// then redirect to the clicked bookmark site, you can use window.open() method for opening the new window
	switch(this.parentNode.className) {
		case 'sexy-twittley':
			this.href += '?title=' + document.title + '&url=' + url + '&desc=' + desc + '&pcat=Internet&tags=';
			break;
		case 'sexy-digg':
			this.href += '?phase=2&title=' + document.title + '&url=' + url + '&desc=' + desc;
			break;
		case 'sexy-twitter':
			this.href += '?status=RT+@your_twitter_id:+' + document.title + '+-+' + url;
			break;
		case 'sexy-scriptstyle':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'sexy-reddit':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'sexy-delicious':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'sexy-stumbleupon':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'sexy-mixx':
			this.href += '?title=' + document.title + '&page_url=' + url + '&desc=' + desc;
			break;
		case 'sexy-technorati':
			this.href += '?add=' + url;
			break;
		case 'sexy-blinklist':
			this.href += '?Action=Blink/addblink.php&Title=' + document.title + '&Url=' + url;
			break;
		case 'sexy-diigo':
			this.href += '?title=' + document.title + '&url=' + url + '&desc=' + desc;
			break;
		case 'sexy-yahoobuzz':
			this.href += '?submitHeadline=' + document.title + '&submitUrl=' + url + '&submitSummary=' + desc + '&submitCategory=science&submitAssetType=text';
			break;
		case 'sexy-myspace':
			this.href += '?t=' + document.title + '&u=' + url;
			break;
		case 'sexy-facebook':
			this.href += '?t=' + document.title + '&u=' + url;
			break;
		case 'sexy-designfloat':
			this.href += '?title=' + document.title + '&url=' + url;
			break;
		case 'sexy-devmarks':
			this.href += '?posttitle=' + document.title + '&posturl=' + url + '&posttext=' + desc;
			break;
		case 'sexy-newsvine':
			this.href += '?h=' + document.title + '&u=' + url;
			break;
		case 'sexy-google':
			this.href += '?op=add&title=' + document.title + '&bkmk=' + url;
			break;
	}
})
