// Image MouseOver Opacity (10-Jan-2006)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// Application Notes

// The MouseOver and MouseOut Images are nested in a <DIV>
// The first image is the MouseOver Image
// The second image is the MouseOut Image
// The <DIV> must have a specified style position of absolute or relative;
// The images must have a specified style position of absolute; and left:0px;top:0px;

// The mouseover function h10OpacityMouse(this,2,50);
// parameter 0 = the mouseover object, this or the unique ID Name       (object or string)
// parameter 1 = the Opacity increment (1 = minimum = slow)             (digit)
// parameter 2 = the Opacity speed in milliSeconds (minimum = 5 = fast) (digit)

// The mouseout function h10OpacityMouse(this,5,5);
// parameter 0 = the mouseover object, this or the unique ID Name (object or string)
// parameters 1 and 2 are option, if omitted the mouseover parameters are used
// parameter 1 = the Opacity increment (1 = minimum = slow)             (digit)
// parameter 2 = the Opacity speed in milliSeconds (minimum = 5 = fast) (digit)

// All variable, function etc. names are prefixed with 'h10' to minimise conflicts with other JavaScripts
// These charactors are easily changed to charactors of choise using global find and replace.

// The Functional Code(2.5K) is best as an External JavaScript

// Tested with IE6 and Mozilla FireFox

var h10Cnt=0;
var h10CkOpc=false;

function h10OpacityMouse(h10m,h10i,h10d){
 if (typeof(h10m)=='string'){ h10m=document.getElementById(h10m); }
 if (!h10m.obj){
  if (!h10i){ h10i=5; }
  if (!h10d){ h10d=15; }
  h10m.obj=new h10OOPOpcMse(h10m.getElementsByTagName('IMG'));
  h10m.obj.imgT.zIndex='1';
  if (h10m.style.MozOpacity!=null||h10m.style.opacity!=null||h10m.style.filter!=null||h10m.style.KHTMLOpacity!=null){
   h10CkOpc=true;
  }
 }
 if (h10i){ h10m.obj.inc=h10i; }
 if (h10d){ h10m.obj.delay=h10d; }
 if (h10m.obj.inc<1){ h10m.obj.inc=1; }
 if (h10m.obj.delay<5){ h10m.obj.delay=5; }
 clearTimeout(h10m.obj.to);
 if (h10m.obj.updown){
  h10m.obj.updown=false;
  if (!h10CkOpc){ h10m.obj.imgT.zIndex='0'; h10m.obj.imgB.zIndex='1'; }
  h10m.obj.up();
 }
 else {
  h10m.obj.updown=true;
  if (!h10CkOpc){ h10m.obj.imgB.zIndex='0'; h10m.obj.imgT.zIndex='1';  }
  h10m.obj.down();
 }
}

function h10OOPOpcMse(h10imgs){
 this.imgT=h10imgs[1].style;
 this.imgB=h10imgs[0].style;
 this.ref='h10imgmo'+h10Cnt;
 window[this.ref]=this;
 this.updown=true;
 this.cnt=0;
 this.min=0;
 this.max=100;
 this.to=null;
 h10Cnt++;
}

h10OOPOpcMse.prototype.up=function(){
 if(!this.updown){
  this.cnt+=this.inc;
  if(this.cnt<=this.max){
   h10Opacity(this.imgB,this.cnt)
   h10Opacity(this.imgT,(100-this.cnt));
   this.setTimeOut("up();",this.delay);
  }
  else {
   h10Opacity(this.imgB,this.max)
   h10Opacity(this.imgT,this.min)
  }
 }
}

h10OOPOpcMse.prototype.down=function(){
 if(this.updown){
  this.cnt-=this.inc;
  if(this.cnt>=this.min){
   h10Opacity(this.imgB,this.cnt)
   h10Opacity(this.imgT,(100-this.cnt));
   this.setTimeOut("down();",this.delay);
  }
  else {
   h10Opacity(this.imgB,this.min);
   h10Opacity(this.imgT,this.max);
  }
 }
}

h10OOPOpcMse.prototype.setTimeOut= function(h10f,h10d){
 this.to=setTimeout("window."+this.ref+"."+h10f,h10d);
}

function h10Opacity(h10obj,h10op) {
 if (h10op>100||h10op<0){ return }
 if (h10obj.MozOpacity!=null){ h10obj.MozOpacity=(h10op/100)-.001; }
 else if (h10obj.opacity!=null){ h10obj.opacity=(h10op/100)-.001; }
 else if (h10obj.filter!=null){ h10obj.filter = 'alpha(opacity='+h10op+')';     }
 else if (h10obj.KHTMLOpacity!=null){ h10obj.KHTMLOpacity=(h10op/100)-.001; }
}