﻿// This javascript is for the changing of the slides and the fade in and out of each image
// Requires <div> and <img> tags for both images (see z_slides.html)
// Reqires slider.css to position the images in the same location
var btype;
var brow;
var browver; 
var tlobj;
var codename;

var timehold = 2000;
var timeinc = 100;
var timeplay = 3000;
var oSlider;
var divtop;
var divbot;
var imgtop;
var imgbot;
var imgtmp;
var vtime = 0;
var incval = .02;
var topinc = -incval;
var botinc = incval;
var cotop = 1;
var cobot = 0;
var imgcache = new Array();
var inum = slides.length;
var lastImgNdx = 1;
var icnt = 0;
var lastImgIn = "bot";


function slider()
{
    // create am image cache
    for (icnt = 0; icnt < inum; icnt++)
    {
	    imgcache[icnt] = new Image(350,262);
	    //imgcache[icnt].src = "slides/" + slides[icnt];     
	    imgcache[icnt].src = slides[icnt];     
    }
    setTimeout("slider2()",2000);
}
    function slider2()
{
	// Discover the browser
	brow = navigator.appName;
	if (brow.substring(0,5) == "Micro") { btype = "IE";}
	
	// defines the image objects for this and other functions
	imgtop = document.getElementById('slideImage1');
	imgbot = document.getElementById('slideImage2');
	
	if (btype == "IE")
	{
	    // for IE 6,7,8
	    imgbot.style.visibility = "hidden";
	    imgtop.style.filter = "progid:DXImageTransform.Microsoft.Fade(overlap='1', duration='3');";
	    setTimeout('setFilter()', timehold);
	}
	else			
	{
	    // for non-IE
	    vtime = timeinc;
	    setOpacity(timehold);
    }
}
function mchangeSlides()
{
	imgtop.src = imgcache[lastImgNdx].src;
	lastImgNdx++;
	if (lastImgNdx == inum){ lastImgNdx = 0;}
	imgbot.src = imgcache[lastImgNdx].src;
	setTimeout('setFilter()', timehold);
}
function setFilter() // IE browser
{
	imgtop.filters[0].Apply();
	imgtop.src = imgbot.src;	
	imgtop.filters[0].Play();
	setTimeout('mchangeSlides()',timeplay);		
}
// the following 3 function are for non IE
function xchangeSlides()
{
	lastImgNdx++;
	if (lastImgNdx == inum){ lastImgNdx = 0;}
    if (lastImgIn == "bot")
    {
	    imgtop.src = imgcache[lastImgNdx].src;
	    topinc = incval 
	    botinc = -incval
        cotop = 0;
        cobot = 1;
        lastImgIn = "top";
    }
    else
    {
	    imgbot.src = imgcache[lastImgNdx].src;
	    topinc = -incval 
	    botinc = incval
        cotop = 1;
        cobot = 0;
        lastImgIn = "bot";
    }
	vtime = timehold;  			    
}		
function changeOpacity() // non IE browser
{
	vtime = timeinc;			
	cotop += topinc;
	cobot += botinc;
	if (cotop < 0 || cobot < 0)
	{
	    xchangeSlides();
	}
	setOpacity(vtime);
}
function setOpacity(vtime) // non IE browser
{
	imgtop.style.opacity = cotop;          
	imgbot.style.opacity = cobot;
	setTimeout("changeOpacity()",vtime);        
} 


