
var atual = 0;
var intervalID;
var mouseOver = false;

function setOn( id, tag, pos) {
    if ( document.getElementById && document.getElementById( id) != null) {
        if( obj = document.getElementById( id).getElementsByTagName( tag)){
            if( obj.length > 0 ) {
                LINK = document.getElementById( id).getElementsByTagName( 'div').item(0).getElementsByTagName( 'a');
                for( i = 0; i < obj.length; i++) {
                    node = obj[i];node.i = i;
                    nod2 = LINK[i];
                    if( i == pos) {
                        node.className = 'on';
                        nod2.className = 'on';
                    } else {
                        node.className = '';
                        nod2.className = '';
                    }

                    node.onmouseover = function() {
                        mouseOver = true;
                    }
                    node.onmouseout = function() {
                        mouseOver = false;
                    }
                }
                if( !mouseOver)
                    if( ++pos >= obj.length) pos = 0;
            }
        }
    }
    atual = pos;
}
function setFunction( id, tag, pos) {
    if ( document.getElementById && document.getElementById( id) != null) {
        if( obj = document.getElementById( id).getElementsByTagName( tag).item(0).getElementsByTagName( 'a')) {
            if( obj.length > 0 ) {
                for( i = 0; i < obj.length; i++) {
                    node = obj[i]; node.i = i;
                    if( i == pos) {
                        node.className = 'on';
                    } else {
                        node.className = '';
                    }
                    node.onmouseover = function() {
                        mouseOver = true;
                    }
                    node.onclick = function() {
                        setOn( 'dest_fotos', 'span', this.i);
                    }
                    node.onmouseout = function() {
                        mouseOver = false;
                    }
                }
            }
        }
    }
}

window.onload = window.reload = function() {
    setFunction( 'dest_fotos', 'div', atual);
    setOn( 'dest_fotos', 'span', atual);
    intervalID = setInterval( "setOn( 'dest_fotos', 'span', atual)", 5000);
}