function Alert(parentElement)
{
	if (parentElement)
	{
		this.ParentElement = parentElement;
		this.IconElement = this.ParentElement.children[0];
		System.ClassList.Remove(this.ParentElement, "uwt-disabled");

		if (this.IconElement != null)
		{
			this.IconElement.NativeObject = this;
			this.IconElement.addEventListener("click", function()
			{
				if (System.ClassList.Contains(this.NativeObject.ParentElement, "uwt-collapsible"))
				{
					System.ClassList.Toggle(this.NativeObject.ParentElement, "uwt-collapsed");
				}
			});
		}
	}

	this.mvarID = "";
	this.setID = function(value)
	{
		this.mvarID = value;
	};
	this.getID = function()
	{
		return this.mvarID;
	};

	this.mvarTitle = "";
	this.setTitle = function(value)
	{
		this.mvarTitle = value;
	};
	this.getTitle = function()
	{
		return this.mvarTitle;
	}
	
	this.mvarContent = "";
	this.setContent = function(value)
	{
		this.mvarContent = value;
	};
	this.getContent = function()
	{
		return this.mvarContent;
	};
	
	this.mvarCssClass = "";
	this.setCssClass = function(value)
	{
		this.mvarCssClass = value;
	};
	this.getCssClass = function()
	{
		return this.mvarCssClass;
	};
	
	this.mvarTimeout = -1;
	this.setTimeout = function(value)
	{
		this.mvarTimeout = value;
	}
	this.getTimeout = function()
	{
		return this.mvarTimeout;
	};
	
	this.mvarParentElement = null;
	this.show = function(timeoutInMilliseconds)
	{
		//!FIXME: this needs to track which alerts have timeouts, and cancel them if they are re-shown
		var element = null;
		if (this.mvarID != "")
		{
			var existing = document.getElementById("uwt_alert__" + this.mvarID);
			if (typeof(existing) !== "undefined")
			{
				element = existing;
			}
		}
		if (element === null)
		{
			element = document.createElement("div");
		}
		element.innerHTML = "";
		
		if (this.mvarID != "")
		{
			element.id = "uwt_alert__" + this.mvarID;
		}

		var cssClass = "uwt-alert";
		if (this.getCssClass() != "") cssClass += " " + this.getCssClass();
		element.className = cssClass;
		element.ObjectReference = this;
		
		element.addEventListener("click", function(e)
		{
			this.ObjectReference.hide();
		});
		
		this.mvarParentElement = element;
		
		var elemTitle = document.createElement("div");
		elemTitle.className = "uwt-title";
		elemTitle.innerHTML = this.getTitle();
		element.appendChild(elemTitle);
		
		var elemContent = document.createElement("div");
		elemContent.className = "uwt-content";
		elemContent.innerHTML = this.getContent();
		element.appendChild(elemContent);
		

		if (Alert.AlertContainer === null)
		{
			Alert.AlertContainer = document.createElement("div");
			Alert.AlertContainer.className = "uwt-alert-container";
			document.body.appendChild(Alert.AlertContainer);
		}
		Alert.AlertContainer.appendChild(element);
		cssClass += " uwt-visible";
		
		// timeout required to see the transition when first adding the element to the page
		window.setTimeout(function()
		{
			element.className = cssClass;
		}, 50);
		
		if (typeof(timeoutInMilliseconds) !== "undefined")
		{
			window.setTimeout(function(sender)
			{
				sender.hide();
			}, timeoutInMilliseconds, this);
		}
		else if (typeof(this.mvarTimeout) !== "undefined")
		{
			window.setTimeout(function(sender)
			{
				sender.hide();
			}, this.mvarTimeout, this);	
		}
	};
	this.hide = function()
	{
		System.ClassList.Remove(this.mvarParentElement, "uwt-visible");
	};
}

Alert.AlertContainer = null;

Alert.show = function(content, title, cssClass, timeoutInMilliseconds, id)
{
	var n = new Alert();
	if (typeof(id) !== "undefined")
	{
		n.setID(id);
	}
	
	if (typeof(content) === "undefined")
	{
		console.warn("showing notification with empty content");
		content = "";
	}
	n.setContent(content);
	
	if (typeof(title) === "undefined")
	{
		console.warn("showing notification with empty title");
		title = "";
	}
	n.setTitle(title);
	
	if (typeof(cssClass) === "undefined") cssClass = "";
	n.setCssClass(cssClass);
	
	if (typeof(timeoutInMilliseconds) !== "undefined")
	{
		n.setTimeout(timeoutInMilliseconds);
	}
	
	n.show();
};

window.addEventListener("load", function()
{
	var items = document.getElementsByClassName("uwt-alert");
	for (var i = 0; i < items.length; i++)
	{
		items[i].NativeObject = new Alert(items[i]);
	}

	window.setTimeout(function()
	{
		var items = document.getElementsByClassName("uwt-alert");
		for (var i = 0; i < items.length; i++)
		{
			if (!System.ClassList.Contains(items[i], "uwt-alert-sticky"))
			{
				items[i].style.right = "-2000px";
			}
		}
	}, 5000);

});
