/**
 * Top Vision
 */

var x = 0;
$(function() {

	// Mascaras de input
	$('.mask-input').each(function() {
		$(this).attr('data', $(this).val());
	});
	$('.mask-input').focus(function() {
		var t    = $(this),
		    data = t.attr('data');
		if( t.val() == data )
		    t.val('');
	}).blur(function() {
		var t    = $(this),
		    data = t.attr('data');
		if( t.val() == '' )
		    t.val(data);
	});

	$('a[rel="zoom"]').fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$('.galeria-troca').find('img').each(function() {
		x++;
		$(this)
		.attr('id', 'img-'+x)
		.css('position', 'absolute')
		.hide();		
	});
	
	if( x > 0 )
		galeria();

	// Validando form de contato
	$('#form-contato').submit(function(e){
		
		var erro  = '';
		var value = '';
		var formulario = [ {
			"campo" : "nome",
			"data"  : "Nome"
		}, {
			"campo" : "email",
			"data"  : "E-mail"
		}, {
			"campo" : "mensagem",
			"data"  : "Mensagem"
		} ];

		var totalCampos = formulario.length;

		for ( i = 0; i < totalCampos; i++ ) {
			value = $('#'+formulario[i].campo).val();
			if (formulario[i].data == value) 
				{erro += formulario[i].data + '\n';}
		}
		if ( erro != '' ) {
			alert( 'Campos Obrigatórios: \n' + erro );
			e.preventDefault();
		} 

	});

	$('.zoom').live('mouseover', function() {
		$(this).fancybox();
	});


	var $container = $(".galeria-troca");
	$container.wtRotator({
		width              : 335,
		height             : 502,
		auto_start         : true,
		delay              : 2500,
		transition         : "block.top.zz",
		transition_speed   : 500,
		block_size         : 100,
		vert_size          : 50,
		horz_size          : 50,
		cpanel_align       : "BR",
		display_thumbs     : false,
		display_dbuttons   : false,
		display_playbutton : false,
		display_tooltip    : false,
		display_numbers    : false,
		display_timer      : true,
		mouseover_pause    : false,
		cpanel_mouseover   : false,
		text_mouseover     : false,
		text_effect        : "down",
		shuffle            : true,
		block_delay        : 50,
		vstripe_delay      : 100,
		hstripe_delay      : 150
	});


});

function galeria()
{
    var i = 1;
	$('#img-' + i).fadeIn(500);
	window.setInterval(function() {
		$('.galeria-troca > img').fadeOut(500);
		i++;
		if( i > x )
			i = 1;
		$('#img-' + i).fadeIn(500);
	}, 5000);
}
