﻿$(document).ready(function() {
	$("a.zProdutos").fancybox({
		'padding'		: 5,
		'titleShow'     : true,
		'autoScale'		: false,
		'transitionIn'	: 'inside',
		'transitionOut'	: 'outside',
		'titlePosition' : 'inside',
		'titleFormat'	: function formatTitle(title, currentArray, currentIndex, currentOpts) {
			return '<div id="fancybox-title-inside">' + (title && title.length ? '<b>' + title + '</b>' : '' ) + (currentArray.length>1 ? 'Imagem ' + (currentIndex + 1) + ' de ' + currentArray.length : '' ) + '</div>';
		}
	});
	$("a.zImages").fancybox({
		'padding'		: 5,
		'titleShow'     : true,
		'autoScale'		: true,
		'transitionIn'	: 'inside',
		'transitionOut'	: 'outside',
		'titlePosition' : 'inside',
		'titleFormat'	: function formatTitle(title, currentArray, currentIndex, currentOpts) {
			return '<div id="fancybox-title-inside">' + (title && title.length ? '<b>' + title + '</b>' : '' ) + (currentArray.length>1 ? 'Imagem ' + (currentIndex + 1) + ' de ' + currentArray.length : '' ) + '</div>';
		}
	});	
	$('a.iFrame').each(function(){
		var dWidth		= parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));  
		var dHeight		= parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));
		if (dWidth<=0){dWidth='90%';}
		if (dHeight<=0){dHeight='90%';}
		$(this).fancybox({
			'padding'		: 5,
			'width'			: dWidth,
			'height'		: dHeight,
			'autoScale'		: false,
			'titleShow'     : false,
			'scrolling'		: 'no',
			'transitionIn'	: 'inside',
			'transitionOut'	: 'outside',
			'type'			: 'iframe'
		});
	});
	$('a.iFrame_googlemaps').each(function(){
		$(this).fancybox({
			'padding'		: 5,
			'width'			: '90%',
			'height'		: '90%',
			'autoScale'		: false,
			'titleShow'     : false,
			'scrolling'		: 'no',
			'transitionIn'	: 'inside',
			'transitionOut'	: 'outside',
			'type'			: 'iframe'
		});
	});	
	
	$.tools.validator.localize("pt_BR", {
		'*'				: 'Valor inválido',
		':email'  		: 'Endereço de e-mail inválido',
		':number' 		: 'O valor deve ser numérico',
		':tel' 			: 'O valor deve ser numérico',
		':url' 			: 'URL inválido',
		'[max]'	 		: 'O valor deve ser inferior a $1',
		'[min]'			: 'O valor deve ser maior que $1',
		'[required]'	: 'Este campo é obrigatório'
	});

	$('#myform').validator({ lang: 'pt_BR' });
	
	$('input.valid-number').bind('keypress', function(e) { 
		return ( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) ? false : true ;
	});

	$("#tabs").tabs("div.panes > div", { history:true });
});

	function callajax(href){
		$('#response').html('<span style="font-size:0.9em;">Localizando, aguarde...</span>');
		$.get(href,{},function(response){ 
			$('#response').html(response);
		});
	};
	
function slideSwitch() {
    var $active = $('#slideshow img.active');

	$active.addClass('last-active');

	// verifica se existe um próximo objeto na div #slideshow, caso ele nao exista, retorna para o primeiro
    var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');

	// Codigo que define as transicoes entre as imagens
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
	//Executa a função a cada 5 segundos
	setInterval( "slideSwitch()", 5000 );
})
