try 
{
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

var animations = new Array();
var animationSteps = 15;

function animation()
{
    this.CurrentStep = 0;
    this.ElementId = '';
    this.Incrementor = 1;
}


function MainNavFocus( element )
{
    
    if( element.href.match( 'javascript:;' ) ) return;
    
    var anim = GetAnimation( element.id );
    var newAnimation = ( anim == null );
    
    if( newAnimation )
    {
        anim = new animation();
        anim.ElementId = element.id;
        anim.CurrentStep = 0;
        animations.push( anim );
    }
    
    anim.Incrementor = 1;

    PerformAnimation(element.id);   
   
}

function MainNavDeFocus( element )
{

    if( element.href.match( 'javascript:;' ) ) return;
    
    var anim = GetAnimation( element.id );
    var newAnimation = ( anim == null );
    
    if( newAnimation )
    {
        anim = new animation();
        anim.ElementId = element.id;
        anim.CurrentStep = animationSteps;
        animations.push( anim );
    }
        anim.CurrentStep = animationSteps;

    anim.Incrementor = -1;

    PerformAnimation(element.id);   
   
}


function SetOpacity( element, opacity )
{

    if( opacity > 100 ) opacity = 100;
    else if( opacity < 0 ) opacity = 0;

    element.style.filter = "alpha(opacity=" + opacity + ")";
    element.style.MozOpacity = (opacity / 100);       
    element.style.KhtmlOpacity = (opacity / 100)- 0.1;
    element.style.opacity = (opacity / 100) - 0.1;
    
}

function PerformAnimation( elementId )
{
    
    var elem = $(elementId);
    var anim = GetAnimation( elementId );
    
    if( anim != null )
    {
    
        if( anim.Incrementor > 0 && anim.CurrentStep < animationSteps ) 
        {
            anim.CurrentStep += 1;
        }
        
        else if( anim.Incrementor < 0 && anim.CurrentStep > 0 ) 
        {
            anim.CurrentStep -= 1;
        }
        
        else
        {
            DeleteAnimation( elementId );
        }
    
        var opacity = anim.CurrentStep / animationSteps * 100;
        SetOpacity( elem, opacity );  
            
        window.setTimeout( 'PerformAnimation("' + elementId + '")', 25 );   
        
    }
    
}

function GetAnimation( elementId )
{

    for( var i=0; i< animations.length;i++ )
    {
        if( animations[i].ElementId == elementId ) return( animations[i] );    
    }

    return( null );
}

function DeleteAnimation( elementId )
{

    for( var i=0; i< animations.length;i++ )
    {
        if( animations[i].ElementId == elementId ) 
        {
            animations.splice( i, 1 );  
            return;
        }
    }

}


