
var image=1;
function nextPage(){
		if(image<images){
			image++;
			$('.back').css('cursor','pointer');
			$('.image').attr('src','imagens/midia'+image+'.jpg');
			if(image==images) $('.next').css('cursor','default');
		}
}
function backPage(){		
		if(image>1){
			image--;
			$('.next').css('cursor','pointer');
			$('.image').attr('src','imagens/midia'+image+'.jpg');
			if(image==1) $('.back').css('cursor','default');
		}
}
function showLatter(){
	$('.black_overlay').css('display','block');
	$('.latter').fadeIn('slow');
}
function hiddenMenu(obj){
		if(menuCases>0){
			menuCases--;
			content++;
			$('.menuCases').css('width',menuCases+'%');
			if(content<=62){$('.content').css('width',content+'%');}
			else showNewContent(obj);
			setTimeout(function(){hiddenMenu(obj)},30);
		}
		else showNewContent(obj);
}
function showNewContent(obj){
		$('.div').fadeOut('slow');
		var html=$(obj).html();
		setTimeout(function(){
			$('.div').html(html);
			$('.div').slideToggle('slow');
		},600);
}

function hiddenMenuIn(obj,param){
		if(menuCases>0){
			menuCases--;
					content++;
			$('.menuCases').css('width',menuCases+'%');
			if(content<=62){$('.content').css('width',content+'%');}
			else showContentIn(obj,param);
			setTimeout(function(){hiddenMenuIn(obj,param)},30);
		}
		else showContentIn(obj,param);
}
function showContentIn(obj,param){
		$('.div').fadeOut('slow');
		var html=$(obj).html();
		setTimeout(function(){
			$('.div').html(html);
			$('.iframe').attr('src','integra_'+param+'.html');
			$('.div').slideToggle('slow');
		},600);
}
function showSummary(obj){
		$(obj).slideToggle();
}
function setHome(){
		window.location='';
}
function sendForm(){
		var nome=$('input:eq(0)').attr('value');var email=$('input:eq(1)').attr('value');var ddd=$('input:eq(2)').attr('value');
		var tel=$('input:eq(3)').attr('value');var text=$('textarea:eq(0)').attr('value');
		if(checkEmpty(nome,'Nome')){
			if(!checkEmpty(email,'E-mail')){
				showError();
				$('#error').html('Preencha o campo "e-mail"');
			}
			else if(!checkMail(email)){
				showError();
				$('#error').html('O email informado é inválido!');
			}
			else if(!checkEmpty(ddd,'DDD')){
				showError();
				$('#error').html('Preencha o campo "DDD"');
			}
			else if(!checkEmpty(tel,'Telefone')){
				showError();
				$('#error').html('Preencha o campo "telefone"');
			}
			else {
				showError();
				$('#error').html('Enviando...');	
				$.post('sendmail.php',{
					   nome: nome,
					   email: email,
					   ddd: ddd,
					   tel: tel,
					   text: text
				},function(result){
					if(result==true){
						showError();
						$('#error').html('Sua mensagem foi enviada com sucesso! ');	
						clearForm();
					}
					else {
						showError();
						$('#error').html('Erro ao enviar mensagem! ');	
					}
				});
			}
		}
		else{
			$('#error').html('Preencha o campo "nome"');
			showError();
		}
}
function checkEmpty(value,txt){
	if(value=='' || value==txt) return false;
	else return true;
}
function clearForm(){
	$('input:eq(0)').attr('value','');
	$('input:eq(1)').attr('value','');
	$('input:eq(2)').attr('value','');
	$('input:eq(3)').attr('value','');
	$('textarea:eq(0)').attr('value','');
}
function showError(){
	clearInterval(interval);
	$('#error').fadeIn('slow');
	var interval=setInterval(function(){
	 	$('#error').fadeOut('slow');
	},5000);
	setTimeout(function(){
		clearInterval(interval);
	},5000);
}
//Validação de emails
function checkMail(mail){
        var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        if(typeof(mail) == "string"){
                if(er.test(mail)){ return true; }
        }else if(typeof(mail) == "object"){
                if(er.test(mail.value)){
                                        return true;
                                }
        }else{
                return false;
                }
}
//Validação de emails
function closeLightBox(){
	$('.black_overlay').css('display','none');
	$('.white_content').fadeOut('slow');
}