var Notification				= function ( ) 
{
	var self					= this ;
	
	self.base					= BaseClass ;
	self.base( ) ;
	
	var baseInitalise			= self.initalise ;
	self.name					= "Notification" ;
	
	self.control				= null;
	self.headerControl			= null ;
	self.titleControl			= null ;
	self.titleTextControl		= null ;
	self.titleCloseControl		= null ;
	self.titleCloseTextControl	= null ;
	self.contentControl			= null ;
	self.messageControl			= null ;
	self.messageTextControl		= null ;

	self.hideAfter				= 2000 ;
	self.hasFilters				= false ;
	self.speed					= 20 ;
	self.stime					= 2000 ;
	self.autoshow				= false ;

	self.text					= "" ;
	self.message				= "" ;
	self.title					= "" ;
	self.updateTextOnShow		= false ;
	self.attachOnInitalisation	= false ;

	self.childWindowStyle		= "width=400,height=250,scrollbars=yes" ;
	self.childWindowName		= "" ;

	/* probably could be made internal / private */
	self.oldonloadHndlr			= window.onload, self.popupHgt, self.actualHgt, self.tmrId = -1, self.resetTimer ;
	self.titHgt, self.cntDelta, self.tmrHide = -1, self.hideAlpha ;
	self.showBy = null, self.dxTimer = -1, self.popupBottom, self.oldLeft ;
	
	var childWindow				= null ;

	self.oldOnScroll			= window.onscroll ;
	self.windowScroll			= function( )
	{
		if ( self.oldOnScroll != null )
		{
			self.oldOnScroll( ) ;
		}
		if ( self.tmrHide != -1 )
		{
			self.control.style.display	= 'none' ; 
			self.control.style.display	= 'block' ;
		}
	} ;

    self.show				= function( )
    {
		if ( self.dxTimer != -1 )
		{
			self.control.filters.blendTrans.stop( ) ;
		}

		if ( ( self.tmrHide != -1 ) )
		{
			clearInterval( self.tmrHide ) ;
			self.tmrHide		= setInterval( self.espopup_tmrHideTimer , self.hideAfter ) ;
			return ;
		}
		if ( self.tmrId != -1 )
		{
			return ;
		}

		self.control.style.left			= self.oldLeft ;
		self.control.style.top			= '' ;
		self.control.style.filter		= '' ;

		if ( self.tmrHide != -1 )
		{
			clearInterval( self.tmrHide );
			 self.tmrHide		= -1 ;
		}

		self.headerControl.style.display	= 'none' ;
		self.contentControl.style.display	= 'none' ;

		if ( navigator.userAgent.indexOf( 'Opera' ) != -1 )
		{
			self.control.style.bottom		= ( document.body.scrollHeight * 1 - document.body.scrollTop * 1 - document.body.offsetHeight * 1 + 1 * self.popupBottom ) + 'px' ;
		}
      
		if ( self.updateTextOnShow )
		{
			self.updateTextOnShow			= false ;
			
			self.messageControl.innerHTML	= self.message ;
			self.titleControl.innerHTML		= self.title ;
		}

		self.actualHgt			= 0 ;
		self.control.style.height			= self.actualHgt + 'px' ;
		self.control.style.visibility		= '' ;
		if ( !self.resetTimer )
		{
			self.control.style.display	= '' ;
		}
		self.tmrId				= setInterval( self.espopup_tmrTimer , ( self.resetTimer ? self.stime : 20 ) ) ;
    } ;

	self.espopup_winLoad		= function( )
	{
		if ( self.oldonloadHndlr != null && typeof self.oldonloadHndlr == "function" )
		{
			self.oldonloadHndlr( ) ;
		}

		self.oldLeft			= self.control.style.left ;
		self.popupBottom		= self.control.style.bottom.substr( 0 , self.control.style.bottom.length - 2 ) ;

		self.titHgt				= self.headerControl.style.height.substr( 0 , self.headerControl.style.height.length - 2 ) ;
		self.popupHgt			= self.control.style.height ;
		self.popupHgt			= self.popupHgt.substr( 0 , self.popupHgt.length - 2 ) ;
		self.actualHgt			= 0 ; 
		self.cntDelta			= self.popupHgt - ( self.contentControl.style.height.substr( 0 , self.contentControl.style.height.length - 2 ) ) ;

		if ( self.autoshow )
		{
			self.resetTimer		= true ;
			self.show( null ) ;
		}
	} ;

	self.espopup_tmrTimer		= function( )
	{
		if ( self.resetTimer )
		{
			self.control.style.display	= '' ;
			clearInterval( self.tmrId ) ;
			self.resetTimer		= false ;
			self.tmrId			= setInterval( self.espopup_tmrTimer , self.speed ) ;
		}
		self.actualHgt += 5 ;
		if ( self.actualHgt >= self.popupHgt )
		{
			self.actualHgt		= self.popupHgt ;
			clearInterval( self.tmrId ) ;
			self.tmrId			= -1 ;
			self.contentControl.style.display	= '' ;
			if ( self.hideAfter != -1 )
			{
				self.tmrHide	= setInterval( self.espopup_tmrHideTimer , self.hideAfter ) ;
			}
		}
		if ( self.titHgt < self.actualHgt - 6 )
		{
			self.headerControl.style.display	= '' ;
		}
		if ( ( self.actualHgt - self.cntDelta ) > 0 )
		{
			self.contentControl.style.display	= '' ;
			self.contentControl.style.height	= ( self.actualHgt - self.cntDelta ) + 'px' ;
		}
		self.control.style.height			= self.actualHgt + 'px' ;
	} ;
    
	self.espopup_tmrHideTimer	= function( )
	{
		clearInterval( self.tmrHide ) ;
		self.tmrHide			= -1 ;
		if ( self.hasFilters )
		{
			backCnt				= self.contentControl.innerHTML ;
			backTit				= self.headerControl.innerHTML ;
			self.contentControl.innerHTML		= '' ;
			self.headerControl.innerHTML		= '' ;
			self.control.style.filter		= 'blendTrans(duration=1)' ;
			self.control.filters.blendTrans.apply( ) ;
			self.control.style.visibility	= 'hidden' ;
			self.control.filters.blendTrans.play( ) ;
			self.contentControl.innerHTML		= backCnt ;
			self.headerControl.innerHTML		= backTit ;
		    
			self.dxTimer		= setInterval( self.espopup_dxTimer , 1000 ) ;
		}
		else
		{
			self.control.style.visibility	= 'hidden' ;
		}
	} ;
    
	self.espopup_dxTimer		= function( )
	{
		clearInterval( self.dxTimer ) ;
		self.dxTimer			= -1 ;
	} ;
 
	var close					= function( )
	{
		if ( self.tmrId == -1 )
		{
			self.control.style.filter		= '' ;
			self.control.style.display	= 'none' ;
			if ( self.tmrHide != -1 )
			{
				clearInterval( self.tmrHide ) ;
				self.tmrHide	= -1 ;
			}
			if ( self.onClose != null && typeof self.onClose == "function" )
			{
				var result		= self.onClose( ) ;
			}
		}
	} ;

	self.onClose				= function( )
	{
		return					true ;
	} ;

	var showWindow				= function( )
	{
		if ( self.onShowWindow != null && typeof self.onShowWindow == "function" )
		{
			var result			= self.onShowWindow( ) ;
		}

		if ( childWindow != null )
		{
			childWindow.close( ) ;
		}
		childWindow				= window.open( '' , self.childWindowName , self.childWindowStyle + ', menubar=no, resizable=no, status=no, toolbar=no, location=no' ) ;
		if( !childWindow )
		{
			alert( "Popup windows for this site have been disabled.\n\nPlease ensure popup blockers have been disabled for this site." ) ;
		}
		else
		{
			childWindow.document.write( self.text ) ;
		}
	} ;

	self.onShowWindow			= function( )
	{
		return					true ;
	} ;

	var mousemoveBack, mouseupBack ;
	var ofsX, ofsY ;

	self.dragDrop				= function( e )
	{
		mousemoveBack			= document.body.onmousemove ;
		mouseupBack				= document.body.onmouseup ;
		ox						= ( e.offsetX == null ) ? e.layerX : e.offsetX ;
		oy						= ( e.offsetY == null ) ? e.layerY : e.offsetY ;
		self.ofsX				= ox ;
		self.ofsY				= oy ;

		document.body.onmousemove		= self.dragDropMove ;
		document.body.onmouseup			= self.dragDropStop ;
		if ( self.tmrHide != -1 )
		{
			clearInterval( self.tmrHide ) ;
		}
	} ;

	self.dragDropMove			= function( e )
	{
		if ( e == null && event != null)
		{
			self.control.style.left		= ( event.clientX * 1 + document.body.scrollLeft - self.ofsX ) + 'px' ;
			self.control.style.top		= ( event.clientY * 1 + document.body.scrollTop - self.ofsY ) + 'px' ;
			event.cancelBubble	= true ;
		}
		else
		{
			self.control.style.left		=( e.pageX * 1 - self.ofsX ) + 'px' ;
			self.control.style.top		=( e.pageY * 1 - self.ofsY ) + 'px' ;
			e.cancelBubble		= true ;
		}
		if ( ( event.button & 1 ) == 0 )
		{
			self.dragDropStop( ) 
		}
	} ;

	self.dragDropStop			= function( )
	{
		document.body.onmousemove= mousemoveBack;
		document.body.onmouseup= mouseupBack;
	} ;

	self.createControls			= function( )
	{
		self.control			= document.createElement( "div" ) ;
		document.body.appendChild( self.control ) ;

		self.control.style.display				= "none" ;
		self.control.style.background			= "#8fbc8b" ;
		self.control.style.borderRight			= "1px solid #556b2f" ;
		self.control.style.borderBottom			= "1px solid #556b2f" ;
		self.control.style.borderLeft			= "1px solid #329b32" ;
		self.control.style.borderTop			= "1px solid #329b32" ;
		self.control.style.position				= "absolute" ;
		self.control.style.zIndex				= 9999 ;
		self.control.style.width				= "200px" ;
		self.control.style.height				= "100px" ;
		self.control.style.right				= "15px" ;
		self.control.style.bottom				= "15px";
		self.addEvent( self.control , "selectstart" , function(){return false;} ) ;

		self.headerControl		= document.createElement( "div" ) ;
		self.control.appendChild( self.headerControl ) ;

		self.headerControl.style.cursor			= "default" ;
		self.headerControl.style.display		= "none" ;
		self.headerControl.style.position		= "absolute" ;
		self.headerControl.style.left			= "2px" ;
		self.headerControl.style.width			= "194px" ;
		self.headerControl.style.top			= "2px" ;
		self.headerControl.style.height			= "14px" ;
		self.headerControl.style.filter			= "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#FF8fbc8b', EndColorStr='#FFc8dcc8')" ;
		self.headerControl.style.font			= "12px arial,sans-serif" ;
		self.headerControl.style.color			= "#000000" ;
		self.headerControl.style.textDecoration	= "none";

		self.titleControl		= document.createElement( "span" ) ;
		self.headerControl.appendChild( self.titleControl ) ;
		self.titleTextControl	= document.createTextNode( "Interactive help" ) ;
		self.titleControl.appendChild( self.titleTextControl ) ;

		self.titleCloseControl	= document.createElement( "span" ) ;
		self.headerControl.appendChild( self.titleCloseControl ) ;
		self.titleCloseTextControl				= document.createTextNode( "X" ) ;
		self.titleCloseControl.appendChild( self.titleCloseTextControl ) ;
		
		
		self.titleCloseControl.style.position	= "absolute" ;
		self.titleCloseControl.style.right		= "0px" ;
		self.titleCloseControl.style.top		= "0px" ;
		self.titleCloseControl.style.cursor		= "pointer" ;
		self.titleCloseControl.style.color		= "#228b22" ;
		self.titleCloseControl.style.font		= "bold 12px arial,sans-serif" ;
		self.titleCloseControl.style.position	= "absolute" ;
		self.titleCloseControl.style.right		= "3px" ;
		self.addEvent( self.titleCloseControl , "click" , close ) ;
		self.addEvent( self.titleCloseControl , "mousedown" , function(event){event.cancelBubble=true;} ) ;
		self.addEvent( self.titleCloseControl , "mouseover" , function(){self.titleCloseControl.style.color="#556b2f";} ) ;
		self.addEvent( self.titleCloseControl , "mouseout" , function(){self.titleCloseControl.style.color="#228b22";} ) ;

		self.contentControl		= document.createElement( "div" ) ;
		self.control.appendChild( self.contentControl ) ;

		self.contentControl.style.display		= "none" ;
		self.contentControl.style.borderLeft	= "1px solid #228b22" ;
		self.contentControl.style.borderTop		= "1px solid #228b22" ;
		self.contentControl.style.borderBottom	= "1px solid #329b32" ;
		self.contentControl.style.borderRight	= "1px solid #329b32" ;
		self.contentControl.style.background	= "#8fbc8b" ;
		self.contentControl.style.padding		= "2px" ;
		self.contentControl.style.overflow		= "hidden" ;
		self.contentControl.style.textAlign		= "center" ;
		self.contentControl.style.filter		= "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#FF8fbc8b', EndColorStr='#FFc8dcc8')" ;
		self.contentControl.style.position		= "absolute" ;
		self.contentControl.style.left			= "2px" ;
		self.contentControl.style.width			= "194px" ;
		self.contentControl.style.top			= "20px" ;
		self.contentControl.style.height		= "76px" ;
		self.addEvent( self.contentControl , "mousedown" , function(event){event.cancelBubble=true;} ) ;

		self.messageControl		= document.createElement( "a" ) ;
		self.contentControl.appendChild( self.messageControl ) ;
		self.messageTextControl				= document.createTextNode( "Message to show in popup" ) ;
		self.messageControl.appendChild( self.messageTextControl ) ;

		self.messageControl.style.font			= "12px arial,sans-serif" ;
		self.messageControl.style.color			= "#000000" ;
		self.messageControl.style.textDecoration	= "none" ;
		self.addEvent( self.messageControl , "mouseover" , function(){self.messageControl.style.textDecoration="underline";} ) ;
		self.addEvent( self.messageControl , "mouseout" , function(){self.messageControl.style.textDecoration="none";} ) ;
		self.addEvent( self.messageControl , "click" , showWindow ) ;
		self.messageControl.href				= "javascript:var result = true ; " ;
		return					true ;
	} ;

	self.initalise				= function( )
	{
		// Must set the response of this into a variable or the method will itself return true and not continue.
		if ( baseInitalise( ) == false )
		{
			return				false ;
		}
		if ( self.createControls( ) == false )
		{
			return				false ;
		}

		if ( self.attachOnInitalisation )
		{
			self.espopup_winLoad( ) ;
		}
		else
		{
			window.onload		= self.espopup_winLoad ;
		}
		window.onscroll			= self.windowScroll ;
		return					true ;
	} ;

	// Object create OK	
	return						true;
} ;
