// Java Document
// xAniOpacity r1, Copyright 2006-2007 Michael Foster (Cross-Browser.com) 
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL 

function xAniOpacity(e, o, t, a, oe) { 
   if (!(e=xGetElementById(e))) return;
   xOpacity(e,0);
   var o0 = xOpacity(e); // start value 
   var dx = o - o0; // displacement 
   var fq = 1 / t; // frequency
   if (a) fq *= (Math.PI / 2); 
   var t0 = new Date().getTime(); // start time 
   var tmr = setInterval(
      function() {
         var et = new Date().getTime() - t0; // elapsed time
         if (et < t) {
             var f = et * fq; // constant velocity 
             if (a == 1) f = Math.sin(f); // sine acceleration 
             else if (a == 2) f = 1 - Math.cos(f); // cosine acceleration 
             f = Math.abs(f); 
             xOpacity(e, f * dx + o0); // instantaneous value 
         } else {
             clearInterval(tmr); 
             xOpacity(e, o); // target value 
             if (typeof oe == 'function') oe(); // 'onEnd' handler 
             else if (typeof oe == 'string') eval(oe); 
         } 
    }, 10 // timer resolution 
  ); 
}

// xOpacity r1, Copyright 2006-2007 Michael Foster (Cross-Browser.com) 
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL 
function xOpacity(e, o) { 
  var set = xDef(o); 
  // if (set && o == 1) o = .9999; // FF1.0.2 but not needed in 1.5 
  if(!(e=xGetElementById(e))) return 2; // error 
  if (xStr(e.style.opacity)) { // CSS3
    if (set) e.style.opacity = o + ''; 
	else o = parseFloat(e.style.opacity); 
  } 
  else if (xStr(e.style.filter)) { // IE5.5+ 
    if (set) e.style.filter = 'alpha(opacity=' + (100 * o) + ')'; 
	else if (e.filters && e.filters.alpha) { o = e.filters.alpha.opacity / 100; }
  } 
  else if (xStr(e.style.MozOpacity)) { // Gecko before CSS3 support
    if (set) e.style.MozOpacity = o + ''; 
	else o = parseFloat(e.style.MozOpacity); 
  } 
  else if (xStr(e.style.KhtmlOpacity)) { // Konquerer and Safari
    if (set) e.style.KhtmlOpacity = o + ''; 
	else o = parseFloat(e.style.KhtmlOpacity); 
  } 
  return isNaN(o) ? 1 : o; // if NaN, should this return an error instead of 1? 
}

// xGetElementById r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com) 
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL 
function xGetElementById(e) {
 if(typeof(e)=='string') { 
   if(document.getElementById) e=document.getElementById(e); 
   else if(document.all) e=document.all[e]; 
   else e=null; 
 } 
 return e; 
}

// xDef r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com) 
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL 
function xDef() 
{
  for(var i=0; i<arguments.length; ++i){
    if(typeof(arguments[i])=='undefined') return false;
  } return true; 
}

// xStr r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com) 
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL 
function xStr(s) 
{ 
  for(var i=0; i<arguments.length; ++i){
    if(typeof(arguments[i])!='string') return false;
  }
  return true; 
}
