function socialShare(div){
	share_url = location.href;
	if (share_url.substring(share_url.length-1, share_url.length) != "/") {
		share_url = share_url + "/";
	}
	
	share_url = encodeURIComponent(share_url);
	share_title = document.title;
	
	if (share_title.length > 130) {
		share_title = share_title.substring(0, 130)+"..."
	}
	//share_title = encodeURIComponent(share_title);
	socialDoShare(div, share_url, share_title);
}

function socialShareUrl(div, share_url){
	
	share_url = encodeURIComponent(share_url);
	share_title = document.title;
	
	if (share_title.length > 130) {
		share_title = share_title.substring(0, 130)+"..."
	}
	//share_title = encodeURIComponent(share_title);
	socialDoShare(div, share_url, share_title);
}

function socialDoShare(div, share_url, share_title){
	
	share_title = encodeURIComponent(share_title);
	$("#"+div).html('<a title="Мой Мир" target="_blank" href="http://connect.mail.ru/share?share_url=' + share_url + '&title='+share_title+'"><img src="/images/social_networks/moi_mir.gif" width="16" height="16"></a><a  title="Одноклассники" target="_blank" href="http://www.odnoklassniki.ru/dk?st.cmd=addShare&st._surl=' + share_url+'"><img src="/images/social_networks/odnokl.gif" width="16" height="16"></a><a title="В контакте" target="_blank" href="http://vkontakte.ru/share.php?url=' + share_url + '&title=' + share_title + '&noparse=true"><img src="/images/social_networks/vkont.gif" width="16" height="16"></a><a title="LiveJournal" target="_blank" href="http://www.livejournal.com/update.bml?subject=' + share_title + '&event=' + encodeURIComponent("<a href=\"") + share_url +encodeURIComponent("\">") + share_title + encodeURIComponent("</a>")+'"><img src="/images/social_networks/live.gif" width="16" height="16"></a><a title="Twitter" target="_blank" href="http://twitter.com/share?url=' + share_url + '&text=' + share_title+'"><img src="/images/social_networks/twitt.gif" width="16" height="16"></a><a title="Facebook" target="_blank" href="http://www.facebook.com/sharer.php?u=' + share_url + "&t=" + share_title+'"><img src="/images/social_networks/face_b.gif" width="16" height="16"></a><a title="Google Plus" target="_blank" href="https://plusone.google.com/_/+1/confirm?hl=en&url=' + share_url+'"><img src="/images/social_networks/gp.png" width="16" height="16"></a>');

	$("#"+div+" > a").click(function(){
		
		url = $(this).attr("href");
		
		$.post("/ajax/save_social_stats.php", {url: encodeURIComponent(url)});
		
		
		
	});
	
}


var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

 function base64_encode (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
			_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
		}
		return output;
}

