// 12-09-2003 MJT Added support for <input type='image'>
GMM_MouseOvers = new Object();
var selectedMouseOver = null;

function GMM_MouseOver2(ImName, ImNormSrc, ImActSrc) // [, ImSelSrc , AddMouseOver, AddMouseOut])
{
  if(document.images[ImName]) {
    imgobj = document.images[ImName];
  } else {
    if (document.getElementById) {
	    imgobj = document.getElementById(ImName);
	  }
	}

	if (!imgobj) {
	  // alert(ImName + " not found in current document!");
		return;
	}

	this.Name = ImName;

	// preload
	this.ImNorm = new Image();
	this.ImNorm.src = ImNormSrc;

	this.ImAct = new Image();
	this.ImAct.src = ImActSrc;

	if(arguments[3]) {
  	ImSelSrc = arguments[3];
  	this.ImSel = new Image();
	  this.ImSel.src = ImSelSrc;
	}

	if(arguments[4])
		this.AddOverFunc = arguments[4];

	if(arguments[5])
		this.AddOutFunc = arguments[5];

	if(imgobj.onmouseover)
	{	CurrMouseOver = imgobj.onmouseover.toString();

		if(CurrMouseOver.indexOf("return"))
		{	alert("Return instruction found in mouseover-handler, please remove");
			return;
		}

		if(CurrMouseOver.indexOf("{"))
		{	MouseOverBody = CurrMouseOver.substring(CurrMouseOver.indexOf("{")+1, CurrMouseOver.indexOf("}"));
			this.OldOverFunc = MouseOverBody;
		}
	}

	if(imgobj.onmouseout)
	{	CurrMouseOut = imgobj.onmouseout.toString();

		if(CurrMouseOver.indexOf("return"))
		{	alert("Return instruction found in mouseout-handler, please remove");
			return;
		}

		if(CurrMouseOut.indexOf("{"))
		{	MouseOutBody = CurrMouseOut.substring(CurrMouseOut.indexOf("{")+1, CurrMouseOut.indexOf("}"));
			this.OldOutFunc = MouseOutBody;
		}
	}

	GMM_MouseOvers[ImName] = this;

	imgobj.onmouseover = GMM_HandleMouseOver;
	imgobj.onmouseout = GMM_HandleMouseOut;
	if (arguments[3])
	  imgobj.onclick = GMM_HandleMouseClick;
}

function GMM_HandleMouseOver()
{
  if (this.name == selectedMouseOver)
    return;

  theMO = GMM_MouseOvers[this.name];

	if(theMO.AddOverFunc)
		eval(theMO.AddOverFunc);

	if(theMO.OldOverFunc)
		eval(theMO.OldOverFunc);

	this.src = theMO.ImAct.src;
}

function GMM_HandleMouseOut()
{
  if (this.name == selectedMouseOver)
    return;

  theMO = GMM_MouseOvers[this.name];

	if(theMO.AddOutFunc)
		eval(theMO.AddOutFunc);

	if(theMO.OldOutFunc)
		eval(theMO.OldOutFunc);

	this.src = theMO.ImNorm.src;
}

function GMM_HandleMouseClick()
{
  if (this.name == selectedMouseOver)
    return;

  // alert('click');
  if (selectedMouseOver != null) {
    theMO = GMM_MouseOvers[selectedMouseOver];
    this.src = theMO.ImNorm.src;
  }
  selectedMouseOver = this.name;

  theMO = GMM_MouseOvers[this.name];

	this.src = theMO.ImSel.src;
}

function setAutoRollovers()
{ // use the attribute "oversrc" within the <img>-tag
  // or <input type="image">-tag.
  // note double code will be fixed later, works for now

  if (!document.getElementById) return;
  var imgOrgSrc;
  var imgPreload = new Array();

  // do images used as form buttons
  var inputarr = document.getElementsByTagName('input');
  for (var j = 0; j < inputarr.length; j++) {
    if (inputarr[j].getAttribute('type') == "image") {
      if (inputarr[j].getAttribute('oversrc')) {
        imgPreload[imgPreload.length] = new Image();
        imgPreload[imgPreload.length - 1].src = inputarr[j].getAttribute('oversrc');
        inputarr[j].onmouseover = function() {
          imgOrgSrc = this.getAttribute('src');
          this.setAttribute('src',this.getAttribute('oversrc'))
        }
        inputarr[j].onmouseout = function() {
          if (typeof imgOrgSrc != "undefined") {
            this.setAttribute('src',imgOrgSrc);
          }
        }
      }
    }
  }

  // do real images
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
    if (imgarr[i].getAttribute('oversrc')) {
      imgPreload[imgPreload.length] = new Image();
      imgPreload[imgPreload.length - 1].src = imgarr[i].getAttribute('oversrc');
      imgarr[i].onmouseover = function() {
        imgOrgSrc = this.getAttribute('src');
        this.setAttribute('src',this.getAttribute('oversrc'))
      }
      imgarr[i].onmouseout = function() {
        if (typeof imgOrgSrc != "undefined") {
          this.setAttribute('src',imgOrgSrc);
        }
      }
    }
  }
}