function preloadimg(src)
{
   var img = new Image(); 
   img.src = src;
}
function findpreviewimg(target_id)
{
    var imgs, preview_img;
    if (preview_img = document.getElementById(target_id))
    {
	imgs = document.getElementsByTagName('img');
	orig_src = preview_img.src;
	for(i=0;i<imgs.length;i++)
	{
	    if(/preview_img/.test(imgs[i].className))
	    {
		preloadimg(imgs[i].src.replace('.gif','.jpg'));
		// add the function preview to the parent Element of the image
		imgs[i].onmouseover = function(){preview(preview_img, this.src.replace('.gif','.jpg'));};
		imgs[i].onmouseout  = function(){preview(preview_img, orig_src);};
		imgs[i].onfocus     = function(){preview(preview_img, this.src.replace('.gif','.jpg'));};
		imgs[i].onblur      = function(){preview(preview_img, orig_src);};
	    }
	}
    }
}
function preview(target, new_image_name)
{
    target.src = new_image_name;
}

function findrollimg()
{
    var imgs,i;
    imgs = document.getElementsByTagName('img');
    for(i=0;i<imgs.length;i++)
    {
	if(/roll/.test(imgs[i].className))
	{
	    // add the function roll to the parent Element of the image
	    imgs[i].parentNode.onmouseover=function(){roll(this);};
	    imgs[i].parentNode.onmouseout=function(){roll(this);};
	    imgs[i].parentNode.onfocus=function(){roll(this);};
	    imgs[i].parentNode.onblur=function(){roll(this);};
	}
    }
}
function roll(o)
{
    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
    src = o.childNodes[isnode].src;
    ftype = src.substring(src.lastIndexOf('.'), src.length);
    if(/_on/.test(src))
    {
	newsrc = src.replace('_on','');
    }else{
	newsrc = src.replace(ftype, '_on'+ftype);
    }
    o.childNodes[isnode].src=newsrc;
}

window.onload=function()
{
    findrollimg();
    findpreviewimg('preview_img');
}
