// Based on:
//---------------------------------------------------------------
// Opacity Displayer, Version 1.0
// Copyright Michael Lovitt, 6/2002.
// Distribute freely, but please leave this notice intact.
//---------------------------------------------------------------
// Reworked for efficiency by David Kasprzyk, 02/2009

//---------------------------------------------------------------
// ID OPACITY OBJECT
//
// Instantiates the object, defines the properties and methods.
function IdOpacityObject(id, doesHover, path) {
    if (arguments.length == 3) {
        this.normalPath = path;
    } else if (arguments.length == 2) {
        this.normalPath = id;
    } else if (arguments.length == 1) {
        doesHover = false;
        this.normalPath = id;
    }

    if (doesHover) {
        this.hoverPath = this.normalPath + "_h";

        if (preloadUrls != null) {
            preloadUrls[preloadUrls.length] = "images/" + this.hoverPath + ".png";
        }
    }

    if (ns) {
        if (browserVersion >= 5) {
            this.idObject = document.getElementById(id).style;
        } else {
            this.idObject = eval("document." + id);
        }
    } else {
        this.idObject = eval(id + ".style");
    }

    this.SetBackground = IdSetBackground;

    this.Normal = SetNormal;
    this.Hover = SetHover;
    this.SetPath = SetPath;
    this.Show = ShowObject;
    this.Hide = HideObject;

    this.Normal();
}

// Uses AlphaImageLoader filter, or the css background property,
// as appropriate, to apply a PNG as the background of the id object.
function IdSetBackground() {
    if (pngAlpha) {
        this.idObject.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/" + this.path + ".png', sizingMethod='scale')";
    } else {
        this.idObject.backgroundImage = 'url(images/' + this.path + '.png)';
    }
}
//---------------------------------------------------------------

//---------------------------------------------------------------
// CLASS OPACITY OBJECT
//
// Instantiates the objects, defines the properties and methods.
function ClassOpacityObject(_class, doesHover, path) {
    if (arguments.length == 3) {
        this.normalPath = path;
    } else if (arguments.length == 2) {
        this.normalPath = _class;
    } else if (arguments.length == 1) {
        doesHover = false;
        this.normalPath = _class;
    }

    if (doesHover) {
        this.hoverPath = this.normalPath + "_h";

        if (preloadUrls != null) {
            preloadUrls[preloadUrls.length] = "images/" + this.hoverPath + ".png";
        }
    }

    var all = document.all ? document.all : document.getElementsByTagName('*');
    this.classObjects = new Array();

    for (var i = 0; i < all.length; i++) {
        if (all[i].className == _class) {
            this.classObjects[this.classObjects.length] = all[i].style;
        }
    }

    this.SetBackground = ClassSetBackground;

    this.Normal = SetNormal;
    this.Hover = SetHover;

    this.Normal();
}

// Uses AlphaImageLoader filter, or the css background property,
// as appropriate, to apply a PNG as the background of all of the class objects.
function ClassSetBackground() {
    if (pngAlpha) {
        for (var i = 0; i < this.classObjects.length; i++) {
            this.classObjects[i].filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/" + this.path + ".png', sizingMethod='scale')";
        }
    } else {
        for (var i = 0; i < this.classObjects.length; i++) {
            this.classObjects[i].backgroundImage = 'url(images/' + this.path + '.png)';
        }
    }
}
//---------------------------------------------------------------

//---------------------------------------------------------------
// Helper functions
function SetNormal() {
    this.path = this.normalPath;
    this.SetBackground();
}

function SetHover() {
    this.path = this.hoverPath;
    this.SetBackground();
}

function SetPath(path) {
    this.normalPath = path;
}

function ShowObject() {
    this.idObject.display = 'block';
}

function HideObject() {
    this.idObject.display = 'none';
}
//---------------------------------------------------------------

//---------------------------------------------------------------
// global variables
// if IE5.5+ on win32, then display PNGs with AlphaImageLoader
if ((browser.isIE55 || browser.isIE6up) && browser.isWin32) {
    var pngAlpha = true;
// else, if the browser can display PNGs normally, then do that. that list includes:
    //     -Gecko Engine: Netscape 6 or Mozilla, Mac or PC
    //     -IE5+ Mac (OpacityObject applies the background image at 100% opacity)
    //     -Opera 6+ PC
    //     -Opera 5+ Mac (Doesn't support dynamically-set background images)
    //     -Opera 6+ Linux 
    //     -Omniweb 3.1+ 
    //     -Icab 1.9+ 
    //     -WebTV 
    //     -Sega Dreamcast
} else if ((browser.isGecko) || (browser.isIE5up && browser.isMac) || (browser.isOpera && browser.isWin && browser.versionMajor >= 6) || (browser.isOpera && browser.isUnix && browser.versionMajor >= 6) || (browser.isOpera && browser.isMac && browser.versionMajor >= 5) || (browser.isOmniweb && browser.versionMinor >= 3.1) || (browser.isIcab && browser.versionMinor >= 1.9) || (browser.isWebtv) || (browser.isDreamcast)) {
} else {
    // Browser is too old to support this. Should notify the user somehow
}

var ns = document.all ? false : true;
var browserVersion = parseFloat(navigator.appVersion);
//---------------------------------------------------------------
