/* Set Images */

var sPATH_APPLET   = "changingimage/FadeImages.class"

/* Non-User Globals */
var iFADE_IMG     = 0
var aFADE_PRELOAD = new Array

//window.onload = initFade



function writeFadeApplet(){

         /* Globals: sPATH_APPLET, iFADE_WIDTH, iFADE_HEIGHT, aFADE_IMG_SRC */
         
         document.write( '<APPLET code="'   + sPATH_APPLET + '"' ) 
         document.write(         'width="'  + iFADE_WIDTH  + '"' )  
         document.write(         'height="' + iFADE_HEIGHT + '">' ) 
         
         var n = aFADE_IMG_SRC.length
         
         for( var i=0; i<n; i++ ){
         
              document.write( '<PARAM name="IMAGE ' + (i+1) + '"' )  
              document.write(        'value="' + aFADE_IMG_SRC[ i ] + '">' ) 
         
         }//endfor
         
         document.write(         '<PARAM name="DISPLAY DELAY"' )  
         document.write(                'value="' + iDISPLAY_DELAY + '">' ) 
         document.write(         '<PARAM name="TRANSITION DELAY"' ) 
         
         var iTransitionDelay = Math.round( 500/iFADE_SPEED )
                  
         document.write(                'value="' + iTransitionDelay + '">' )
         document.write(         '<PARAM name="TRANSITION FRAMES"' )  
         
         var nTransitionFrames = Math.round( 100/iFADE_SPEED )
         
         document.write(                'value="' + nTransitionFrames + '">' ) 
         document.write( '</APPLET>' ) 

}//endfunc

function writeFadeLayers(){

         if( document.all ){
        
             var w = iFADE_WIDTH
             var h = iFADE_HEIGHT
    
             document.write( '<DIV id="fadeLayer" style="position:relative;width:' + w + ';height:' + h + '">' )
             document.write(      '<DIV id="upperLayer"' )
             document.write(      '     style="position:absolute;left:0;top:0;width:' + w + ';height:' + h + ';filter:alpha()">' )
             document.write(      '</DIV>' )
             document.write(      '<DIV id="lowerLayer"' )
             document.write(      '     style="position:absolute;left:0;top:0;width:' + w + ';height:' + h + ';filter:alpha()">' )
             document.write(      '</DIV>' )
             document.write( '</DIV>')
         
         }else
             writeFadeApplet()
             
         document.close()    
             
         setTimeout( "initFade()", 1000 )      
         
}//endfunc



         

function imageFadeIn( sId ){

         var oLayerToShow = document.all[ sId ]
   
         var iOpac = oLayerToShow.filters.alpha.opacity

         if( iOpac<100 )         
             oLayerToShow.filters.alpha.opacity += iFADE_SPEED
         
         else{
         
             window.clearInterval( iINTERVAL )
             
             setTimeout( "changeFadeImage('" + sId + "')", iDISPLAY_DELAY )
         
         }//endif

}//endfunc

function changeFadeImage( sIdLayerFinished ){

         var sIdLayerToShow = ( sIdLayerFinished!="upperLayer" ) ? "upperLayer" : "lowerLayer"         
         var oLayerToShow   = document.all[ sIdLayerToShow ]
         
         /* init opacity */
         oLayerToShow.filters.alpha.opacity = 0
         
         var oLayerFinished = document.all[ sIdLayerFinished ] 
         
         /* increase z-index */
         oLayerToShow.style.zIndex = ( oLayerFinished ) ? oLayerFinished.style.zIndex + 1 : 0
         
         /* insert image */
         oLayerToShow.innerHTML = '<IMG border='+iFADE_BORDER+' width='+iFADE_WIDTH+' height='+iFADE_HEIGHT+' src="' + aFADE_PRELOAD[ iFADE_IMG ].src + '">'
         
         /* next source */
         var n = aFADE_IMG_SRC.length
         iFADE_IMG = ( iFADE_IMG < (n-1) ) ? iFADE_IMG + 1 : 0
         
         var nFramesPerSecond  = 24
         var iMilliSecPerFrame = Math.round( 1000/nFramesPerSecond )
         
         iINTERVAL = setInterval( "imageFadeIn('" + sIdLayerToShow + "')", iMilliSecPerFrame )
             
}//endfunc

function preloadFadeImages(){

         var n = aFADE_IMG_SRC.length 
  
         for( var i=0; i<n; i++ ){
         
              aFADE_PRELOAD[ i ]     = new Image
              aFADE_PRELOAD[ i ].src = aFADE_IMG_SRC[ i ]
              
         }//endfor   
                  
}//endfunc

function initFade(){

         preloadFadeImages()

         if( aFADE_PRELOAD.length>0 ){

             if( document.all )             
                 changeFadeImage()
                  
         }else{
         
             setTimeout( "initFade()", 1000 )    
             
         }//endif    

}//endfunc



