/*
	#################################################
	#    Auto: Thiago Silva (Pedreiro Digital)      #
	#         www.pedreirodigitalweb.com.br         #       
	#################################################
*/
var imagens = new Array();
var fotos = new Array();
var IMG = new Image();
var conta_foto = 0;
var fotos_noticia_array = new Array();
var fotos_noticia = new Image();
var fotos_noticia_id = 0;

var utilidades = function()
{
}

utilidades.prototype.loader_thumb = function()
{
	var a = 0;
	$('.thumb_foto').each
	(
		function()
		{
			fotos.push($(this));
			$(this).css({opacity:0});
			IMG.src = $(this).attr('src');
			IMG.onLoad = utilidades.prototype.thumb_completo();
		}
	);
}

utilidades.prototype.thumb_completo = function()
{
	$(fotos[conta_foto]).attr('src',IMG.src);
	$(fotos[conta_foto]).animate({opacity:1});
	conta_foto++;
}

utilidades.prototype.limitar = function(texto,tamanho,simbolo) 
{
	nova='';  
	for(i=0;i<tamanho;i++) 
	{  
		if(texto.substr(i,1) == " ")
		{
			nova += ' '+texto.substr(0,i);  
		}
	}  
	return nova+simbolo;  
}

utilidades.prototype.email_enviar = function()
{
	if(class_util.validar_campos(['nome','email','mensage']))
	{
	  var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	  if (regmail.test($("#email").val())) 
	  {
		$.ajax
		(
			{
				type: 'POST',
				url: host + 'lib/php/contato.php',
				data: 'nome='+$('#nome').val()+'&email='+$('#email').val()+'&assunto='+$('#assunto').val()+'&mensage='+$('#mensage').val(),
				dataType: 'xml',
				success: utilidades.prototype.emailCompleto
			}
		);
	  } 
	  else 
	  {
		  $('.msg').html('o email informado e invalido tente novamente!');
		  return false;
	  }
	}
	else
	{
		$('.msg').html('preencha os campos em branco para continuar');
	}
}

utilidades.prototype.emailCompleto = function(xml)
{
	$(xml).find('dados').each
	(
		function()
		{
			$('.msg').html($(this).find('mensagem').text());
			$('#nome').val('');
			$('#email').val('');
			$('#assunto').val('')
			$('#mensage').val('');
		}
	);
}

utilidades.prototype.load_foto_banda = function(foto)
{
	$('#foto_banda').css({display:'none'});
	imagem.src = host + foto;
	imagem.onload = utilidades.prototype.exibir_foto_banda;
}

utilidades.prototype.exibir_foto_banda = function()
{
	Width = IMG.width;
	Height = IMG.height;
	Width_Metade = Width / 2;
	Height_Metade = Height / 2;
	
	$('#conteiner .ampliada').animate
	(
		{
			opacity:0
		}
		,500,
		function()
		{
			$('#conteiner').animate
			(
				{
					width:Width,
					height:Height,
					marginLeft:'-'+Width_Metade+'px',
					marginTop: '-'+Height_Metade+'px'
				}
				,500,
				function()
				{
					$('.legenda').slideDown('slow');
					$('#conteiner .ampliada').css
					(
						{
							background:'url('+IMG.src+') no-repeat',
							width:Width,
							height:Height
						}
					);	
			
					$('#conteiner .ampliada').animate
					(
						{
							opacity:1
						}
						,500,
						function()
						{
							if(id_galeria>=(imagens.length-1))
							{
								$('#conteiner .pro').attr('disabled', true);
								$('#conteiner .pro').css({opacity:0.3});
							}
							else
							{
								$('#conteiner .pro').attr('disabled', false);
								$('#conteiner .pro').css({opacity:1});
							}
							
							if(id_galeria<=0)
							{
								$('#conteiner .ant').attr('disabled', true);
								$('#conteiner .ant').css({opacity:0.3});
							}
							else
							{
								$('#conteiner .ant').attr('disabled', false);
								$('#conteiner .ant').css({opacity:1});
							}
							
							$('#conteiner .botoes').slideDown('slow');
						}
					);
				}
			);
		}
	);
}

utilidades.prototype.load_imagens = function()
{
	$('.thumb_foto').each
	(
		function()
		{
		 	fotos_noticia.src = $(this).attr('src');
			$(this).hide();
			fotos_noticia.onload = utilidades.prototype.load_imagens_completo();
		}
	);
}

utilidades.prototype.load_imagens_completo = function()
{
	$('#thumb_foto_' +fotos_noticia_id).attr('src',fotos_noticia.src);
	$('#thumb_foto_' +fotos_noticia_id).fadeIn();
	fotos_noticia_id++;
}

utilidades.prototype.seleciona_menu = function(pagina)
{
	$('opcao, .iten').each
	(
		function()
		{
			if(this.title == pagina)
			{
				$('.menu_'+this.id).css({cursor:'auto'});
				$('.menu_'+this.id).addClass('menu_ativo_'+this.id);
			}
		}
	);
}

utilidades.prototype.enviar_contato = function()
{
	if(!$('#nome').val() || !$('#email').val() || !$('#telefone').val() || !$('#mensagem').val())
	{
		class_alertas.confirmacao('(*) preencha os campos em branco!');
	}
	else
	{
		$.ajax
		(
			{
				type: 'POST',
				url: host + 'lib/php/contatos.php',
				data: utilidades.prototype.get_campos (),
				dataType: 'text',
				success: utilidades.prototype.enviar_completo
			}
		);
		class_alertas.esperar('aguarde enviando seu e-mail...');
	}
}

utilidades.prototype.enviar_completo = function(texto)
{
	class_alertas.confirmacao(texto);
	utilidades.prototype.resetar();
}

utilidades.prototype.resetar = function()
{
	var formulario = document.getElementById('acao');
	for(i=0; i<formulario.length; i++)
	{
		if(formulario[i].type != 'submit')
		{
			formulario[i].value = '';
		}
	}
}

utilidades.prototype.get_campos = function()
{
	var formulario = document.getElementById('acao');
	var campos='';
	for(i=0; i<formulario.length; i++)
	{
		if(formulario[i].type != 'submit')
		{
			campos += formulario[i].id + '=' + formulario[i].value + '&';
		}
	}
	return campos.substr(0,campos.length-1);
}
