﻿// JavaScript Document


/***********************************************
* Fade-in image slideshow script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var slideshow_width='790px' //SET IMAGE WIDTH
var slideshow_height='305px' //SET IMAGE HEIGHT
var pause=3000 //SET PAUSE BETWEEN SLIDE (3000=3 seconds)
// choose images that are same size or they will stretch
// resize images or you will only see part of top left of image


var fadeimages=new Array()
//SET 1) IMAGE PATHS, 2) optional link, 3), optional link target:
fadeimages[0]=["images/ramsell_home01.jpg", "giving", ""]
fadeimages[1]=["images/ramsell_home02.jpg", "giving/", ""]
fadeimages[2]=["images/ramsell_home03.jpg", "http://www.ramselltechnologies.com", "_blank"] 
fadeimages[3]=["images/ramsell_home04.jpg", "whatwedo/familyofbusinesses.aspx", ""] 
fadeimages[4]=["images/ramsell_home05.jpg", "giving/fhf.aspx", ""] 

////NO need to edit beyond here/////////////

var preloadedimages=new Array()
for (p=0;p<fadeimages.length;p++){
preloadedimages[p]=new Image()
preloadedimages[p].src=fadeimages[p][0]
}

var ie4=document.all
var dom = null != document.getElementById

var curpos=10
var degree=10
var curcanvas="canvas0"
var nextimageindex=0
var tempobj

function startit() {
//nextimageindex = Math.floor(Math.random() * (fadeimages.length - 1));	
// RANDOM
nextimageindex = Math.ceil(Math.random() * fadeimages.length) % fadeimages.length;
    setCanvasImage(getCanvasById(curcanvas), nextimageindex)
    rotateimage()
}

function setNextImage(i) {
    nextimageindex = i;
    if (curpos < 100) { // we are rotating 
        nextpause = 1;
    }
    else { // we are waiting for rotateimage 
        clearTimeout(dropslide);
        rotateimage();
    }
}

function rotateimage()
{
    if (ie4 || dom) {
        nextpause = pause // reset pause to default

        if (tempobj) tempobj.style.zIndex--
        tempobj = getCanvasById(curcanvas);
        setOpacity(tempobj, curpos = 0);
        setCanvasImage(tempobj, nextimageindex);
        tempobj.style.zIndex++

        dropslide = eval('setInterval("fadepic()",50)')
        curcanvas = (curcanvas == "canvas0") ? "canvas1" : "canvas0"
    }
    else {
        document.images.defaultslide.src = fadeimages[nextimageindex][0]
    }

    nextimageindex = advanceIndex(nextimageindex, fadeimages.length);
}

function fadepic()
{
    if (curpos < 100)
        setOpacity(tempobj, curpos += 10)
    else
    {
        clearInterval(dropslide);
        dropslide = setTimeout("rotateimage()", nextpause)
    }
}

function getCanvasById(id) {
    return ie4 ? eval("document.all." + id) : document.getElementById(id)
}

function setCanvasImage(canvas, index) {
    canvas.innerHTML = insertimage(index);
}


function insertimage(i){
var tempcontainer = '<img src="' + fadeimages[i][0] + '" border="0" usemap="#Map" />'
if (ie4){
	document.all.MapArea.href = fadeimages[i][1]
	document.all.MapArea.target = fadeimages[i][2]
}
else{
	document.getElementById('MapArea').href = fadeimages[i][1]
	document.getElementById('MapArea').target = fadeimages[i][2]
}
return tempcontainer
}

function setVisibility(obj, visible) {
    obj.style.visibility = visible ? "visible" : "hidden";
}

function setOpacity(obj, opac)
{
    if (obj.filters)
        obj.filters.alpha.opacity = curpos
    else if (obj.style) {
        if (obj.style.MozOpacity)
            obj.style.MozOpacity = curpos / 101
        else obj.style.opacity = curpos / 101
    }    
}

function advanceIndex(index, imageCount) {
    return (index + 1) % imageCount;
}

if (ie4||dom||true)
window.onload=startit
else
setInterval("rotateimage()",pause)

