$(document).ready(function(){
	$('#foto_cab img').fadeIn('slow');
});

$(document).ready(function(){
//Desce menu para selecionar o tema
	$ativo = false;
	$('#foto_cab').hover( function() {
		$ativo = true;
		setTimeout(function(){
			if($ativo){
				$('#foto_cab .info').animate({'margin-top': '-40px'}, 'slow');
			}
		}, '500');
	}, function() {
		$ativo = false;
		setTimeout(function(){
			if(!$ativo){
				$('#foto_cab .info').animate({'margin-top': '0'}, 'slow');
			}
		}, '0');
	});
});

$(document).ready(function(){
	//Links Internos
	$('#links_internos a.foto').hover( function() {
		$(this).find('img').stop().animate({'margin-top': '-30px'}, 'slow');
	}, function() {
		$(this).find('img').stop().animate({'margin-top': '0'}, 'slow');
	});
	
	//Fotos da Esturuta da Empresa
	$('#fotos_estrutura .foto').hover( function() {
		$(this ).find('a.titulo').fadeIn();
	}, function() {
		$(this ).find('a.titulo').fadeOut();
	});
	
	//Links Eventos
	$('#lista_eventos a.foto').hover( function() {
		$(this).find('img').stop().animate({'margin-top': '-30px'}, 'slow');
	}, function() {
		$(this).find('img').stop().animate({'margin-top': '0'}, 'slow');
	});
	
	//Ampliar Foto de Eventos
	$('#conteudo_evento .foto a').hover( function() {
		$(this).find('img').stop().animate({'margin-top': '-30px'}, 'slow');
	}, function() {
		$(this).find('img').stop().animate({'margin-top': '0'}, 'slow');
	});
	
	//Botao Login
	$('a.botoes_enviar').hover( function() {
		$(this).find('span').stop().animate({'margin-top': '0'}, 'slow');
	}, function() {
		$(this).find('span').stop().animate({'margin-top': '-27px'}, 'slow');
	});
	
	$('a.botoes_enviar').focus( function() {
		$(this).find('span').stop().animate({'margin-top': '0'}, 'slow');
	});
	
	//Modal Anterior
	$('#modal a.anterior').hover( function() {
		$(this).find('span').stop().animate({'margin-left': '0'}, 'slow');
	}, function() {
		$(this).find('span').stop().animate({'margin-left': '-160px'}, 'slow');
	});
	
	//Modal Poxima
	$('#modal a.proxima').hover( function() {
		$(this).find('span').stop().animate({'margin-left': '0'}, 'slow');
	}, function() {
		$(this).find('span').stop().animate({'margin-left': '160px'}, 'slow');
	});
	
});


/* Formulário de Login  */

$(document).ready(function() {
 
    // cache references to the input elements into variables
    var passwordField = $('input[name=txtSenha]');
    var emailField = $('input[name=txtLogin]');
    // get the default value for the email address field
    var emailFieldDefault = emailField.val();
 
    // add a password placeholder field to the html
    passwordField.after('<input id="passwordPlaceholder" type="text" value="senha" autocomplete="off" class="senha" />');
    var passwordPlaceholder = $('#passwordPlaceholder');
 
    // show the placeholder with the prompt text and hide the actual password field
    passwordPlaceholder.show();
    passwordField.hide();

    // when focus is placed on the placeholder hide the placeholder and show the actual password field
    passwordPlaceholder.focus(function() {
        passwordPlaceholder.hide();
        passwordField.show();
        passwordField.focus();
    });
    // and vice versa: hide the actual password field if no password has yet been entered
    passwordField.blur(function() {
        if(passwordField.val() == '') {
            passwordPlaceholder.show();
            passwordField.hide();
        }
    });
 
    // when focus goes to and moves away from the email field, reset it to blank or restore the default depending if a value is entered
    emailField.focus(function() {
        if(emailField.val() == emailFieldDefault) {
            emailField.val('');
        }
    });
    emailField.blur(function() {
        if(emailField.val() == '') {
            emailField.val(emailFieldDefault);
        }
    });
 
});



function submit_login() {
	document.forms["form_login"].submit();
}

function submit_contato() {
	//document.forms["form_contato"].submit();
	$.ajax({
		type: "POST",
		url: window.location,
		data: $('form#form_contato').serialize(),
		cache: false,
		beforeSend: function(){
			$('.loading').show();
		},
		success: function(txt){
			$('.loading').hide();
			$('.ajaxResult').html(txt);
			$('html,body').animate({scrollTop: $('.ajaxResult').offset().top}, 1000);
		},
		error: function(){
			$('.loading').hide();
			alert('Houve um erro ao submeter o formulário. Tente novamente mais tarde.');
		}
	});
}

