/**
 * P�gina de func��es em JavaScript
 */

$(function(){
	
	// Barra do topo do site
	$('#openBarTopo li').click(function(){
		$('#acompanhePedido').toggle('blind', {}, 1000);
		$('#openBarTopo li').toggle();
	});
	// requisição da busca
	$('form#buscaPedido img').click(function(){
		
		if ($('form#buscaPedido input').val() != ''){
			buscaPedido($('form#buscaPedido input').val());
		}else{
			alert( "Para prosseguir digite um valor válido!" );
		}
		
	});
	$('img#buscaPedido').click(function(){
		alert($(this).attr('name'));
		buscaPedido($(this).attr('name'));
	});
	function buscaPedido(ordem){
		$('div#acompanhePedido div#content').html('<br><br>Carregando...');
		$.ajax({
			type: "GET",
			url: "functions/get_servico.php",
			data: "ordem="+ ordem,
			success: function(msg){
				$('div#acompanhePedido div#content').html(msg).css('background','transparent');
			}
		});
	}
	
	
	// loopedSlider - Banner rotativo
	$.fn.loopedSlider.defaults.addPagination = true;
	$('#loopedSlider').loopedSlider({
		autoStart: 3500,
		hoverPause: true
	});
	
	// Rollover de imagens dos conteudos
	$('#wrapper .rollover').bind('mouseover mouseout', function(){
		$src = $(this).attr('name');
		$name = $(this).attr('src');
		$(this).attr('src', $src).attr('name', $name);
	});
	
	$('ul#serv1 li').mouseover(function(){
		$('div#imagem1').html('');
		$img = $(this).attr('class');
		$('div#imagem1').html('<img src="images/servicos/'+ $img +'" />');
	});
	$('ul#serv2 li').bind('mouseover', function(){
		$('div#imagem2').html('');
		$img = $(this).attr('class');
		$('div#imagem2').html('<img src="images/servicos/'+ $img +'" />');
	});
	
	// animação no submenu dentro das paginas
	$('.treeCollun ul li a.noAtive').hover(function(){
		$(this).stop().animate({paddingLeft:'10px', color:'#cacaca'},300);
		},function(){
		$(this).stop().animate({paddingLeft:'0px', color:'#a4a4a4'},300);
	});
	
	// testando formulario de contato
	$('form#testeForm').submit(function(){
		  $('form#testeForm .error').remove();
			var hasError = false;
			$('.requiredField').each(function() {
				if(jQuery.trim($(this).val()) == '') {
					var labelText = $(this).prev('label').text();
					$(this).parent().append('<span class="error">'+labelText+' requerido</span>');
					hasError = true;
				} else if($(this).hasClass('email')) {
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					if(!emailReg.test(jQuery.trim($(this).val()))) {
						var labelText = $(this).prev('label').text();
						$(this).parent().append('<span class="error">'+labelText+' inválido</span>');
						hasError = true;
					}
				}
			});
			if(!hasError) {
				return true;
			}
			return false;
	  });
	
	// starta a galeria
    $('div.lightBox a').lightBox();
    
});
