// JavaScript functions to access ANSYS animations for report
// "flexion_report.html" created on Mon Dec 15 14:51:22 Paris, Madrid 2003 

// The SlideShow constructor
// function SlideShow(animPath, animName, animTitle, animWidth, animHeight, animFrames, animTime, animDirect)
//   animPath    -  This is the path relative to the location of this 
//                  document it
//                  is a string and so must be wrapped with single quotes.
//   animName    -  The object name is passed in as a string and so must be 
//                  wrapped with single quotes.
//   animTitle   -  The title to show for this animimation sequence. This
//                  is a string and so must be wrapped with single quotes.
//                  It can include HTML tags around the text as well.
//   animWidth   -  The width of the figures used for the animation.
//   animHeight  -  The height of the figures used for the animation.
//   animFrames  -  The number of animation sequences to show.
//   animTime    -  The time delay (mili-seconds) between displays of animation 
//                  frames.  This value is limited by machine performance and 
//                  the slide show will wait for every slide to show regardless 
//                  of how small this value is set to.
//   animDirect  -  The direction of play:
//                     'forward'  - When the last frame is played continues
//                                  to the first frame and increments.
//                     'back'     - When the last frame is played continues
//                                  to the previous frame and decrements until
//                                  the first frame is played then increments
//                                  again.
//
function SlideShow(animPath, animName, animTitle, animWidth, animHeight, animFrames, animTime, animDirect)
{
   // Initialize object properties

   // Set the status to prevent annoying flashes only works in IE though
   // Netscape seems to ignore it for the most part.
   if (window.defaultStatus == "") {
      window.defaultStatus = 'ANSYS Analysis Report';
   }

   // Set browser-determined global variables
   this.ns4 = (document.layers ? true : false);
   this.ie4 = (document.all ? true : false);
   if (this.ns4) {
      //this.print = nsPrint;
      // for now we will just set printing true
      this.print = true;
   } else {
      this.print = true;
   }

   // These are used by the animator
   this.animActive = 0;
   this.animTitle = animTitle;
   this.animFrames = animFrames;
   this.animHeight = animHeight;
   this.animName = animName;
   this.animPictName = 'Pic_' + animName;
   this.animOffset = 1;
   this.animPath = animPath;
   this.animWidth = animWidth;
   this.curSlide = 0;
   this.imgLoaded = 1;
   if (animDirect == 'back') {
      this.showDirection = 1;
   } else {
      this.showDirection = 0;
   }
   this.showIncrement = 1;
   this.showSpeed = animTime;
   this.btnWidth = 34;
   this.btnHeight = 18;

   this.playup = new Image (this.btnWidth,this.btnHeight);
   this.playup.src = "anim_images/playbtnup34x18.png";
   this.playdown = new Image (this.btnWidth,this.btnHeight);
   this.playdown.src = "anim_images/playbtndown34x18.png";
   this.playactive = new Image (this.btnWidth,this.btnHeight);
   this.playactive.src = "anim_images/playbtnactive34x18.png";
   this.playButton = 'Picbtn_' + animName;
   this.pauseButton = 'Pausebtn_' + animName;
   this.pauseup = new Image (this.btnWidth,this.btnHeight);
   this.pauseup.src = "anim_images/pausebtnup34x18.png";
   this.pausedown = new Image (this.btnWidth,this.btnHeight);
   this.pausedown.src = "anim_images/pausebtndown34x18.png";
   this.pauseactive = new Image (this.btnWidth,this.btnHeight);
   this.pauseactive.src = "anim_images/pausebtnactive34x18.png";

   var index = '';

   // Set the current slide to the last animation frame
   this.curSlide = this.animFrames - 1;

   // Create the slide show region using a table this includes:
   //    an image
   //    a title          playButton stopButton
   //
   document.writeln('<TABLE COLS=2 WIDTH="' + this.animWidth + '"><TR>');
   document.writeln('<TD VALIGN=TOP COLSPAN="2" \
      HEIGHT="' + this.animHeight + '">');
   document.writeln('<CENTER>');
   document.writeln('<IMG NAME="' + this.animPictName + '" \
      SRC="' + this.animPath + 'frame' + this.curSlide + '.png">');
   document.writeln('</CENTER>');
   document.writeln('</TD>');
   document.writeln('</TR>');
   document.writeln('<TR><TD VALIGN=TOP>');
   document.writeln('<B>' + this.animTitle + '</B>');
   document.writeln('</TD>');
   document.writeln('<TD VALIGN=TOP>');
   document.writeln('<DIV ALIGN=RIGHT><FORM>');
   document.writeln('<IMG SRC="' + this.playup.src + '" \
      WIDTH="' + this.btnWidth + '" \
      HEIGHT="' + this.btnHeight + '" \
      BORDER="0" \
      NAME="' + this.playButton + '" \
      ONMOUSEDOWN="javascript: ' + this.animName + '.buttonPressed(1)" \
      ONMOUSEUP="javascript: ' + this.animName + '.buttonReleased(1)">');
   document.writeln('<IMG SRC="' + this.pauseactive.src + '" \
      WIDTH="' + this.btnWidth + '" \
      HEIGHT="' + this.btnHeight + '" \
      BORDER="0" \
      NAME="' + this.pauseButton + '" \
      ONMOUSEDOWN="javascript: ' + this.animName + '.buttonPressed(0)" \
      ONMOUSEUP="javascript: ' + this.animName + '.buttonReleased(0)">');
   document.writeln('</FORM></DIV></TD></TR></TABLE>');
   //
}

