// ==UserScript==
// @name           Dojo Integration Test
// @namespace      test
// @description    Proof Of Concept To Integrate Dojo And Greasemonkey
// @include        *
// ==/UserScript==


//Include Dojo from the AOL CDN
var script = document.createElement('script');
script.src="http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js";
document.getElementsByTagName('head')[0].appendChild(script);

//Include the Tundra Theme CSS file
var link = document.createElement('link');
link.rel = "stylesheet";
link.type= "text/css";
link.href="http://o.aolcdn.com/dojo/1.0.0/dijit/themes/tundra/tundra.css";
document.getElementsByTagName('head')[0].appendChild(link);

//Wait until everything is loaded before trying to do anything
window.addEventListener('load', function(event) {
	var dojo = unsafeWindow["dojo"];
	dojo.require("dijit.Dialog");

	//Don't do anything until "Dijit.Dialog" has been loaded
	dojo.addOnLoad(function(){
		var dijit = unsafeWindow["dijit"];
		dojo.addClass(document.getElementsByTagName('body')[0], "tundra");
		
		//Create The Div Element For the Dialog
		var pane = document.createElement('div');
		pane.id = "floatingPane";
		pane.innerHTML="Dojo Lives… In GreaseMonkey!";
		document.getElementsByTagName('body')[0].appendChild(pane);

		//Actually Create The Dialog
		dialog = new dijit.Dialog({
			title: "Dojo Integration Test"
		},pane);
		dialog.show();
	});
}, 'false');

