
var	lastID = 1024;
var	notifTime = 25;

function __CWGetCurrentEventTarget(e)
{
	var	targ;
	if (!e) e = window.event;
	if ( e.target )
	{
		targ = e.target;
	}
	else if ( e.srcElement )
	{
		targ = e.srcElement;
	}
	if (targ.nodeType==3) // defeat Safari bug
  	{
  		targ = targ.parentNode;
  	}
  	
  	return targ;
}

function __CWCloseAlert(e)
{
	var	targ = __CWGetCurrentEventTarget(e);
	while ( targ )
	{
		var	className = targ.getAttribute("class");
		if ( className == "CWAlertFill" ) break;
		targ = targ.parentNode;
	}
	
	if ( !targ )
		window.console.log( "targ is nil" );
	else
		targ._alert.close();
}

function CWAlert()
{
	lastID++;
	
	this.winID = "CWAlert"+lastID;
	this.win = document.createElement("div");
	this.win.setAttribute( "class", "CWAlertFill" );
	this.win.setAttribute( "id", this.winID );
	this.win.style.opacity = 0;
	this.win.style.filter = 'alpha(opacity=' + 0 + ')';
	this.win._alert = this;
	this.win.onclick = __CWCloseAlert;

	document.body.appendChild( this.win );
	
	this.alertWinID = "CWAlertWIN"+lastID;
	this.alertWin = document.createElement("div");
	this.alertWin.setAttribute( "class", "CWAlertWindowFill" );
	this.alertWin.setAttribute( "id", this.alertWinID );

	this.show = _CWAlertShow;
	this.close = _CWAlertHide;

}

function _CWSetObjectOpacity(aID, opacity)
{
	var	obj = document.getElementById(aID);
	obj.style.opacity = opacity/10;
	obj.style.filter = 'alpha(opacity=' + opacity*10 + ')';
}

function __CWShowAlertWin(aID)
{
	var	obj = document.getElementById(aID);
	var	myAlert = obj._alert;
	
	obj.appendChild( myAlert.alertWin );
}

function _CWAlertShow()
{
	for (var i=0;i<10;i++)
	{
		if ( i == 9 )
			setTimeout('__CWShowAlertWin(\"'+this.winID+'\")',notifTime*i);
		else
			setTimeout('_CWSetObjectOpacity(\"'+this.winID+'\",'+i+')',notifTime*i);
	}
}



function __CWRemoveWin(aID)
{
	var	obj = document.getElementById(aID);
	document.body.removeChild(obj);
}

function _CWAlertHide()
{
	for (var i=9;i>=0;i--)
	{
		if ( i == 0 )
			setTimeout('__CWRemoveWin(\"'+this.winID+'\")',notifTime*(9-i));
		else
			setTimeout('_CWSetObjectOpacity(\"'+this.winID+'\",'+i+')',notifTime*(8-i));
		
	}
}