// call as - listPropertyNamesValues(obj,"objName");
function listPropertyNames(obj, objName) {
   var undefined;
   var names = "";
   var j = 0;
   if (objName == undefined) {
      for (var i in obj) {
         names += i + "\n";
         if (j > 10) {
            alert(names);
            names = "";
            j = 0;
         }
         j++;
      }
      alert(names);
   } else {
      for (var i in obj) {
         names += i + " value = " + eval(objName + '.' + i) + "\n";
         if (j > 10) {
            alert(names);
            names = "";
            j = 0;
         }
         j++;
      }
      alert(names);
   }
}
SlideShow.prototype.listPropertyNames = listPropertyNames;

// Function to change slides
function changeSlide() {
   if (this.imgLoaded) {
      this.imgLoaded = 0;
      eval ('document.' + this.playButton + '.src = "' + this.playactive.src + '"');
      eval ('document.' + this.pauseButton + '.src = "' + this.pauseup.src + '"');
   offset = this.animOffset;
	// If the motion is back and forth we check to see if we need to change the
   // direction
   if (this.showDirection) {
      // We want to decrement if we hit the end
	   this.showIncrement = (this.curSlide + (offset*this.showIncrement) < 0 ? 1 : (this.curSlide + (offset*this.showIncrement) == this.animFrames ? -1 : this.showIncrement));
      offset = this.showIncrement * offset;
   }
	// Calculate the next slide index number
	this.curSlide = (this.curSlide + offset < 0 ? this.animFrames - 1 : (this.curSlide + offset == this.animFrames ? 0 : this.curSlide + offset));

	// Show the next slide
   // Netscape requires the document. is used.
   eval ('document.' + this.animPictName + '.src = "' + this.animPath + 'frame' + this.curSlide + '.png' + '"');
   localObj = new Function (this.animName + '.setImgLoaded()');
   eval ('document.' + this.animPictName + '.onload = ' + localObj);
   } else {
      // Do nothing just return
   }
}
SlideShow.prototype.changeSlide = changeSlide;

function setImgLoaded() {
   this.imgLoaded = 1;
}
SlideShow.prototype.setImgLoaded = setImgLoaded;



function setImgLoaded() {
   this.imgLoaded = 1;
}
SlideShow.prototype.setImgLoaded = setImgLoaded;

function animateSeq(anim) {
	var undefined;
   if (anim) {
      if (!this.animActive) {
         // Begin the animation
         this.animActive = 1;
         this.auto = setInterval(this.animName + '.changeSlide()', this.showSpeed);
         this.imgLoaded = 1;
      }
   }
   if (anim == 0) {
      // Stop the animation
	     if (this.animActive) {
         this.animActive = 0;
         clearInterval(this.auto);
         this.imgLoaded = 1;
      }
   }
}
SlideShow.prototype.animateSeq = animateSeq;

// START OF BUTTON EVENT FUNCTION

function buttonPressed(val) {
   if (val == 0) {
      eval ('document.' + this.pauseButton + '.src = "' + this.pausedown.src + '"');
   } else {
      eval ('document.' + this.playButton + '.src = "' + this.playdown.src + '"');
   }
}
SlideShow.prototype.buttonPressed = buttonPressed;

function buttonReleased(val) {
   if (val == 0) {
      eval ('document.' + this.pauseButton + '.src = "' + this.pauseactive.src + '"');
      eval ('document.' + this.playButton + '.src = "' + this.playup.src + '"');
   } else {
      eval ('document.' + this.playButton + '.src = "' + this.playactive.src + '"');
      eval ('document.' + this.pauseButton + '.src = "' + this.pauseup.src + '"');
   }
   eval (this.animName + '.animateSeq(val)');
}
SlideShow.prototype.buttonReleased = buttonReleased;
// START OF ANIMATION FUNCTIONS  

function animseq_1 (animTitle,animTime, animDirect) {
   var undefined;
   // jobname = 'flexion'
   if (animTitle == undefined) {
      animTitle = 'Deformed_Shape';
   }
   if (animTime == undefined) {
      animTime = 500;
   }
   if (animDirect == undefined) {
      animDirect = 'back';
   }
   animseq1 = new SlideShow('animseq_1/','animseq1',animTitle,586,440,10,animTime,animDirect);
}

function animseq_2 (animTitle,animTime, animDirect) {
   var undefined;
   // jobname = 'flexion'
   if (animTitle == undefined) {
      animTitle = 'flexion Animation 2';
   }
   if (animTime == undefined) {
      animTime = 500;
   }
   if (animDirect == undefined) {
      animDirect = 'back';
   }
   animseq2 = new SlideShow('animseq_2/','animseq2',animTitle,588,442,10,animTime,animDirect);
}

function animseq_3 (animTitle,animTime, animDirect) {
   var undefined;
   // jobname = 'flexion'
   if (animTitle == undefined) {
      animTitle = 'flexion Animation 3';
   }
   if (animTime == undefined) {
      animTime = 500;
   }
   if (animDirect == undefined) {
      animDirect = 'back';
   }
   animseq3 = new SlideShow('animseq_3/','animseq3',animTitle,590,444,10,animTime,animDirect);
}
