var uacct1;
var uacct2;

$(document).ready(function() {
	$.get("asiServletGoogleConstant.jsp?tipo=1", function(data) {
		uacct1 = data;
	});
	
	$.get("asiServletGoogleConstant.jsp?tipo=2", function(data) {
		uacct2 = data;
	});
});

function _jsShare(t, titulo, descricao, thumb) {
	link = window.location.toString();
	link = link.substr((link.length-1),1) == "/"  ? link.substr(0,(link.length-1)) :  link;
	  
	if (link.indexOf("?") == -1) {
		link += '?origem=' + t;
	}
	else {
		link += '&origem=' + t;
	}
	
	link = escape(link);
	  
	if (titulo == undefined || titulo == '' || !titulo) {
		titulo = document.title;
	} 

	switch(t) {
		case 'twitter':
			window.open('http://twitter.com/home?status=' + titulo + ' - ' + link);
			break;
			
		case 'facebook':
			window.open('http://www.facebook.com/share.php?u=' + link + '&t=' + titulo, 'facebook', 'width=500, height=400');
			break;

		case 'linkedin':
			window.open('http://www.linkedin.com/shareArticle?mini=true&url=' + link + '&title=' + titulo + '&summary=' + descricao + '&source=Assine Abril - http://www.assineabril.com.br', 'linkedin', 'width=500, height=370');
			break;

		case 'google':
			window.open('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + link + '&title=' + titulo, 'google', 'width=600, height=450');
			break;

		case 'delicious':
			window.open('http://del.icio.us/post?url=' + link + '&title=' + titulo + '&notes=' + descricao);
			break;

		case 'tumblr':
			window.open('http://www.tumblr.com/share?v=3&u=' + link + '&t=' + titulo + '&s=' + titulo, 'tumblr', 'width=440, height=450');
			break; 
			
		case 'orkut':
			urlShare = 'http://promote.orkut.com/preview?nt=orkut.com&tt=' + titulo + '&du=' + link;
			
			if (descricao != undefined && descricao != '') {
				urlShare += '&cn=' + descricao;
			}
			if (thumb != undefined && thumb != '') {
				urlShare += '&tn=' + thumb;
			}
			
			window.open(urlShare, 'orkut', 'width=645, height=422');
			break;
	}

	doTrackEventRedeSocial(t);
}

function doTrackEventRedeSocial(rede) {
	var _gaq = _gaq || [];
	_gaq.push(
	    ['_setAccount', uacct1],
	    ['_setAllowHash','false'],
	    ['_setDomainName','.assineabril.com.br'],
	    ['_trackEvent','redesocial', rede],
	    ['b._setAccount', uacct2],
	    ['b._setAllowHash','false'],
	    ['b._setDomainName','.assineabril.com.br'],
	    ['b._trackEvent', 'redesocial', rede]
	  );
	
	(function() {
	  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();	
}