/*
	#################################################
	#    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 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');
						}
					);
				}
			);
		}
	);
}


function findObj(n, d) { //v4.01
 var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
 if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
 for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
 if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function ExibeEscondeLayer() { //v6.0
 var i,p,v,obj,args=ExibeEscondeLayer.arguments;
 for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
   if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
   obj.visibility=v; }
}
