//********************************************
// Document: casket.js 
// author: Jay Grubb
// created: Oct 15, 2002
// last update: April 15 2004 (1)
// 							Oct 22, 2011  (2)
//
// Browser: MSIE 5.0> or Nav4.0>
//
// Preload images 
//********************************************

//*********
// variables
//
var cMaxImg=22 ;			      // number of images
var pictBuffer=new Array() ;  // buffer of preloaded images 
var data=new Array(22);	 	 	// image file name
var curphoto ;						// cur index to file name 
var timerId ;						// pointer to Timeout handle
var attempt ;   					// number of attempts to load an image

//*********
// Initialize the variable to preload images
//
data[0]=["../common/images/title.gif"] ;
data[1]=["images/pine.jpg"] ;
data[2]=["images/memorial.jpg"] ;
data[3]=["images/18guagesilver.jpg"] ;
data[4]=["images/solidpoplar.jpg"] ;
data[5]=["images/solidpoplar.jpg"] ;
data[6]=["images/solidpoplar.jpg"] ;
data[7]=["images/20gaugesealer.jpg"] ;
data[8]=["images/artfirefighter.jpg"] ;
data[9]=["images/solidmaple.jpg"] ;
data[10]=["images/20gaugelastsupper.jpg"] ;
data[11]=["images/arthunter.jpg"] ;
data[12]=["images/solidmahogany.jpg"] ;
data[13]=["images/32ozcopper.jpg"] ;
data[14]=["images/artrace.jpg"] ;
data[15]=["images/doveroak.jpg"] ;
data[16]=["images/bronze.jpg"] ;
data[17]=["images/artgolf.jpg"] ;
data[18]=["images/solidhickory.jpg"] ;
data[19]=["images/stainless.jpg"] ;
data[20]=["images/artmountian.jpg"] ;
data[21]=["images/solidcherry.jpg"] ;

//*********
// function: load
// preloads images and increments graphic bar
//
function load() {
// wait til the picture loaded last time is loaded before
// loading a new one
   if(curphoto>0) {
	     if(!pictBuffer[curphoto-1].complete && ++attempt<2000)
          return;
	}
	 attempt=0;
   // load the image into memory
	 pictBuffer[curphoto]=new Image() ;
	 pictBuffer[curphoto].src=data[curphoto] ;
   // end the timer and show the images
   if(curphoto>=data.length) {
       clearInterval(timerId) ;
			 timerId=-1 ;
			 curphoto=0 ;
	 }
}	     
	 
//*********
// function: preload
// preloads images and adjusts image size to screen resolution
//

function sizeImages(bPrt)
{
	 var xs = screen.availWidth ;
	 var ys = screen.availHeight ;
   var n = document.images.length  ;

	 try {
						  
			 if( (bPrt != true) && ((xs <= 1000) && (ys <= 800)) ) 
			 { 
						document.body.style.fontSize = "10pt" ;
			 }
			 else if ((bPrt == true) || ((xs <= 1280)  && (ys <= 990)) ) 
			 { 
						document.body.style.fontSize = "12pt" ;
			 }
			 else  
			 {
						document.body.style.fontSize = "14pt" ;
			 }
			 while(--n>0 )
	 		 {
			 	  if( n==4 ) 				
					{
					     var e = document.getElementById("flame") ;
							 if (e!=null) {
							 		if ((xs >1280) && (bPrt == false ))
									{
									 		var m = (-77.5 * xs/1210)  ;
											e.style.marginLeft = m.toString() + "px" ;
											m = 120 * (xs/1210)   ;
								  		e.style.marginTop = m.toString() + "px" ;
									}
									else 
									{
							 		 	 e.style.marginTop = "118px" ;
										 e.style.marginLeft = "-79px" ;
							 		}
							}
					}
					else if ((xs > 1280) && (bPrt==false)) 
					{ 
			 	 			document.images[n].width= 250 * (xs/1210) ;
							document.images[n].height= document.images[n].width * 0.7 ;
					}
				 	else  
					{
							document.images[n].width= 250 ;
							document.images[n].height= 175 ;
					}						
			}
			 if (bPrt == true) {
			 			 document.images["titleimg"].width= 370.0  ;
	 		 			 document.images["titleimg"].height= 45.0  ;
			 }
			 else
			 {
			 			 document.images["titleimg"].width= 370.0  * (xs/900) ;
	 		 			 document.images["titleimg"].height= 45.0  * (xs/900) ;
			 }
	 }
	 catch(error) {
	 alert("ER") ;
	 }
}

function preload() 
{
	 
   curphoto=0; // index to data
   attempt=0;
	 // load the images every fifty milisecond
   timerId=setInterval("load()",50) ;
	 sizeImages(false) ;
}

//*********
// function: cancelTimer
// Cancels the timer stopping the slide show.
//
function cancelTimer() {
    // If the timer is going, stop the timer 
    if(timerId>0) 
        clearTimeout(timerId) ;
    // clear the timer handle
    timerId=-1 ;
}


