function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			func();
			oldonload();
		}
	}
}
var evergreen = {
	addWidget : function(o)
	{
		// embed a marker element so we can find this specific position in the DOM
		var id = "evergreen"+Math.round(Math.random()*1000000000);
		document.write("<div id='"+id+"' class='evergreenbox'></div>");
		
		// curry the embed context into a closure specific to this widget
		var attemptEmbed = function(){
			var el = document.getElementById(id);
			if (!el) return false;
			var hint = o.hint ? o.hint(el) : '';
			if ( o.hint && !hint ) return false;
			var h = o.height||100, w = o.width||100;
			el.innerHTML = "<iframe src='http://evergreen.empora.com/iframe?width="+w+"&height="+h+"&hint="+hint+"&pid="+o.pid+"' style='border:0; height:"+h+"px; width:"+w+"px;overflow:hidden; scroll:none' border='0'></iframe>";
			return true;
		};
		
		// if the hint is already available in the DOM then execute immediately, otherwise add an onload event
		try
		{
			if (!attemptEmbed()) addLoadEvent(attemptEmbed);
		}
		catch(err)
		{
			addLoadEvent(attemptEmbed);
		}
	}
};


