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
*/
function totaltrim(text){
    text=$.trim(text);
    var val='';     
    $.each(text.split(' '),function(index,value){
            var add = $.trim(value);
            if (add!=''){val += add + ' '};
    });
    return val;
}
$('.shr-bookmarks a.external').live('click', function() {
    var $this=$(this);
    $this.attr('target','_blank');
    var href=$this.attr('href');
    if (href.indexOf("?")<=0){
	    // get the current URL & encode it into the standard URI
	    var url = encodeURIComponent('http://www.ketelkiezer.nl/');
        var title = encodeURIComponent(totaltrim($('#socialtitle').text())); 
        var desc = encodeURIComponent(totaltrim($('#socialcontent').text()));
        
	    switch(this.parentNode.className) {
		    case 'shr-twittley':
			    this.href += '?title=' + title + '&url=' + url + '&desc=' + desc + '&pcat=Internet&tags=';
			    break;
		    case 'shr-digg':
			    this.href += '?phase=2&title=' + title + '&url=' + url + '&desc=' + desc;
			    break;
		    case 'shr-twitter':
			    this.href += '?status=' + title + '&url=' + url;     
			    break;
		    case 'shr-scriptstyle':
			    this.href += '?title=' + title + '&url=' + url;
			    break;
		    case 'shr-reddit':
			    this.href += '?title=' + title + '&url=' + url;
			    break;
		    case 'shr-delicious':
			    this.href += '?title=' + title + '&url=' + url;
			    break;
		    case 'shr-stumbleupon':
			    this.href += '?title=' + title + '&url=' + url;
			    break;
		    case 'shr-mixx':
			    this.href += '?title=' + 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=' + title + '&Url=' + url;
			    break;
		    case 'shr-diigo':
			    this.href += '?title=' + title + '&url=' + url + '&desc=' + desc;
			    break;
		    case 'shr-yahoobuzz':
			    this.href += '?submitHeadline=' + title + '&submitUrl=' + url + '&submitSummary=' + desc + '&submitCategory=science&submitAssetType=text';
			    break;
		    case 'shr-myspace':
			    this.href += '?t=' + title + '&u=' + url;
			    break;
		    case 'shr-facebook':
			     this.href += '?src=bm&t=' + title + '&u=' + url + '&v=3';	   
			    break;
		    case 'shr-designfloat':
			    this.href += '?title=' + title + '&url=' + url;
			    break;
		    case 'shr-devmarks':
			    this.href += '?posttitle=' + title + '&posturl=' + url + '&posttext=' + desc;
			    break;
		    case 'shr-newsvine':
			    this.href += '?h=' + title + '&u=' + url;
			    break;
		    case 'shr-google':
			    this.href += '?op=add&title=' + title + '&bkmk=' + url;
			    break;
		    case 'shr-hyves':
			    this.href += '?name=' + title + '&text=' + desc + '&type=12';
			    break;
		    case 'shr-linkedin':
			    this.href += '?mini=true&url=' + url + '&title=' + title + '&summary=' + desc;
			    break;			 
            case 'shr-mail':
			    this.href += '?subject=' + title + '&body=' + desc + "%20" + url;
			    break;	
	    }
	    return true
	}
})
