var Ads = Class.create();
Ads.prototype = {
    
    images: new Array(),
    currentIndex: 0,
    
    initialize: function (container) {
        this.images = $$('#' + container + ' img');
        if (this.images.length < 1) return;
        this.images.each(function (element){
            element.xOpacity = 0;
        });
        this.images[this.currentIndex].style.display = "block";
        this.images[this.currentIndex].xOpacity = .99;
        this.imageFade();
    },
    
    imageFade: function () {
        currentOpacity = this.images[this.currentIndex].xOpacity;
        nextIndex = this.images[this.currentIndex+1]?this.currentIndex+1:0;
        nextOpacity = this.images[nextIndex].xOpacity;
    
        currentOpacity-=.05; 
        nextOpacity+=.05;
    
        this.images[nextIndex].style.display = "block";
        this.images[this.currentIndex].xOpacity = currentOpacity;
        this.images[nextIndex].xOpacity = nextOpacity;
    
        this.setOpacity(this.currentIndex); 
        this.setOpacity(nextIndex);
    
        if(currentOpacity <= 0) {
            this.images[this.currentIndex].style.display = "none";
            this.currentIndex = nextIndex;
            setTimeout(this.imageFade.bind(this),5000);
        } else {
            setTimeout(this.imageFade.bind(this),30);
        }
    },
    
    setOpacity: function (index) {
        if(this.images[index].xOpacity>.99) {
            this.images[index].xOpacity = .99;
            return;
        }
        this.images[index].style.opacity = this.images[index].xOpacity;
        this.images[index].style.MozOpacity = this.images[index].xOpacity;
        this.images[index].style.filter = "alpha(opacity=" + (this.images[index].xOpacity*100) + ")";
    }
}

sfHover = function() {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
