// index.js - javascript support for ingraminsuranceagency.com
// use: image cycling scripts for index.htm
// version: 7/1/2010
// copyright 2010 ingram insurance agency, all rights reserved
// scripting copyright 2010 amalgamated binaries, inc., all rights reserved

// global function for image loading


window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);


// global variables for index.htm fades
var d = document;
var imgs = new Array();
var zInterval = null;
var current = 0;
var pause = false;
var interval = 4000; // 4 sec
var timerID;

// so_init support function (index.htm)
function so_init()
{
 if (!d.getElementById || !d.createElement) return;
 imgs = d.getElementById("imgblock").getElementsByTagName("img");
 for (i=1; i<imgs.length; i++) imgs[i].xOpacity = 0;
 imgs[0].style.display = "block";
 imgs[0].xOpacity = .99;
 setTimeout(so_xfade,interval);
}



// so_xfade support function (index.htm)
function so_xfade()
{
 var cOpacity = imgs[current].xOpacity;
 var nIndex = imgs[current+1]?current+1:0;
 var nOpacity = imgs[nIndex].xOpacity;
 cOpacity-=.05;
 nOpacity+=.05;
 imgs[nIndex].style.display = "block";
 imgs[current].xOpacity = cOpacity;
 imgs[nIndex].xOpacity = nOpacity;
 setOpacity(imgs[current]);
 setOpacity(imgs[nIndex]);

 // test for pause state...
 // This code should be used to stop the animation (e.g., user hovers over a topic link)...
 // if ((pause) && (timerID)) { clearTimeout(timerID); timerID=0; } else { } // allow processing to continue

 if(cOpacity<=0) { imgs[current].style.display = "none"; current = nIndex; timerID = setTimeout(so_xfade,interval); } else { timerID = setTimeout(so_xfade,50); }

 // setOpacity nested function
 function setOpacity(obj)
 {
  if(obj.xOpacity>.99) { obj.xOpacity = .99; return; }
  obj.style.opacity = obj.xOpacity;
  obj.style.MozOpacity = obj.xOpacity;
  obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
 }
}

// so_pause function
function so_pause()
{
 pause = true;
}

