$(document).ready(function() {
	// exibe/oculta submenus
	/*$("li.menu").hover(
		function(){
			$(this).find('.submenu').slideToggle();
		},
		function(){
			$(this).find('.submenu').slideToggle();
		}
	);*/
	
	$("li.menu").mouseenter(
		function(){
//			if($(this).find('.submenu').css('display') == 'none')
			$('.submenu').hide().removeClass('ativo').addClass('inativo');
			$('.menu').removeClass('ativo').addClass('inativo');
			if( $(this).find('.submenu').attr('class') != undefined)
				$(this).addClass('ativo').find('.submenu').show().removeClass('inativo').addClass('ativo');
		}
		/*,
		function(){
			if($(this).find('.submenu').css('display') != 'none')
				
		}*/
	);
	
	// exibe/oculta legenda com fade
	$("#image").find('a').find('img').hover(
		function (){
			$(this).parent().parent().find('.img_legenda').animate( { opacity: 0.8 } , 500 );
		},
		function (){
			$(this).parent().parent().find('.img_legenda').stop().animate( { opacity: 0.0 } , 500 );
		});	
		
	// fade na troca de image
	$("#image").fadeIn(1000);
	$("#home").fadeIn(1000);
	setTimeout("$('#home').fadeOut(1000);",9000)
	
	var random = 0;
	var tot = $( '.currarq' ).hide().length;
	$( '.curr_arq_0' ).show();
	
	var intervalo = window.setInterval(function() {

		var vel = 800;
		
		if(random == tot){
			random = 0;
		}
		$( '.curr_arq_' + random ).fadeOut( vel , function() {

			var r = random + 1;

			if( r == tot){
				r = 0;
			}

			$( '.curr_arq_' + r ).fadeIn( vel );
			random++;
		} );

	}, 5000);
	
	var rndm = 1;
	var tot2 = $( '.img_contato' ).find('img').hide().length;
	$( '.img_contato_1' ).show();
	
	var interv = window.setInterval(function() {

		var vel = 800;
		
		if(rndm > tot2){
			rndm = 1;
		}
		$( '.img_contato_' + rndm ).fadeOut( vel , function() {

			var r = rndm + 1;

			if( r > tot2){
				r = 1;
			}

			$( '.img_contato_' + r ).fadeIn( vel );
			rndm++;
		} );

	}, 3000);
	
});

$(window).unload(function() {
	$("#image").fadeOut(1000);
});

/*
function mostraSubmenu(div){ // abre o submenu
	var div_submenu = div+'_submenu';
	document.getElementById(div).className="menu ativo";
	document.getElementById(div_submenu).className="submenu ativo";
}

function escondeSubmenu(div){ // fecha o submenu
	var div_submenu = div+'_submenu';
	document.getElementById(div).className="menu inativo";
	document.getElementById(div_submenu).className="submenu inativo";
}
*/
function clearField(field){
	if (field.value == field.defaultValue) field.value = "";
}

function popField(field){
	if (field.value == "") field.value = field.defaultValue;
}