


//class Action
//{
   function Action( pointCursorTarget, sTitle, sText, oExternalActionPlayer, iDelay ) 
   {
      this.pointCursorTarget                 = pointCursorTarget;   
      this.sText                             = sText;   
      this.sTitle                            = sTitle;   
      this.oExternalActionPlayer             = oExternalActionPlayer;   
      this.iDelay                            = iDelay;   
   }
   Action.prototype.getCursorTargetPoint                 = function(){ return this.pointCursorTarget; }
   Action.prototype.getTitle                             = function(){ return this.sTitle; }
   Action.prototype.getText                              = function(){ return this.sText; }
   Action.prototype.getExternalActionPlayer              = function(){ return this.oExternalActionPlayer; }
   Action.prototype.getDelay                             = function(){ return this.iDelay; }
//}

//class MessageWindow
//{

   var MessageWindow_HEADER_COLOR         = '#0281C3';

   var MessageWindow_WIDTH                = 290;
   var MessageWindow_HEIGHT               = 200;
   var MessageWindow_HEADER_HEIGHT        = 25;
   
   var MessageWindow_HELP_ICO_WIDTH       = 20;
   var MessageWindow_HELP_ICO_HEIGHT      = 16;
   
   var MessageWindow_HELP_CLOSE_WIDTH     = 24;
   var MessageWindow_HELP_CLOSE_HEIGHT    = 24;

   var MessageWindow_CAPTION_WIDTH        = MessageWindow_WIDTH - 100;
   var MessageWindow_CAPTION_HEIGHT       = MessageWindow_HEIGHT - 8;
   var MessageWindow_SLIDE_INCREMENT      = 10;
   
   var MessageWindow_SLIDE_SPEED          = 4;

   function MessageWindow( oCloseListener, sCaption, oLocationChangeListener )
   {
               
      //window
      this.hWindow = new DynLayer();		
	   this.hWindow.setSize( MessageWindow_WIDTH, MessageWindow_HEIGHT );
	   this.hWindow.setLocation( 0, 0 );
      this.hWindow.setBgColor('#ffffff');
//      this.hWindow.setInnerBorder( 1,'#001C2B' );            	   
      this.hWindow.oLocationChangeListener = oLocationChangeListener;
      
      this.hWindow.addEventListener({
		   onlocationchange:function(e){
			   e.getSource().oLocationChangeListener.locationChanged();   			
		   }
	   });
      
      //end window
      	
      	
      //header	
      this.hHeader = new DynLayer();		
	   this.hHeader.setLocation( 0, 0 );
	   this.hHeader.setSize( MessageWindow_WIDTH, MessageWindow_HEADER_HEIGHT  );
	   this.hHeader.setBgColor( MessageWindow_HEADER_COLOR );      
//      this.hHeader.setInnerBorder( 1,'#001C2B' );            	   
	   this.hHeader.setHTML('&nbsp;');

      this.hHelpIco = new DynLayer();		
	   this.hHelpIco.setLocation( 5, 5 );
	   this.hHelpIco.setSize( MessageWindow_HELP_ICO_WIDTH, MessageWindow_HELP_ICO_HEIGHT );      
	   this.hHelpIco.setBgColor( MessageWindow_HEADER_COLOR );      
	   this.hHelpIco.setHTML('<img src="_xgfx_images_dynapi/help-ico.png">');
      
      this.hHeader.addChild( this.hHelpIco );

      this.hClose = new DynLayer();		
	   this.hClose.setLocation( MessageWindow_WIDTH - MessageWindow_HELP_CLOSE_WIDTH - 5, 0 );
	   this.hClose.setSize( MessageWindow_HELP_CLOSE_WIDTH, MessageWindow_HELP_CLOSE_HEIGHT );      
	   this.hClose.setBgColor( MessageWindow_HEADER_COLOR );      
	   this.hClose.setHTML('<img src="_xgfx_images_dynapi/close.gif">');
	   
      this.hClose.oCloseListener = oCloseListener;
      
      this.hClose.addEventListener({
		   onclick:function(e){
			   e.getSource().oCloseListener.closeClicked();   			
		   }
	   });
                  
      this.hHeader.addChild( this.hClose );
      
      this.hCaption = new DynLayer();		
	   this.hCaption.setLocation( 5 + MessageWindow_HELP_ICO_WIDTH + 10, 4 );
	   this.hCaption.setSize( MessageWindow_CAPTION_WIDTH, MessageWindow_CAPTION_HEIGHT );      
	   this.hCaption.setBgColor( MessageWindow_HEADER_COLOR );      
	   
	   this.setCaption( sCaption );

      this.hHeader.addChild( this.hCaption );

      //end header

      this.hWindow.addChild( this.hHeader ); 
      
      this.hText = new DynLayer();		
	   this.hText.setLocation( 0, MessageWindow_HEADER_HEIGHT );
	   this.hText.setSize( MessageWindow_WIDTH, MessageWindow_HEIGHT - MessageWindow_HEADER_HEIGHT );
  //    this.hText.setInnerBorder( 1,'#001C2B' );            	   
	   this.hText.setBgColor('#ffffff');      

      
      this.hWindow.addChild( this.hText ); 
            
      DragEvent.enableDragEvents( this.hWindow );
      DragEvent.setDragBoundary(this.hWindow, {left:5, right:5, top:5, bottom:5});
      
      
      dynapi.document.addChild( this.hWindow );
      
      this.hide();

   }
   
   MessageWindow.prototype.setCaption = function( sCaption )
   { 
      this.hCaption.setHTML( '<font class="tekstbiggerwhitebold">' + sCaption + '</font>' ); 
   }
   
   MessageWindow.prototype.setActionText = function( sTitle, sText )
   { 
      var sRes = '<table width="100%" height="100%" border="1" borderColor="#C0C0C0" cellPadding="3" cellSpacing="0" style="BORDER-COLLAPSE: collapse"  bordercolorlight="#C0C0C0" bordercolordark="#C0C0C0">';
      sRes += '<tr><td valign="top">';
      sRes += '<table cellspacing=15><tr><td class="tekstbiggerbold">' + sTitle + '</td></tr><tr><td class="tekst">' + sText + '</td></tr></table>';
      sRes += '</td></tr>';
      sRes += '</table>';
      
      this.hText.setHTML( sRes );
   }
   
   MessageWindow.prototype.show = function()
   {
      this.hWindow.setVisible( true );
   }

   MessageWindow.prototype.hide = function()
   {
      this.hWindow.setVisible( false );
   }
   
   MessageWindow.prototype.setLocation = function( oPoint )
   {
      this.hWindow.setLocation( oPoint.getX(), oPoint.getY() );
   }
   
   MessageWindow.prototype.slideTo = function( oPoint, oEndListener )
   {
      this.hWindow.slideTo( oPoint.getX(), oPoint.getY(), MessageWindow_SLIDE_INCREMENT, MessageWindow_SLIDE_SPEED );
      
     	   
   }
   
   MessageWindow.prototype.getWidth = function()
   {
      return this.hWindow.getWidth();
   }
   
   MessageWindow.prototype.getMainWindow = function()
   {
      return this.hWindow;
   }
   

