/*
 * PrettyDigg 0.1.1
 * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com, http://blog.nihilogic.dk/
 * MIT License [http://www.opensource.org/licenses/mit-license.php]
 */

var strAPIKey = "http://www.lefthandedtoons.com";
var bProxy = true;

function sendRequest(strEndpoint, oContent, fncCallback) {
	var strURL = "http://" + 
		(bProxy ? ("digg.com/tools/services?endPoint=" + encodeURIComponent(strEndpoint) + "&") : ("services.digg.com" + strEndpoint + "/?"))
		+ "type=javascript"
		+ "&appkey=" + encodeURIComponent(strAPIKey)
		+ "&callback=" + encodeURIComponent(fncCallback)
		//+ "&time=" + new Date().getTime();

	if (oContent) {
		for (var a in oContent) {
			if (oContent.hasOwnProperty(a)) {
				strURL += "&" + a + "=" + encodeURIComponent(oContent[a]);
			}
		}
	}

	var oScript = document.createElement("script");
	oScript.setAttribute("type", "text/javascript");
	document.body.appendChild(oScript);
	oScript.src = strURL;
}

//Digg.prototype.callMethod  = function(strMethod, oContent, fncCallback) {
//			sendRequest(strMethod, oContent, fncCallback);
		//}

function onStoryFound(res) 
{
	if( res.stories && res.stories[0] )
	{	
		document.getElementById('diggbutton').style.display = "block";
	}
}

function loadDigg(link)
{
    sendRequest('/stories', {"link" : link}, "onStoryFound");
}
