function $(e) {
    return (typeof(e) == "string") ? document.getElementById(e) : e
}

function getInlineOpacity(e) {  
    return $(e).style.opacity || '';
}  

function setOpacity(element, value){  
    element= $(element);  
    if (value == 1){
        setStyle(element, { opacity: 
                                    (/Gecko/.test(navigator.userAgent) &&
                                     !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 
                                    0.999999 : null });
        if(/MSIE/.test(navigator.userAgent))  
            setStyle(element, {filter: getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});  
    } else {  
        if(value < 0.00001) value = 0;  
        setStyle(element, {opacity: value});
        if(/MSIE/.test(navigator.userAgent))  
            setStyle(element, 
                     { filter: getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') +
                       'alpha(opacity='+value*100+')' });  
    }
}  

function setStyle(element, style) {
    element = $(element);
    for (var name in style)
        element.style[name] = style[name];
}

function getStyle(element, style) {
    element = $(element);
    var value = element.style[style];
    if (!value) {
        if (document.defaultView && document.defaultView.getComputedStyle) {
            var css = document.defaultView.getComputedStyle(element, null);
            value = css ? css.getPropertyValue(style) : null;
        } else if (element.currentStyle) {
            value = element.currentStyle[style];
        }
    }

    if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
        if (getStyle(element, 'position') == 'static') value = 'auto';

    return value == 'auto' ? null : value;
}

var current = null

function crossFade() {
    current = current || $('first_quote')
    var next = (current.nextSibling && current.nextSibling.nodeName) == "P" ? current.nextSibling : $('first_quote')
    setOpacity(next, 0.0)
    next.className = "quote"
    var x = 0.0
    var interval = setInterval(function() {
        x = x + 0.05
        setOpacity(current, 1.0 - x)
        setOpacity(next, x)
        if (x >= 0.99) {
            clearInterval(interval)
            current.className = "hidden quote"
            setOpacity(current, 1)
            current = next
        }
    }, 50)
}

function cycleQuotes() {
    setInterval(crossFade, 20000) //8000
}