/*  Document    :  ImageHover.js
 *  Created On  :  2 November 2006, 6:06 PM
 *  Author      :  jrbethke
 *  Description :  Provides features to elements that allow them to be
 *                  hovered, selected, and deactivated.
 */


function implementImageHover() {
    var imgarr = document.getElementsByTagName('img');
    for (var i = 0; i < imgarr.length; i++) {
        if(!(imgarr[i].getAttribute('active'))) imgarr[i].setAttribute('active', true);
        if (imgarr[i].getAttribute('hsrc')) {
            imgarr[i].setAttribute('originalSrc',imgarr[i].getAttribute('src'));
            imgarr[i].onmouseover = function() {
                if(this.getAttribute('active') != 'false' && this.getAttribute('active') != false) {
                    this.setAttribute('src', this.getAttribute('hsrc'));
                }else{
                    this.style.cursor = "default";
                }
            }
            imgarr[i].onmouseout = function() {
                if(this.getAttribute('active') != 'false' && this.getAttribute('active') != false) {
                    this.setAttribute('src',this.getAttribute('originalSrc'));
                }
            }
        }
        if (imgarr[i].getAttribute('dsrc')) {
            imgarr[i].activate = function() {
                this.setAttribute('active', true);
                this.setAttribute('src',this.getAttribute('originalSrc'));
            }
            imgarr[i].deactivate = function() {
                this.setAttribute('src', this.getAttribute('dsrc'));
                this.setAttribute('active', false);
            }
        }
    }
}

function implementRowHover(tableRef, hoverColor) {
    var rows = tableRef.childNodes[0].childNodes;
    for(var i in rows) {
        if(rows[i].nodeName == "TR") {
            if(!(rows[i].getAttribute('selected'))) rows[i].setAttribute('selected', false);
            
            rows[i].setAttribute('oldColor', rows[i].style.backgroundColor);
            rows[i].setAttribute('textColor', rows[i].style.color);
            rows[i].onmouseover = function() {
                if(this.getAttribute('selected') != 'true' && this.getAttribute('selected') != true) {
                    this.style.backgroundColor = hoverColor;
                }
            }
            rows[i].onmouseout = function() {
                if(this.getAttribute('selected') != 'true' && this.getAttribute('selected') != true) {
                    this.style.backgroundColor = this.getAttribute('oldColor');
                }
            }
            
            rows[i].select = function() {
                this.setAttribute('selected', true);
                this.style.backgroundColor = hoverColor;
                this.style.color = "#ffffff";
            }
            rows[i].deselect = function() {
                this.style.backgroundColor = this.getAttribute('oldColor');
                this.style.color = this.getAttribute('textColor');
                this.setAttribute('selected', false);
            }
        }
    }
}