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;
					}
				}
			}
		}
	}
}

function setLayerOn(id)
{
	if ( document.getElementById && document.getElementById( id) != null) {	
		var a = document.getElementById( 'modelo_perfil');
		var b = document.getElementById( 'modelo_fotos');
		if( obj = document.getElementById( id).getElementsByTagName( 'a')) {
			if( obj.length == 2 ) {
				obj[0].onclick = function() {
					a.className = 'on';
					b.className = 'off';
					this.className = 'on';
					obj[1].className = ''; 
				}
				obj[1].onclick = function() {
					a.className = 'off';
					b.className = 'on';
					this.className = 'on';
					obj[0].className = ''; 				
				}				
			}
		}
	}
}

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