var ShowHide = new ShowHide();
var currentlyShowing;

function ShowHide() {

	this.Show = 'block';
	this.Hide = 'none';
	this.FadeOutTimeoutDefaultDuration = 100;
	this.FadeInTimeoutDefaultDuration = 100;
	this.FadeOutTimeout = null;
	this.FadeInTimeout = null;

	this.HideElement = function(id) {
		this.SetElementDisplay(id, this.Hide);
	}

	this.ShowElement = function(id) {
		this.SetElementDisplay(id, this.Show);
	}

	this.ToggleElementDisplay = function(id) {
		if (currentlyShowing != null && currentlyShowing != id)
			this.SetElementDisplay(currentlyShowing, this.Hide);
		this.SetElementDisplay(id, document.getElementById(id).style.display == this.Show ? this.Hide : this.Show);
		currentlyShowing = id;		
	}

	this.SetElementDisplay = function(id, stateToSet) {
		document.getElementById(id).style.display = stateToSet;
	}

	this.MakeElementVisible = function(id) {
		this.SetElementVisibility(id, 1);
	}

	this.MakeElementInvisible = function(id) {
		this.SetElementVisibility(id, 0);
	}

	this.SetElementVisibility = function(id, visibilityToSet) {
		var elementToSetVisibility = document.getElementById(id);
		elementToSetVisibility.style.opacity = visibilityToSet;
		elementToSetVisibility.style.filter = 'alpha(opacity = ' + visibilityToSet * 100 + ')';
	}

	this.FadeOutElement = function(id, duration) {
		var elementToFadeOut = document.getElementById(id);
		this.SetElementVisibility(id, elementToFadeOut.style.opacity - 0.1);
		if (elementToFadeOut.style.opacity > 0) {
			this.StartFadeOutTimeout(id, duration);
		} else {
			this.StopFadeOutTimeout();
			this.HideElement(id);
		}
	}

	this.StartFadeOutTimeout = function(elementToFadeOut, duration) {
		this.FadeOutTimeout = setTimeout('ShowHide.FadeOutElement(\'' + elementToFadeOut + '\', ' + duration + ');', duration);
	}

	this.StopFadeOutTimeout = function(elementToFadeOut) {
		clearTimeout(this.FadeOutTimeout);
		this.FadeOutTimeout = null;
		if (elementToFadeOut != null)
			this.MakeElementVisible(elementToFadeOut);
	}

	this.FadeInElement = function(id, duration) {
		var elementToFadeIn = document.getElementById(id);
		if (elementToFadeIn.style.display != this.Show) {
			this.SetElementVisibility(id, 0);
			this.ShowElement(id);
		}
		this.SetElementVisibility(id, Number(elementToFadeIn.style.opacity) + 0.1);
		if (elementToFadeIn.style.opacity < 1)
			this.StartFadeInTimeout(id, duration);
	}

	this.StartFadeInTimeout = function(elementToFadeIn, duration) {
		this.FadeInTimeout = setTimeout('ShowHide.FadeInElement(\'' + elementToFadeIn + '\', ' + duration + ');', duration);
	}

	this.StopFadeInTimeout = function(elementToFadeIn) {
		clearTimeout(this.FadeInTimeout);
		this.FadeInTimeout = null;
		if (elementToFadeIn != null)
			this.MakeElementInvisible(elementToFadeIn)
	}

	this.GetMouseLocation = function(e) {
		if (e.pageX)
			tempX = e.pageX;
		else if (e.clientX)
			tempX = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		else
			tempX = 0;
		if (e.pageY)
			tempY = e.pageY;
		else if (e.clientY)
			tempY = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		else
			tempY = 0;
		return new Array(tempX, tempY);
	}

}
