RSSLoader = function(url) {
	var yahooPipe = "http://pipes.yahoo.com/pipes/9oyONQzA2xGOkM4FqGIyXQ/run?&_render=JSON&_callback=RSSLoader.processor&feed=";
	
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement("script");
	
	newScript.type = "text/javascript";
	newScript.src = yahooPipe + url;
	headID.appendChild(newScript);
};

RSSLoader.processor = function(feed) {
	var text = "";
	
	text = "<h1>" + feed.value.title + "</h1><br />\n";
	for (var i = 0; i < feed.value.items.length; i++) {
		text += "<a href='" + feed.value.items[i].link + "'>" + feed.value.items[i].title + "</a><br />";
	}
	
	$("rss").update(text);
};

var onloadHandlers = Array();

function addOnloadHandler(handler) {
	if (handler != null) {
		onloadHandlers.add(handler);
	}
};

function onloadHandler() {
	// Add the popup windows:
	
	new PopupWindow("popup", null, null, "600px", "400px", "Popup", 50).makeDraggable().makeResizable().hide();
	
	$('popup').hide();
	
	//new PopupWindow("widgetDeployer", null, null, "600px", "400px", "Widget deployer").hide();//.makeResizable();
	
	// Replace all widget holders with actual widgets:
	Widget.replaceAll(document.getElementsByName("widget"));
	
	//$("jsonTest", "jsonTest2", "jsonTest3", "jsonTest4").on("focus", function() { $(this).resizeTo(300, 50, 300, Tween.bounceOut, 60); }).on("blur", function() { $(this).resizeTo(100, 20, 300, Tween.bounceOut, 60); });
	
	//RSSLoader("http://feeds.dzone.com/dzone/frontpage");
	
	// Call each onload handler:
	for (var i = 0; i < onloadHandlers.length; i++) {
		onloadHandlers[i]();
	}
};

jsonHandler = function(response) {
	var json = JSON.parse(response);
	
	// Check if error:
	if (json.error != "") {
		Debugger.write("JSON error: \"" + json.error + "\"!").show();
	}
	
	// Set the JSON test input element value through JSON:
	document.getElementById("jsonTest").value = json.result[0].name;
	
	// Call the "say" function of each JSON object:
	for (var i = 0; i < json.result.length; i++) {
		json.result[i].say();
	}
};

window.onload = onloadHandler;
