
$(document).ready(function() {
		
	//document.body.style.overflow='hidden';
	$("html").css("overflow", "hidden");
	
	/* NEWSLETTER */
	$('.news').click(function(event){
		event.preventDefault();
		event.stopPropagation();
		$('.newsmsg').hide(0).html("");
		$('.newsletter').fadeIn();
		$('.moldura').one("click", function() { // fechar news ao clicar fora
			$('.newsletter').fadeOut();
		});
	});
	
	
	$('.newsletter .fechar').live("click", function(event){
		event.preventDefault();
		$('.newsletter').fadeOut();
	});
	
	
	$('.newsletter .enviar').live("click", function(event){
		event.preventDefault();
		
		var erroform = 0;
		$('.newsmsg').hide(0).html("");
		
		if($.validateEmail($("#newsemail").val()) == false || $("#newsemail").val().lenght == 0 || $("#newsemail").val() == "" || $("#newsemail").val() == null) erroform = '*Insira um e-mail válido.';
		
		if($("#newsnome").val().lenght == 0 || $("#newsnome").val() == "" || $("#newsnome").val() == null) erroform = "*Preeencha todos os campos.";
		
		alert(erroform);
		if(erroform != 0){
			$('.newsmsg').html(erroform).fadeIn();
		}
		else{
			$.post(
					"../newsletter/newsletter.php", 
					$("#fornewsletter").serialize(),
					function(data) {
						$('.newsmsg').html("*Seus dados foram cadastrados com sucesso.").fadeIn();
						$("#newsnome").val("");
						$("#newsemail").val("");
					}
			);
		}
		
	});
	
	
	/* AMPLIAR CONTEUDO */
	$('.ampliar').click(function(event){
		event.preventDefault();
		altquadro();
	});
	
	
	/* ABAS DO CONTEUDO */
	$('.abas a').click(function(event){
		event.preventDefault();
		
		$('.conteudo').hide(0);		
		$('.fotos').hide(0);
		
		var target = 0;
		
		if($(this).hasClass('active')){
			$('.abas a').removeClass('active');
			var target = 0;
		} else {
			$('.abas a').removeClass('active');
			$(this).addClass('active');
			var target = $(this).attr('conteudo');
		}
		 
		$('.conteudo'+target).fadeIn();
		if($('#tS'+target).length) $('#tS'+target).fadeIn("slow",function(){ $oScrollbar.tinyscrollbar_update(); });
		else $oScrollbar.tinyscrollbar_update();
		
	});
	
	
	/* CARREGA FOTOS */
	if($('.fotos').length){
		$.getScript("../../js/jquery.thumbnailScroller.js", function() {
			
			for(i=0; i<5; i++){
				if($("#tS"+i).length){
					$("#tS"+i).thumbnailScroller({ 
						scrollerType:"clickButtons", 
						scrollerOrientation:"horizontal", 
						scrollSpeed:2, 
						scrollEasing:"easeOutCirc", 
						scrollEasingAmount:600, 
						acceleration:4, 
						scrollSpeed:800, 
						noScrollCenterSpace:10, 
						autoScrolling:0, 
						autoScrollingSpeed:2000, 
						autoScrollingEasing:"easeInOutQuad", 
						autoScrollingDelay:500 
					});
					
					if(i>0) $("#tS"+i).hide(0);
				}
			}
			
		});
	}
	
	
	/* CARREGA SCROLLBAR */
	if($('#scrollbar1').length){
		$.getScript("../../js/jquery.tinyscrollbar.min.js", function() {
			$oScrollbar = $('#scrollbar1');
			$oScrollbar.tinyscrollbar();
		});
	}
	
	
	
	var randomico = Math.random()*100;
	
	/* CARREGA NEWSLETTER */
	$.get('../newsletter/newsletter.html?rand='+randomico, function(data) {	$('body').append(data); });
	
	/* FALE CONOSCO */
	$('.blankOnFocus').blankOnFocus();
	
	
});

var conteudoativo = 2;
function altquadro(){
	if($('.quadro').width() < 800){
		$('.ampliar').html('x');
		$('.quadro').width(800);
		$('#scrollbar1').width(750);
		$('.abas').css('marginLeft',150);
		$('.quadro').addClass('quadroampli');
		$('.quadro .conteudo').each(function(){
			if($(this).find('.coluna')[1]){
				$(this).find('.coluna').css('float','left').width('315px');
				$(this).find('.coluna:first-child').css('marginRight','50px');
			}
			else{
				$(this).find('.coluna').width('720px');
			}
		});
		
		$('#scrollbar1 .viewport').width('720px');
		
		/*
		if($('.quadro .conteudo'+conteudoativo+' .coluna')[1]){
			$('.quadro .coluna').css('float','left').width('315px');
			$('.quadro .coluna:first-child').css('marginRight','50px');
		}
		else{
			$('.quadro .coluna').width('720px');
		}
		*/
	} else {
		$('.ampliar').html('+');
		$('.quadro').width(303);
		$('#scrollbar1').width(262);
		$('.abas').css('marginLeft',-350);
		$('.quadro').removeClass('quadroampli');
		/*
		if($('.quadro .conteudo'+conteudoativo+' .coluna')[1]){
			$('.quadro .coluna').css('float','none');
			$('.quadro .coluna:first-child').css('marginRight','0px');
		}
		$('.quadro .coluna').width('230px');
		*/
		
		$('.quadro .conteudo').each(function(){
			if($(this).find('.coluna')[1]){
				$(this).find('.coluna').css('float','none');
				$(this).find('.coluna:first-child').css('marginRight','0px');
			}
		});
		$('.quadro .coluna').width(230);
		$('#scrollbar1 .viewport').width(230);
		
	}
	
	$oScrollbar.tinyscrollbar_update();
}



/* VALIDA E-MAIL */
$.validateEmail = function (emailt){
		
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(emailReg.test(emailt))
		return true;
	else
		return false;
};



/* ZERA CAMPOS ON FOCUS */
$.fn.blankOnFocus=function(){
		$(this).each(function() { $(this).attr('label',$(this).val()); });
		$(this)
			.focus(function(){var $o=$(this);if($o.attr('label')==$o.val())$o.val('');})
			.blur(function(){var $o=$(this);if($.trim($o.val())=='')$o.val($o.attr('label'));});
		/* alert(2); */
};



/* ENVIA EMAIL FALE CONOSCO */
function enviafaleconosco(e){
	
	$(e).preventDefault;
	//formulario = $(e).closest("form");
	erroform = 0;
	$(".msgerro").hide(0);
	
	$("#formfaleconosco").find('.req').each(function(){
		if($(this).val().lenght == 0 || $(this).attr('label') == $(this).val()){
			erroform = 'campo req'; // campo não preenchido
		}
	});
	
	if($.validateEmail($("#formfaleconosco").find("#email").val()) == false) erroform = 'campo email';
	
	if(erroform == 0){
		$.post(
				"faleconosco.php", 
				$("#formfaleconosco").serialize(),
				function(data) {
					/* alert('ok'); */
					$(".conteudo0").hide(0);
					$(".conteudo1").slideDown();
					$oScrollbar.tinyscrollbar_update();
				}
		);
	} else {
		/* alert(erroform); */
		$(".msgerro").fadeIn();
		return false;
	}
}
