// preload all images in the document object 
// v3.2 07/17/2007 Loading "over" images are depending on whether they have onmouseover and onmouseout event. Elimiate unneccesary server request.
function imgOnload(theImage)
{
	if ( theImage == null )
		this.status = true;
	else
		theImage.status=true;
}

function imgToOver( path )
{
    var l;
    l = path.lastIndexOf('.');
    if ( l > 0 )
    {
        return path.substring(0,l) + "_over" + path.substring(l);
    } else
    {
        return path + '_over';
    }
}

function imgToNormal( path )
{
    var l = path.indexOf('_over');
    return path.substr(0,l) + path.substr(l+5);
}

function preloadImg()
{
	var d=document;
	if ( d.images )
	{
		if ( ! d.imgarr ) { d.imgarr = new Array(); }
		var i, j=d.images.length;
		for (i=0; i<j; i++)
		{
            if ( d.images[i].onmouseover && d.images[i].onmouseout )  // only pre-grab image when that image has both onmouseover and onmouseout event handled
            {
                var overimg=new Image();
                overimg.status = false;
                overimg.onload = imgOnload;
                overimg.src = imgToOver( d.images[i].src );
                //alert(overimg.src);
            }
  			d.imgarr.push(overimg);
		}
	}
}

function imgOver(theImage) { //v3.0
	if ( !document.imgarr || !theImage || theImage.src.indexOf('_over') >= 0) return;
    theImage.src = imgToOver(theImage.src);
}

function imgOut(theImage)
{
	if (!document.imgarr || !theImage || theImage.src.indexOf('_over') == -1) return;
    theImage.src = imgToNormal(theImage.src);
}

window.onload=preloadImg;   // always tries preload all over image 