function submit_orcamento() {
	//document.forms["form_orcamento"].submit();
	$.ajax({
		type: "POST",
		url: window.location,
		data: $('form#form_orcamento').serialize(),
		cache: false,
		beforeSend: function(){
			$('.loading').show();
		},
		success: function(txt){
			$('.loading').hide();
			$('.ajaxResult').html(txt);
			$('html,body').animate({scrollTop: $('.ajaxResult').offset().top}, 1000);
		},
		error: function(){
			$('.loading').hide();
			alert('Houve um erro ao submeter o formulário. Tente novamente mais tarde.');
		}
	});
}

function submit_evento() {
	//document.forms["form_evento"].submit();
	$.ajax({
		type: "POST",
		url: window.location,
		data: $('form#form_evento').serialize(),
		cache: false,
		beforeSend: function(){
			$('.loading').show();
		},
		success: function(txt){
			$('.loading').hide();
			$('.ajaxResult').html(txt);
			$('html,body').animate({scrollTop: $('.ajaxResult').offset().top}, 1000);
		},
		error: function(){
			$('.loading').hide();
			alert('Houve um erro ao submeter o formulário. Tente novamente mais tarde.');
		}
	});
}


/* Abre Foto Estrutura  */

function abre_foto(num,titulo,cod){
    
	var foto_atual = $('#modal .foto_atual').val();
	$('#modal .foto_atual').val(cod);
	foto_atual = cod;
		
	if(foto_atual=='1'){
		$('#modal a.anterior').hide();
	}else{
		$('#modal a.anterior').show();
	}
	var numero_fotos = $('#fotos_estrutura div').length;
	if(foto_atual==numero_fotos){
        $('#modal a.proxima').hide();
    }else{
        $('#modal a.proxima').show();
    }
	
	var link = APP_HOST+'Images/Site/Empresa/Estrutura/foto-'+num+'.jpg';
    $('#modal').show();
	$('#foto_estrutura').hide();
    $('#legenda_estrutura').hide();
	$('#foto_estrutura').attr('src',link);
	$('#foto_estrutura').fadeIn();
	$('#legenda_estrutura').html(titulo);
	$('#legenda_estrutura').fadeIn();
	
	
}



function foto_anterior() {
    var foto_atual = $('#modal .foto_atual').val();
	foto_atual--;
	$('#fotos_estrutura div:nth-child('+foto_atual+') a.foto').click();
}

function foto_proxima() {
    var foto_atual = $('#modal .foto_atual').val();
	foto_atual++;
	$('#fotos_estrutura div:nth-child('+foto_atual+') a.foto').click();
}

function fechar_modal() {
    $('#modal').fadeOut();
}


function marca_checkbox(id) {
    $('#marca_'+id).hide();
	$('#desmarca_'+id).show();
	$('input.'+id).attr('value', 'marcado');
}

function desmarca_checkbox(id) {
    $('#desmarca_'+id).hide();
	$('#marca_'+id).show();
	$('input.'+id).attr('value', 'desmarcado');
}

function marca_radio(id,opcao,valor) {
	$('#'+id+' a').removeClass('ok');
	$('#'+opcao).addClass('ok');
	$('input.'+id).attr('value', valor);
}


function abre_dropdown(altura) {
	$('#lateral .drop_links').stop().animate({'height': altura}, 'slow');
	$('#lateral a.abre_drop').hide();
	$('#lateral a.fecha_drop').show();
}

function fecha_dropdown(altura) {
	$('#lateral .drop_links').stop().animate({'height': '27px'}, 'slow');
	$('#lateral a.fecha_drop').hide();
	$('#lateral a.abre_drop').show();
}



$(document).ready(function(){
	$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
});


function filtra_duvidas(categoria) {
    $('#tags ul li').removeClass('marcado');
	$('#tags ul .'+categoria).addClass('marcado');
	$('#duvidas div.duvida').hide();
	$('#duvidas div.'+categoria).fadeIn(300);
}


function filtra_noticias(categoria) {
    $('#tags ul li').removeClass('marcado');
	$('#tags ul .'+categoria).addClass('marcado');
	$('#ultimas_noticias li.noticia').hide();
	$('#ultimas_noticias li.'+categoria).fadeIn(300);
}

function exibir_todas() {
    $('#tags ul li').removeClass('marcado');
	$('#tags ul .todas').addClass('marcado');
	$('#duvidas div.duvida').hide();
	$('#duvidas div.duvida').fadeIn(300);
}

function exibir_todas_noticias() {
    $('#tags ul li').removeClass('marcado');
	$('#tags ul .todas').addClass('marcado');
	$('#ultimas_noticias li.noticia').hide();
	$('#ultimas_noticias li.noticia').fadeIn(300);
}

