// Used to add links to Tweet 'from DFTBA'
// To send a tweet set the link (href=) attribute to javascript: DFTBATweet('What You Want To Tweet');
// E.G.<a href="javascript: DFTBATweet('I like this song - http://bit.ly/xxxx')">Tweet This Song</a>

var tweetWin=0;

function DFTBATweet(Content) {
	var TweetEncoded = escape(Content);
	if(tweetWin)
	{
    	if(!tweetWin.closed) tweetWin.close();
  	}
	var URLStr = "http://share.dftba.com/twitter/authenticate.php?Type=plain&Content="+TweetEncoded;
	var top = 0;
	var left = 0;
	var width = 0;
	var height = 0;
	tweetWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

window.onload=function() {
	if ( document.getElementById('fb_like') ) {
		var FB_LINK = 'http://dftba.com/like.php?key='+escape(encode64(document.location+"-_-"+document.title));
		var FB_URL = 'http://www.facebook.com/widgets/like.php?layout=button_count&show_faces=false&action=like&href='+FB_LINK;
		document.getElementById('fb_like').innerHTML = '<iframe src="'+FB_URL+'" scrolling="no" frameborder="0" style="border:none; width:110px; height:20px; margin-top:10px;"></iframe>';
		document.getElementsByTagName("head")[0].innerHTML = document.getElementsByTagName("head")[0].innerHTML+"\n"+'<meta property="og:title" content="'+document.title+'"/>';
	}
}

var fbWin=0;

function DFTBAfbook(title, lnk) {
	var titleencoded = escape(title);
	var lnkencoded = escape(lnk);
	if(fbWin)
	{
    	if(!fbWin.closed) tweetWin.close();
  	}
	var URLStr = "http://www.facebook.com/sharer.php?u="+lnkencoded+"&t="+titleencoded;
	var top = 0;
	var left = 0;
	var width = 500;
	var height = 200;
	tweetWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

window.onload=function() {
	if ( document.getElementById('fb_like') ) {
		var FB_LINK = 'http://dftba.com/like.php?key='+escape(encode64(document.location+"-_-"+document.title));
		var FB_URL = 'http://www.facebook.com/widgets/like.php?layout=button_count&show_faces=false&action=like&href='+FB_LINK;
		document.getElementById('fb_like').innerHTML = '<iframe src="'+FB_URL+'" scrolling="no" frameborder="0" style="border:none; width:110px; height:20px; margin-top:10px;"></iframe>';
		document.getElementsByTagName("head")[0].innerHTML = document.getElementsByTagName("head")[0].innerHTML+"\n"+'<meta property="og:title" content="'+document.title+'"/>';
	}
}

var keyStr = "ABCDEFGHIJKLMNOP" +
               "QRSTUVWXYZabcdef" +
               "ghijklmnopqrstuv" +
               "wxyz0123456789+/" +
               "=";

function encode64(input) {
input = escape(input);
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;

do {
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);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);

return output;
}
