function handleEvent(obj, event, func) {
    try {
        obj.addEventListener(event, func, false);
    } catch (e) {
        if (typeof eval("obj.on"+event) == "function") {
            var existing = obj['on'+event];
            obj['on'+event] = function () { existing(); func(); };
        } else {
            obj['on'+event] = func;                        
        }
    }
} 

sfHover = function() {
	var sfEls = document.getElementById("menu").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);

function rotateText() {
    var self = this;

    self.current = 0;
    self.opacity = 0;
    self.debug   = false;

    self.instantiate = function () {
        self.theDiv = document.getElementById('rotatingText');
        self.textArray = self.theDiv.innerHTML.split("--");
        self.theDiv.innerHTML = self.textArray[0];
        
        if (self.textArray.length > 1) {
            self.theDiv.style.opacity = 0;
            self.theDiv.style.filter  = "alpha(opacity:0)";         
            self.fadeIn(); // self.timer = setTimeout(self.rotate, 1 * 1000);        
        }
    }
    
    self.rotate = function () {
        self.fadeOut();        
    }
    
    self.fadeOut = function () {
        if (self.debug) {
            self.theDiv.innerHTML = 'in fadeOut: opacity = '+self.opacity;        
        }
        if (self.opacity <= 0) {
            clearTimeout(self.timer);
            self.replaceText();
        } else {
            self.opacity -= 0.05;
            self.theDiv.style.opacity = self.opacity;
            self.theDiv.style.filter = "alpha(opacity:"+self.opacity*100+")";    
            self.timer = setTimeout(self.fadeOut, 100);
        }    
    }
    
    self.replaceText = function() {
        if (self.debug) {
            self.theDiv.innerHTML = 'in replace';
        }
        self.current++;        
        if (self.current == self.textArray.length) {
            self.current = 0;
        }
        
        self.theDiv.innerHTML = self.textArray[self.current];
        self.timer = setTimeout(self.fadeIn, 100);
    }
    
    self.fadeIn = function() {
        if (self.debug) {
            self.theDiv.innerHTML = 'in fadeIn: opacity = '+self.opacity;    
        }
        if (self.opacity >= 0.95) {
            self.opacity = 1;
            self.theDiv.style.opacity = 0.95;
            self.theDiv.style.filter = "alpha(opacity:"+95+")";
            self.timer = setTimeout(self.rotate, 3 * 1000);        
        } else {
            self.opacity += 0.05;
            self.theDiv.style.opacity = self.opacity;
            self.theDiv.style.filter = "alpha(opacity:"+self.opacity*100+")";    
            self.timer = setTimeout(self.fadeIn, 100);
        }    

    }

    handleEvent(window, 'load', self.instantiate);
}

var textRotator = new rotateText();