jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages("/images/header.jpg",
"/images/headerpic01.jpg",
"/images/headerpic01.jpg",
"/images/headerpic02.jpg",
"/images/headerpic04.jpg",
"/images/einstein.jpg",
"/images/gallery_nav_Vgames.jpg",
"/images/gallery_nav_girls.jpg",
"/images/gallery_nav_polo.jpg",
"/images/gallery_nav_players.jpg",
"/images/gallery_nav_seniors.jpg",
"/images/gallery_nav_Teams.jpg");
function findimg()
{
 var imgs,i;
// Loop through all images, check if they contain the class button
 imgs=document.getElementsByTagName('img');
 for(i=0;i<imgs.length;i++)
 {
  if(/button/.test(imgs[i].className))
  {
// add the functions to the parent Element of the image
  imgs[i].parentNode.onmouseover=function(){shake(this);rattle(this);roll(this);};
  imgs[i].parentNode.onmouseout=function(){restore();};
  imgs[i].parentNode.onfocus=function(){shake(this);rattle(this);roll(this);};
  imgs[i].parentNode.onblur=function(){restore();};
  }
 }
}
function shake(o)	//get name from image, find div#name, swap display property for that div
{ 
	 var i,imgname,blurb,greet;
	// loop through all childNodes
	 for (i=0;i<o.childNodes.length;i++)
	 {
	  nownode=o.childNodes[i];
	// if the node is an element and an IMG set the variable and exit the loop
	  if(nownode.nodeType==1 && /img/i.test(nownode.nodeName))
	  {
	   imagename = nownode.getAttribute('name');
	   break;
	  }
	 }
	// find div and swap display
	 blurb = document.getElementById(imagename);
	 greet = document.getElementById('text'); 
	 if (blurb.style.display == 'none')
	 {	blurb.style.display = 'block';
	 	greet.style.display = 'none';	 	
	 } else {
		 blurb.style.display = 'none';
		 grett.style.display = 'block';
	 }	
}
function rattle(o)	//double rollover the current icon so it doesn't change
{
	 var i,isnode,src,ftype,newsrc,nownode;
	// loop through all childNodes
	 for (i=0;i<o.childNodes.length;i++)
	 {
	  nownode=o.childNodes[i];
	// if the node is an element and an IMG set the variable and exit the loop
	  if(nownode.nodeType==1 && /img/i.test(nownode.nodeName))
	  {
	   isnode=i;
	   break;
	  }
	 }
	// check src and do the rollover
	 o.childNodes[isnode].className+= ' unfade';
}
function roll(o)	//roll over all icons
{
 var i,j,k,isnode,src,ftype,newsrc,nownode;
// loop through all childNodes
 for (i=0;i<o.parentNode.parentNode.childNodes.length;i++) //list items
 {	
 	for(j=0;j<o.parentNode.parentNode.childNodes[i].childNodes.length;j++) //links
 	{	
		for(k=0;k<o.parentNode.parentNode.childNodes[i].childNodes[j].childNodes.length;k++) //images
		{	
			if (o.parentNode.parentNode.childNodes[i].childNodes[j].childNodes[k].nodeType==1)
			{	
				nownode=o.parentNode.parentNode.childNodes[i].childNodes[j].childNodes[k];
				 //if the node is an element and an IMG set the variable and exit the loop
				if(nownode.nodeType==1 && /img/i.test(nownode.nodeName))
				{	
					nownode.className+=' fade'; 
				}
			}
		}
	}
 }
}
function restore()
{
	var greet, icons,i,blurbs,j;
	//hide all blurbs
	blurbs = document.getElementById('content').getElementsByTagName('div');
	for (j=0;j<blurbs.length;j++)
	{
		blurbs[j].style.display = 'none'
	}
	//restore visability of greeting text
	greet = document.getElementById('text');
	greet.style.display = 'block';
	//unfade all icons
	icons = document.getElementsByTagName('img');
	for (i=0;i<icons.length;i++)
	{
		icons[i].className=icons[i].className.replace(' fade', '');
		icons[i].className=icons[i].className.replace(' unfade', '');
	}	
}
window.onload=function(){
 findimg();
}