//Browser Detect
(function($) {
    var userAgent = navigator.userAgent.toLowerCase();

    $.browser = {
        version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1],
        safari: /webkit/.test(userAgent),
        opera: /opera/.test(userAgent),
        msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
        mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
    };

})(jQuery);


$(function(){
	$('p.back a').click(function(e){
		e.preventDefault();
		window.history.back();
	});	
});



function validaForm(){
	var valid = true;
	if($('#nome').val().length == 0){
		$('#inf_name').show();
		valid=false;
	} else {
		$('#inf_name').hide();
	}
	if($('#telefone').val().length == 0){
		$('#inf_tele').show();
		valid=false;
	} else {
		$('#inf_tele').hide();
		if(!validaTelefone($('#telefone').val())){
			$('#inf_tele_format').show();
			valid=false;				
		} else {
			$('#inf_tele_format').hide();
		}
	}
	
	if($('#email').val().length == 0){
		$('#inf_email').show();
		valid=false;
	} else {
		$('#inf_email').hide();
		if(!validaEmail($('#email').val())){
			$('#inf_email_format').show();
			valid=false;				
		} else {
			$('#inf_email_format').hide();
		}
	}
	
	if($('#msg').val().length == 0){
		$('#inf_msg').show();
		valid=false;
	} else {
		$('#inf_msg').hide();
	}
	return valid;
}



function slideShowSmall(intervalo, velocidade){
	$('ul li[id!=image0]').each(function(){
		var mydiv = $(this).find('div.largeimage');			
		$(mydiv).css('overflow','hidden');
		if($(mydiv).children('div').length > 1){
			//alert("ChangeImage('" + $(mydiv).attr('id') + "'," + 500 + ")");
			window.setInterval("ChangeImage('" + $(mydiv).attr('id') + "'," + 500 + ")", 3000);
			
		}	
	});
}


function ChangeImage(divid,velocidade){
	var showdiv = $('#'+ divid);		
	var largura = $(showdiv).find('img:first').width();
	var altura = $(showdiv).find('img:first').height();
	var totalimagens = $(showdiv).find('img').length;
	$(showdiv).children('div').css('position','absolute');
	$(showdiv).height(altura).width(largura);		
	$(showdiv).children('div:last').animate({'opacity': 0.0}, velocidade, function(){				
		$(showdiv).children('div:last').css('opacity','1.0');
		$(showdiv).children('div:last').prependTo($(showdiv));
	});
};
	
	
	

function validaTelefone(telefone){
	return (telefone.length == 9);
}
