﻿
function StatusBar(containerID)
{
	var containerObject = document.getElementById(containerID);
	
	this._messages = new Array();
	this._isShowingMessages = false;
	this._showTimerID = 0;
	
	this._messageContainer = document.createElement("DIV");
	this._messageContainer.className = "TopMenuNotification";
	this._messageContainer.style.display = "none";
	containerObject.appendChild(this._messageContainer);
	
}

function StatusBar_AddMessage(iconUrl, text, displayTimeMS, notificationSound)
{
	var message = new Object();
	message.IconUrl = iconUrl;
	message.Text = text;
	message.DisplayTimeMS = displayTimeMS;
	message.NotificationSound = notificationSound;
	
	this._messages.push(message);
	
	if (!this._isShowingMessages)
		this.ShowMessages();
}

function StatusBar_BuildMessage(message)
{
//	var html = "<table cellpadding='0' cellspacing='0'><tr>";
//	
//	if (message.IconUrl != null && message.IconUrl != "")
//		html = html + "<td valign='middle'><img src='" + unescape(message.IconUrl) + "' style='padding-right: 5px' />";
//
	//	html = html + "<td>" + unescape(message.Text) + "</td></tr></table>";
	var html = "<div class='status-message'><div class='status-content'><span class='status-icon'>";
	html = html + unescape(message.Text);
	html = html + "</span></div></div>";
	this._messageContainer.innerHTML = html;
}

function StatusBar_ShowMessages()
{
	if (this._messages.length == 0)
	{
		this._isShowingMessages = false;
		this._messageContainer.style.display = "none";
		return;
	}
	
	this._isShowingMessages = true;
	
	this._messageContainer.style.display = "block";
	var message = this._messages.shift();
	this.BuildMessage(message);

	if (message.NotificationSound > 0)
		this.PlaySound(message.NotificationSound);
	
	var instance = this;
	this._showTimerID = setTimeout( function(){instance.ShowMessages();}, message.DisplayTimeMS);
}

function StatusBar_GetFlashObject(movieName)
{
	if (window.document[movieName]) 
	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName]; 
	}
	else
		return document.getElementById(movieName);
}

function StatusBar_PlaySound ( soundID, tryCount )
{
	var soundplayer = this.GetFlashObject ( "Sounds" );

	if ( soundplayer != null )
	{
		try
		{
			if (typeof(soundplayer.Rewind) == 'undefined')
			{
				if (typeof(tryCount) == 'undefined')
					tryCount = 0;
				else if (tryCount > 10)
					return;
				
				var instance = this;
				setTimeout ( function(){instance.PlaySound(soundID, tryCount++); }, 500 );
			}
			else
			{
				soundplayer.Rewind ();
				soundplayer.GotoFrame ( soundID );
			}
		}
		catch (ex)
		{
		}
	}
}

StatusBar.prototype.BuildMessage = StatusBar_BuildMessage;
StatusBar.prototype.AddMessage = StatusBar_AddMessage;
StatusBar.prototype.ShowMessages = StatusBar_ShowMessages;
StatusBar.prototype.GetFlashObject = StatusBar_GetFlashObject;
StatusBar.prototype.PlaySound = StatusBar_PlaySound;