//}

//class ActionPlayer 
//{
   function ActionPlayer( pointOrigin, aActions, sCaption, pointStartSlide )
   {
      this.pointOrigin     = pointOrigin;
      this.aActions        = aActions;
      this.oMessageWindow  = new MessageWindow( this, sCaption, this ); 
      this.bSlidingMessageWindow = false;
      this.bSlidingArrow      = false;
      this.iCurrentActionNr   = 0;
      this.oCurrentAction     = null;
      this.bStartingSlide     = false;
      this.bIsPlaying         = false;

      
      
      this.oStartPoint = this.getOriginPoint().clone();
      //this.getStartPoint().translate( new Point( - this.getMessageWindow().getWidth(), 0 ) );      
      
      this.oStartSlidePoint = this.getStartPoint().clone();
      this.oStartSlidePoint.translate( pointStartSlide );


      this.arrow =new DynLayer(null,0,0,25,25);
	   dynapi.document.addChild(this.arrow);
	   this.arrow.setHTML('<img src="_xgfx_images_dynapi/arrow.gif">');
	   this.arrow.setVisible(false);
	   this.arrow.MyParent = this;
	   
	   
      this.arrow.addEventListener({
		   onlocationchange:function(e){
			   e.getSource().MyParent.arrowLocationChange();   			
		   }
	   });

      this.oMessageWindow.hWindow.MyParent = this;

	   this.oMessageWindow.hWindow.addEventListener ({
   	
		   ontimer:function(e)
		   {
			   e.getSource().MyParent.timerStopped();
   	
		   }
   	
	   });


      
   }
   
   ActionPlayer.prototype.getOriginPoint        = function(){ return this.pointOrigin; }
   ActionPlayer.prototype.getStartPoint         = function(){ return this.oStartPoint; }
   ActionPlayer.prototype.getActions            = function(){ return this.aActions; }   
   ActionPlayer.prototype.getMessageWindow      = function(){ return this.oMessageWindow; }   
   
   
   

   ActionPlayer.prototype.locationChanged = function()
   {
      if( this.bSlidingMessageWindow )
      {
         if( 
               ( this.getMessageWindow().getMainWindow().getX() == this.getStartPoint().getX() ) 
               &&
               ( this.getMessageWindow().getMainWindow().getY() == this.getStartPoint().getY() ) 
           )
           {
               this.bSlidingMessageWindow = false;
                              
               this.getMessageWindow().hide();                    
               this.arrow.setVisible( false );
               
               this.bIsPlaying            = false;

           }
      }
      else if( this.bStartingSlide )      
      {
         if( 
               ( this.getMessageWindow().getMainWindow().getX() == this.oStartSlidePoint.getX() ) 
               &&
               ( this.getMessageWindow().getMainWindow().getY() == this.oStartSlidePoint.getY() ) 
           )
           {
               this.bStartingSlide = false;
                              
               this.nextAction(); 
           }
         
      }
      
   }

   ActionPlayer.prototype.arrowLocationChange = function()
   {

      if( this.bSlidingArrow )
      {
         if( 
               ( this.arrow.getX() == this.pointCurrentArrowTarget.getX() ) 
               &&
               ( this.arrow.getY() == this.pointCurrentArrowTarget.getY() ) 
           )
           {
               
               this.bSlidingArrow         = false;
               var oExternalActionPlayer  = this.oCurrentAction.getExternalActionPlayer();
               
               if( oExternalActionPlayer != null )          
                  oExternalActionPlayer.play();
               
               
               this.oMessageWindow.hWindow.startTimer( 1000 );
               
           }
           
      }
   }
      
   ActionPlayer.prototype.closeClicked  = function()
   {      
      this.bSlidingMessageWindow = true;
      this.getMessageWindow().slideTo( this.getStartPoint() );
   }
   
   ActionPlayer.prototype.isPlaying  = function()
   {      
      return this.bIsPlaying;
   }


   
   ActionPlayer.prototype.play = function()
   {
      this.bIsPlaying      = true;
      
      this.getMessageWindow().show();                        
      this.getMessageWindow().setLocation( this.getStartPoint() );

      this.arrow.setVisible(true);
      this.arrow.setLocation( this.getStartPoint().getX(), this.getStartPoint().getY() );

      if( ! this.oStartSlidePoint.equals( this.getStartPoint() ) )
      {
         this.bStartingSlide = true;      
         this.getMessageWindow().slideTo( this.oStartSlidePoint );      
      }
      else
      {
         this.nextAction(); 
      }
                                                          
   }
   
   ActionPlayer.prototype.nextAction = function()
   {
      if( ! this.isPlaying() ) 
         return;
      
      var aActions = this.getActions();
      
      if( this.iCurrentActionNr == aActions.length )
      {
         this.iCurrentActionNr = 0;
         this.closeClicked();         
      }
      else
      {
         
         this.oCurrentAction = aActions[ this.iCurrentActionNr ];
         
         this.getMessageWindow().setActionText( this.oCurrentAction.getTitle(), this.oCurrentAction.getText() );                           
                                    
         this.pointCurrentArrowTarget = this.oCurrentAction.getCursorTargetPoint().clone();
         this.pointCurrentArrowTarget.translate( new Point( - this.arrow.getWidth(), - this.arrow.getHeight() ) );
                                    
         var x =  this.pointCurrentArrowTarget.getX();
         var y =  this.pointCurrentArrowTarget.getY();
                  
         
         this.iCurrentActionNr++;
         this.bSlidingArrow = true;
         this.arrow.slideTo( x, y, 4, 10 );         
         
         
      }
   }
   
   ActionPlayer.prototype.timerStopped = function()
   {
      var iDelay                 = this.oCurrentAction.getDelay();               
      
      var iTicks                 = this.oMessageWindow.hWindow.getTickCount();
            
      if( iTicks >= iDelay )
      { 
         this.oMessageWindow.hWindow.resetTickCount();
         this.oMessageWindow.hWindow.stopTimer();
         var oExternalActionPlayer  = this.oCurrentAction.getExternalActionPlayer();
         if( oExternalActionPlayer != null )          
            oExternalActionPlayer.unplay();
    
         this.nextAction();            
      }
   }   
   
//}


