// MENU

function abrir ( opc ) {
	
	if ( ! $( opc ).parent().hasClass( 'aberto' ) ) {
		
		fechaTodos();
		
		$( opc ).parent().addClass( 'aberto' );
		
		altura = retornaAltura( $( opc ).parent().attr( 'id' ) );
		
		if ( $(opc).parent().attr( 'id' ) == 'equipe' ) {
			
			$( opc ).parent().animate( { height: altura }, 250, vaiParaEquipe );
			
		} else if ( $(opc).parent().attr( 'id' ) == 'projetos' ) {
			
			$( opc ).parent().animate( { height: altura }, 250, vaiParaProjetos );
		
		} else {
		
			$( opc ).parent().animate( { height: altura }, 250 );
		
		}
		
	} else {
		
		if ( $(opc).parent().attr( 'id' ) == 'equipe' ) {
			
			vaiParaEquipe();
		
		} else {
			
			fechaOpcao( opc );
			
		}
		
	}
	
}

function vaiParaEquipe () {
	
	window.location = '?area=Equipe';
	
}

function vaiParaProjetos () {
	
	window.location = '?area=Todos';
	
}

function fechaTodos () {
	
	var opcoes = $( '#opcoes' ).children();
	
	for ( var i = 0 ; i < opcoes.length ; i ++ ) {
		
		if ( $( opcoes[ i ] ).hasClass( 'aberto' ) ) {
			
			fecha( opcoes[ i ] );
			
		}
		
	}
	
}

function fecha ( opc ) {
	
	$( opc ).removeClass( 'aberto' );
	
	$( opc ).animate( { height: '30px' }, 250 );
	
}

function fechaOpcao ( opc ) {
	
	$( opc ).parent().removeClass( 'aberto' );
	
	$( opc ).parent().animate( { height: '30px' }, 250 );
	
}

function retornaAltura ( id ) {
	
	switch ( id ) {
		
		case 'login': case 'webmail':
			
			return '85px';
			
		break;
		
		default:
			
			return '325px';
			
		break;
		
	}
	
}

function arrasta ( obj ) {
	
}

function proximaPagina ( obj ) {
	
	var pgs = $( obj ).parent().parent().children( '.paginas' );
	
	var pg = $( pgs ).children();
	
	var largura = 287;
	
	var larguraBarra = 173;
	
	var a = $( pgs ).attr( 'id' );
	
	var chave = a.slice( 0, 1 );
	
	if ( chave == 'n' ) {
		
		largura = 325;
		
		larguraBarra = 280;
		
	}
	
	var indice = parseInt( a.slice( 1 ) );
	
	total = pg.length;
	
	if ( indice + 1 < total ) {
		
		indice ++;
		
		$( pgs ).attr( 'id', chave + indice );
		
		$( pgs ).animate( { left: - indice * largura }, 250 );
		
		var larguraIndicador = larguraBarra / total;
		
		var novaMargem = ( indice * larguraIndicador ) + 'px';
		
		$( obj ).parent().children( '.barra' ).children( '.indicador' ).animate( { left: novaMargem }, 250 );
		
	}
	
}

function paginaAnterior ( obj ) {
	
	var pgs = $( obj ).parent().parent().children( '.paginas' );
	
	var pg = $( pgs ).children();
	
	var largura = 287;
	
	var larguraBarra = 173;
	
	var a = $( pgs ).attr( 'id' );
	
	var chave = a.slice( 0, 1 );
	
	if ( chave == 'n' ) {
		
		largura = 325;
		
		larguraBarra = 280;
		
	}
	
	var indice = parseInt( a.slice( 1 ) );
	
	total = pg.length;
	
	if ( indice - 1 >= 0 ) {
		
		indice --;
		
		$( pgs ).attr( 'id', chave + indice );
		
		$( pgs ).animate( { left: - indice * largura }, 250 );
		
		var larguraIndicador = larguraBarra / total;
		
		var novaMargem = ( indice * larguraIndicador ) + 'px';
		
		$( obj ).parent().children( '.barra' ).children( '.indicador' ).animate( { left: novaMargem }, 250 );
		
	}
	
}

// NOTÍCIAS

function configura ( obj ) {
	
	obj.onmouseover = null;
	
	abreNoticia( obj );
	
	$( obj ).mouseenter( function () {
			
			abreNoticia( obj );
			
			//$( obj ).children( '.principal' ).animate( { opacity: '.5' }, 250 );
			
			//$( obj ).children( '.info' ).animate( { height: '330px' }, 250 );
			
		}
	
	).mouseleave(function(){
			
			fechaNoticia( obj );
			//$( obj ).children( '.principal' ).animate( { opacity: '1' }, 250 );
			
			//$( obj ).children( '.info' ).animate( { height: '70px' }, 250 );
			
		}
		
	);
	
}

function abreNoticia ( obj ) {
	
	$( obj ).children( '.info' ).animate( { height: '330px' }, 400 );
	
	$( obj ).children( '.principal' ).animate( { opacity: '.5' }, 400 );
	
}

function fechaNoticia ( obj ) {
	
	$( obj ).children( '.info' ).animate( { height: '73px' }, 250 );
	
	$( obj ).children( '.principal' ).animate( { opacity: '1' }, 250 );
	
}

function abreZoom(arquivo,largura,altura) {
	
	var zoom = window.open("zoom.php?arquivo="+arquivo, "zoom", "width = "+largura+", height = "+altura);
	
}

function alternaUpload() {
	
	var modulo = document.getElementById('moduloUpload');
	
	if(modulo.style.display == 'block') {
		
		modulo.style.display = 'none';
		
	} else {
		
		modulo.style.display = 'block';
		
	}
	
}
