/* Fix flickering images and memory leaks */

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(e) {

}

/* Alpha */

function Alpha(element, sizingMethod) {
    this.element = element;
    this.sizingMethod = sizingMethod || "crop";
    this.applyFilter();
}

Alpha.Filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader";
                                                                                             

Alpha.prototype.applyFilter = function() {
    if(this.hasBackgroundImage()){
        var imageUrl = this.getBackgroundImage();
        this.element.style.background = "none";
        var filter = new StringBuilder();
        filter.append(Alpha.Filter).append("(src='").append(imageUrl).append("', sizingMethod='" + this.sizingMethod + "')");
        this.element.style.filter = filter.toString();
    }
}

Alpha.prototype.hasBackgroundImage = function(){
    return this.element.currentStyle.backgroundImage != "none";
}

Alpha.prototype.getBackgroundImage = function(){
    var imageUrl = this.element.currentStyle.backgroundImage;
    return imageUrl.match(/url\("(.+)"\)/)[1];
}

document.getElementsBySelector('a.logo').each(function(element){
            new Alpha(element);
});
document.getElementsBySelector('h1.title').each(function(element){
            new Alpha(element);
});
