// =============================== //
// Animated Window                 //
// v1.0 - Feb 12, 2005             //
// ------------------------------- //
// Written by Lloyd Hassell        //
// Website: lloydhassell.com       //
// Email: lloydhassell@hotmail.com //
// =============================== //

// INITIALIZATION:

animatedWindow = new Object();

// CONFIGURATION:

animatedWindow.startWidth = 100;
animatedWindow.startHeight = 100;

animatedWindow.endWidth = 640;
animatedWindow.endHeight = 480;

animatedWindow.bgColor = '#FF0000';

animatedWindow.increment = 50;

animatedWindow.frameRate = 50;

animatedWindow.posX = 10;
animatedWindow.posY = 10;

animatedWindow.location = false;
animatedWindow.menubar = false;
animatedWindow.resizable = false;
animatedWindow.scrollbars = false;
animatedWindow.status = false;
animatedWindow.toolbar = false;

// MAIN:

animatedWindow.winIndex = 0;
animatedWindow.windows = new Array();

function isBlank(OBJ) {
   if (OBJ == null) OBJ = '';
   OBJ += '';
   var trimList = ' \f\n\r';
   while (OBJ.length > 0 && trimList.indexOf(OBJ.charAt(0)) != -1) OBJ = OBJ.substring(1);
   while (OBJ.length > 0 && trimList.indexOf(OBJ.charAt(OBJ.length - 1)) != -1) OBJ = OBJ.substring(0,OBJ.length - 1);
   return (OBJ == '') ? true : false;
   }

function isBoolean(STR) {
   return (STR == true || STR == false) ? true : false;
   }

function openAnimatedWindow(URL,STARTWIDTH,STARTHEIGHT,ENDWIDTH,ENDHEIGHT,BGCOLOR,INCREMENT,FRAMERATE,POSX,POSY,LOCATION,MENUBAR,RESIZABLE,SCROLLBARS,STATUS,TOOLBAR) {
   if (isBlank(STARTWIDTH)) STARTWIDTH = animatedWindow.startWidth;
   if (isBlank(STARTHEIGHT)) STARTHEIGHT = animatedWindow.startHeight;
   if (isBlank(ENDWIDTH)) ENDWIDTH = animatedWindow.endWidth;
   if (isBlank(ENDHEIGHT)) ENDHEIGHT = animatedWindow.endHeight;
   if (isBlank(BGCOLOR)) BGCOLOR = animatedWindow.bgColor;
   if (isBlank(INCREMENT)) INCREMENT = animatedWindow.increment;
   if (isBlank(FRAMERATE)) FRAMERATE = animatedWindow.frameRate;
   if (isBlank(POSX)) POSX = animatedWindow.posX;
   if (isBlank(POSY)) POSY = animatedWindow.posY;
   if (isBlank(LOCATION)) LOCATION = animatedWindow.location;
   if (isBlank(MENUBAR)) MENUBAR = animatedWindow.menubar;
   if (isBlank(RESIZABLE)) RESIZABLE = animatedWindow.resizable;
   if (isBlank(SCROLLBARS)) SCROLLBARS = animatedWindow.scrollbars;
   if (isBlank(STATUS)) STATUS = animatedWindow.status;
   if (isBlank(TOOLBAR)) TOOLBAR = animatedWindow.toolbar;
   var winFeaturesStr = 'width=' + STARTWIDTH + ',height=' + STARTHEIGHT;
   winFeaturesStr += ',left=' + POSX + ',screenX=' + POSX + ',top=' + POSY + ',screenY=' + POSY;
   if (isBoolean(LOCATION)) winFeaturesStr += (LOCATION) ? ',location=yes' : ',location=no';
   if (isBoolean(MENUBAR)) winFeaturesStr += (MENUBAR) ? ',menubar=yes' : ',menubar=no';
   if (isBoolean(RESIZABLE)) winFeaturesStr += (RESIZABLE) ? ',resizable=yes' : ',resizable=no';
   if (isBoolean(SCROLLBARS)) winFeaturesStr += (SCROLLBARS) ? ',scrollbars=yes' : ',scrollbars=no';
   if (isBoolean(STATUS)) winFeaturesStr += (STATUS) ? ',status=yes' : ',status=no';
   if (isBoolean(TOOLBAR)) winFeaturesStr += (TOOLBAR) ? ',toolbar=yes' : ',toolbar=no';
   var thisWinIndex = animatedWindow.winIndex;
   animatedWindow.winIndex++;
   animatedWindow.windows[thisWinIndex] = new Object();
   animatedWindow.windows[thisWinIndex].winObj = window.open('','',winFeaturesStr);
   animatedWindow.windows[thisWinIndex].winObj.document.bgColor = BGCOLOR;
   animatedWindow.windows[thisWinIndex].winObj.focus();
   animatedWindow.windows[thisWinIndex].frameRate = FRAMERATE;
   animatedWindow.windows[thisWinIndex].url = URL;
   animatedWindow.windows[thisWinIndex].endWidth = ENDWIDTH;
   animatedWindow.windows[thisWinIndex].endHeight = ENDHEIGHT;
   animatedWindow.windows[thisWinIndex].angle = Math.atan2(ENDHEIGHT - STARTHEIGHT,ENDWIDTH - STARTWIDTH);
   animatedWindow.windows[thisWinIndex].distZ = Math.sqrt(Math.pow(ENDHEIGHT - STARTHEIGHT,2) + Math.pow(ENDWIDTH - STARTWIDTH,2));
   animatedWindow.windows[thisWinIndex].incX = Math.cos(animatedWindow.windows[thisWinIndex].angle) * INCREMENT;
   animatedWindow.windows[thisWinIndex].incY = Math.sin(animatedWindow.windows[thisWinIndex].angle) * INCREMENT;
   animatedWindow.windows[thisWinIndex].incZ = INCREMENT;
   animatedWindow.windows[thisWinIndex].roundedX = STARTWIDTH;
   animatedWindow.windows[thisWinIndex].roundedY = STARTHEIGHT;
   animatedWindow.windows[thisWinIndex].currentX = STARTWIDTH;
   animatedWindow.windows[thisWinIndex].currentY = STARTHEIGHT;
   animatedWindow.windows[thisWinIndex].currentZ = 0;
   resizeAnimatedWindow(thisWinIndex);
   }

function resizeAnimatedWindow(WININDEX) {
   var animateWinObj = animatedWindow.windows[WININDEX];
   if (animateWinObj.currentZ + animateWinObj.incZ < animateWinObj.distZ) {
      animateWinObj.currentX += animateWinObj.incX;
      animateWinObj.currentY += animateWinObj.incY;
      animateWinObj.currentZ += animateWinObj.incZ;
      var incX = Math.round(animateWinObj.currentX) - animateWinObj.roundedX;
      animateWinObj.roundedX += incX;
      var incY = Math.round(animateWinObj.currentY) - animateWinObj.roundedY;
      animateWinObj.roundedY += incY;
      animateWinObj.winObj.resizeBy(incX,incY);
      window.setTimeout('resizeAnimatedWindow(' + WININDEX + ')',animateWinObj.frameRate);
      }
   else {
      var incX = animateWinObj.endWidth - animateWinObj.roundedX;
      var incY = animateWinObj.endHeight - animateWinObj.roundedY;
      animateWinObj.winObj.resizeBy(incX,incY);
      if (!isBlank(animateWinObj.url)) animateWinObj.winObj.location.href = animateWinObj.url;
      }
   }