
function DRG_ActiveButton(Properties)
{
    for (var i = 0; i < Properties.length; i++)
    {
        this[Properties[i][0]] = Properties[i][1];
    }
        
    var div = document.getElementById(this.ID);
    
    this.CurFrame = 0;
    this.NormalFrame = 0;
    this.HoverFrame = this.HoverFrames;
    this.DepressFrame = this.HoverFrames + this.DepressFrames;
    
    div.onmouseover=function(e)
    {
        this.editor.AnimateToFrame(this.editor.HoverFrame);
        
        if (e == null){e=window.event;}
        if (this.editor.OnMouseOver != null){
            this.editor.OnMouseOver(this.editor, e, this.editor.AdditionalEventArguments);
        }
    };
    div.onmouseout=function(e)
    {
        if (!this.editor.LoopingHover)
        {
            this.editor.AnimateToFrame(this.editor.NormalFrame);
        }

        if (e == null){e=window.event;}
        if (this.editor.OnMouseOut != null){
            this.editor.OnMouseOut(this.editor, e, this.editor.AdditionalEventArguments);
        }
    };
    div.onmousedown=function(e)
    {
        this.editor.AnimateToFrame(this.editor.DepressFrame);
      
        if (e == null){e=window.event;}
        if (this.editor.OnMouseDown != null){
            this.editor.OnMouseDown(this.editor, e, this.editor.AdditionalEventArguments);
        }
    };
    div.onmouseup = function(e)
    {
        this.editor.AnimateToFrame(this.editor.HoverFrame);
        
        if (e == null){e=window.event;}
        if (this.editor.OnMouseUp != null){
            this.editor.OnMouseUp(this.editor, e, this.editor.AdditionalEventArguments);
        }
    };
    
    div.onselectstart=function(){return false;}
    div.ondragstart=function(){return false;}
    div.style.cursor="pointer";
    
    if (this.OnMouseDown != null){
        this.OnMouseDown = eval(this.OnMouseDown);
    }
    
    if (this.OnMouseUp != null){
        this.OnMouseUp = eval(this.OnMouseUp);
    }
    
    if (this.OnMouseOver != null){
        this.OnMouseOver = eval(this.OnMouseOver);
    }
    
    if (this.OnMouseOut != null){
        this.OnMouseOut = eval(this.OnMouseOut);
    }
    
    div.id = this.ID;
    this.div = div;
    div.editor = this;
    
    return this;
}
DRG_ActiveButton.prototype.SetFrame = function(frame)
{
    this.div.style.backgroundPosition = "0px " + (-(this.Height * frame)) + "px";
    
    this.CurFrame = frame;
}
DRG_ActiveButton.prototype.StopAnimation = function()
{
    if (this.AnimateTimer != null)
    {
        clearTimeout(this.AnimateTimer);
        this.AnimateTimer = null;
    }
}
DRG_ActiveButton.prototype.AnimateToFrame = function(frame)
{
    this.StopAnimation();

    var dir;
    if (this.CurFrame > frame){
        dir = -1;}
    else{
        dir = 1;}
        
    this.SetFrame(this.CurFrame + dir);

    if (this.CurFrame != frame)
    {
        this.AnimateTimer = setTimeout(this.ID + ".AnimateToFrame(" + frame + ");", 1000 / this.TransitionSpeed);
    }
    else
    {
        if (frame == this.HoverFrame && this.LoopingHover)
        {
            this.SetFrame(this.NormalFrame);
        }
        this.AnimateTimer = null;
    }
}