home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- *
- * File : fireworks2.js (NOTE: requires animate2.js!!)
- *
- * Created : 2000/06/05
- *
- * Author : Roy Whittle (Roy@Whittle.com) www.Roy.Whittle.com
- *
- * Purpose : To create animated fireworks on your desktop
- *
- * History
- * Date Version Description
- *
- * 2000-06-05 1.0 This has to be my best script to date.
- * This is the culmination of all the knowledge
- * I have learned over the past 10 Months doing
- * Javascript.
- * 1.1 Fixed a bug in Netscape resize.
- ***********************************************************************/
- /*** Start - xLayer - a cross browser layer object by www.Roy.Whittle.com ***/
- var xLayerNo=0;
- function xLayer(xHtml)
- {
- var xName="xLayer" + xLayerNo++;
-
- if(document.layers)
- {
- this.layer=new Layer(100);
- this.layer.document.open()
- this.layer.document.write(xHtml)
- this.layer.document.close()
- }
- else
- if(document.all)
- {
- txt = "<DIV ID='" + xName
- + "' STYLE=\"position:absolute;left:100;top:100;width:100;height:100;visibility:hidden\">"
- + xHtml + "</DIV>";
- document.body.insertAdjacentHTML("BeforeEnd",txt);
- this.element = document.all[xName];
- this.layer = document.all[xName].style;
- }
-
- this.show = show;
- this.moveTo = moveTo;
- this.setContent = setContent;
-
- return(this);
- }
- function show()
- {
- if(document.layers)
- this.layer.visibility="show";
- else
- if(document.all)
- this.layer.visibility="visible";
- }
- function moveTo(x,y)
- {
- if(document.layers)
- this.layer.moveTo(x,y);
- else
- if(document.all)
- {
- this.layer.pixelLeft = x;
- this.layer.pixelTop = y;
- }
- }
- function setContent(xHtml)
- {
- if(document.layers)
- {
- this.layer.document.open()
- this.layer.document.write(xHtml)
- this.layer.document.close()
- }
- else
- if(document.all)
- {
- this.element.innerHTML=xHtml;
- }
- }
- /*** End - xLayer - a cross browser layer object by www.Roy.Whittle.com ***/
-
- var fwLayer = new Array();
- var scrWidth=600;
- var scrHeight=400;
- var ow;
- var oh;
- var theTimer;
- var layerNo=0;
- var imgBase="";
- var MAX_FIREWORKS=16;
-
- BaseHref=imgBase+"images_";
- Sep="_";
-
- function moveIt()
- {
- var x=Math.floor(Math.random()*scrWidth);
- var y=Math.floor(Math.random()*scrHeight);
- var z=Math.floor(Math.random()*4);
-
- var myLayer=fwLayer[layerNo];
-
- myLayer.moveTo(x,y);
- myLayer.show();
- turn_on("fw"+layerNo, "firework"+z);
-
- layerNo=(layerNo+1)%MAX_FIREWORKS;
-
- theTimer=setTimeout("moveIt()", Math.floor(Math.random()*(1600/MAX_FIREWORKS) ) );
- }
- function setSize()
- {
- if(document.layers)
- {
- ow=window.outerWidth;
- oh=window.outerHeight;
- scrWidth =window.innerWidth;
- scrHeight=window.innerHeight;
- }
- else if(document.all)
- {
- scrWidth = document.body.clientWidth;
- scrHeight = document.body.clientHeight;
- }
- scrWidth -= 100;
- scrHeight -= 100;
- }
- AnimationFrames("firework0", 20, ".gif");
- function fireworks()
- {
- var i=0;
- setSize();
-
- AniFrame["firework1"]=AniFrame["firework0"];
- AniFrame["firework2"]=AniFrame["firework1"];
- AniFrame["firework3"]=AniFrame["firework2"];
-
- for(i=0 ; i<MAX_FIREWORKS; i++)
- {
- AnimatedImage("fw"+i, "firework0");
- fwLayer[i]=new xLayer("<IMG SRC='"+imgBase+"images_firework0_0.gif' NAME='fw"+i+"'>");
- fwLayer[i].fwNo=0;
- }
-
- theTimer=setTimeout("moveIt()", 1000 );
- }
- function handle_resize()
- {
- if( document.layers
- && ( ow != window.outerWidth
- || oh != window.outerHeight) )
- {
- clearTimeout(theTimer);
- location.reload();
- }
- setSize();
- }
- window.onload=fireworks;
- window.onresize=handle_resize;