﻿var displayLinks = [];

try {
document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}
var DisplayLink = function(elementId, activeImg, inactiveImg, link, target, width, height)
{
    var self = this;
    self.elementId = elementId;
    self.activeImg = activeImg;
    self.inactiveImg = inactiveImg;
    self.link = link;
    self.target = target;
    self.width = width;
    self.height = height;

    var init = function()
    {
        var features = "'menubar=0,resizable=0,status=0,location=0,toolbar=0,directories=0,scrollbars=1";
        if (self.width) features += ",width=" + self.width;
        if (self.height) features += ",height=" + self.height;
        features += "'";

        var preload = new Image();
        preload.src = self.activeImg;
        var button = document.getElementById(self.elementId);
        if (window.addEventListener)
        {
        button.addEventListener("mouseover", function() { button.style.backgroundImage = "url(" + self.activeImg + ")"; }, false);
        button.addEventListener("mouseout", function() { button.style.backgroundImage = "url(" + self.inactiveImg + ")"; }, false);
        button.addEventListener("click", function() { var win = window.open(self.link, self.target, features); if (win) win.focus(); }, false);
        }
        else if (window.attachEvent)
        {
            button.attachEvent("onmouseover", function() { button.style.backgroundImage = "url(" + self.activeImg + ")"; });
            button.attachEvent("onmouseout", function() { button.style.backgroundImage = "url(" + self.inactiveImg + ")"; });
            button.attachEvent("onclick", function() { var win = window.open(self.link, self.target, features); if (win) win.focus(); });
        }
    }
    
    if (window.addEventListener)
        window.addEventListener("load", init, false);
    else if (window.attachEvent)
        window.attachEvent("onload", init);

}
