function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined')
	{
		window.addEventListener('load', fn, false);
	}
	else if (typeof document.addEventListener != 'undefined')
	{
		document.addEventListener('load', fn, false);
	}
	else if (typeof window.attachEvent != 'undefined')
	{
		window.attachEvent('onload', fn);
	}
	else
	{
		return false;
	}
	
	return true;
};




function attachEventListener(target, eventType, functionRef, capture)
{
    if (typeof target.addEventListener != "undefined")
    {
        target.addEventListener(eventType, functionRef, capture);
    }
    else if (typeof target.attachEvent != "undefined")
    {
        target.attachEvent("on" + eventType, functionRef);
    }
    else
    {
        return false;
    }

    return true;
};


/* rotate images using the  DOM */
/* took out the text under the image and instead wrapped the image in the url
	for accessibility. If text changes on the page a screen reader forces the
	user to reload the page thus starting them all over again */
attachEventListener(window, "load", setloadvariable, true);
var num_loaded_images=0;
var images = new Array();
var altText = new Array();
var aUrl = new Array();
 if(document.getElementById) {
  for (var i=0; i < 8; i++) {
   images[i] = new Image();
   }//end for
    images[0].src = "/images/jcw_rotation.jpg";
	altText[0] = "Job Center of Wisconsin";
	aUrl[0] = "https://jobcenterofwisconsin.com";
	images[1].src = "/images/worknet_rotation.jpg";
	altText[1] = "WORKnet";
	aUrl[1] = "http://worknet.wisconsin.gov/worknet/";
	images[2].src = "/images/hire_vets_first_logo_125.jpg";
	altText[2] = "Hire Vets First";
	aUrl[2] = "http://dwd.wisconsin.gov/veterans/default.htm";
    images[3].src = "/images/doyle_rotation.jpg";
	altText[3] = "Jim Doyle";
	aUrl[3] = "http://www.wisgov.state.wi.us/";
	images[4].src = "/images/eafordwd.jpg";
	altText[4] = "Microsoft Elevate America";
	aUrl[4] = "http://www.wisconsinjobcenter.org/ea";
    images[5].src = "/images/county_snapshot_rotation.jpg";
	altText[5] = "County Snapshot";
	aUrl[5] = "http://worknet.wisconsin.gov/worknet/Cntysnap.aspx?menuselection=wdb";
    images[6].src = "/images/oea_125.jpg";
	altText[6] = "Economic Advisors";
	aUrl[6] = "http://dwd.wisconsin.gov/oea/default.htm";
	images[7].src = "/images/wigov_rotation.jpg";
	altText[7] = "Wisconsin Portal";
	aUrl[7] = "http://www.wisconsin.gov/state/index.html";
    var j=0;
  }//end if

 // EDIT THE TWO PLACES WHERE WE HAVE J VALUES WHEN ADDING NEW IMAGES
function animate() {
if(!document.getElementById || !document.createTextNode) { return; }
//alert("j: " + j);
var mainImage = document.getElementById('mainImage');
if(!mainImage){return;}
var divImage = document.getElementById('imageDiv');
//var imageText = document.getElementById('imageText');
var anchorHref = document.getElementById('hrefAnchor');
//var aNode = document.createElement('a');
//mainImage.getAttribute('alt');
//mainImage.setAttribute('alt', ' ');
  if(j < 8) {
   document.getElementById('mainImage').src = images[j].src;
   //mainImage.getAttribute('alt');
   mainImage.setAttribute('alt', altText[j]);
   //aNode.setAttribute('href',aUrl[j]);
   anchorHref.setAttribute('href',aUrl[j]);
   //aNode.appendChild(document.createTextNode(altText[j]));
   //var newText = imageText.appendChild(aNode);

	//replace the text node with the new node
   //imageText.replaceChild(newText,imageText.childNodes[0]);
   var timeoutID = setTimeout('animate()', 3000);
   j++; 
  }//end if <
  else if(j == 8) {
   j = 0;
   animate();
  }//end else if
}//end animate

function setloadvariable() {
 var loadvariable = true;
 if(loadvariable == true) {
   animate();
 }
}
