$(document).ready(function(){
	$(".imagem").click(function(){
		if($(".imagem.active").attr('id') != $(this).attr('id')){
			$(".imagem.active").animate({'width':'154px'}, 300, function(){
				$(this).children('.big2').hide();
				$(this).children('.big').hide();
			}).addClass('small').removeClass('active');
			$(this).animate({'width':'588px'}, 300).removeClass('small').addClass('active');
			
			//animação com o bg imagem1
			$(this).children('.big').show();
			$(this).children('.big2').hide();
			
			setTimeout(function(){
				if($(".imagem.active .big2").length > 0){
					$(".imagem.active .big").hide();
					$(".imagem.active .big2").show();
				}
			},5000);
		}
	}, function(){
		
	});
	

	$(".imagem").hoverIntent({
		over: makeTall, 
		timeout: 500, 
		out: makeShort
	});

	
	/*
	$(".imagem").mouseenter(function(){
		if($(".imagem.active").attr('id') != $(this).attr('id')){
			$(".imagem.active").animate({'width':'154px'}, 300, function(){
				$(this).children('.big2').hide();
				$(this).children('.big').hide();
			}).addClass('small').removeClass('active');
			$(this).animate({'width':'588px'}, 300).removeClass('small').addClass('active');
			
			//animação com o bg imagem1
			$(this).children('.big').show();
			$(this).children('.big2').hide();
			
			setTimeout(function(){
				if($(".imagem.active .big2").length > 0){
					$(".imagem.active .big").hide();
					$(".imagem.active .big2").show();
				}
			},5000);
		}
	}, function(){
		
	});	
	*/
	
	
	setInterval(function(){
		if($(".imagem.active").next().length)
			$(".imagem.active").next().click();
		else {
			$(".imagem").eq(0).click();
		}
	},10000);
	
	
	
	/* Formulário de Busca */
	
	$('#search').bind( "mouseenter", function(){	
		if( $(this).val() == 'Buscar' ){
			$(this).val('');
		}	
	});
	
	$('#search').bind( "mouseleave", function(){
		if( $(this).val() == '' ){
			$(this).val('Buscar');
		}	
	});
	
	$(".busca form").submit(function(){
		if( $("#search").val() != 'Buscar' )
			location.href = $(this).attr('action') + '/busca:' + $("#search").val();
		else
			location.href = $(this).attr('action');
			
		return false;
	});	
	
	
	/* Fim da Busca */
	
	/* Form de Demonstracao */
	
	$('#form-demonstracao').hide();

	$("#img-demonstracao").toggle(
	  function () {
		$(this).attr('src' , www_root + 'img/contato_menos.png' );
	    $('#form-demonstracao').show();
	  },
	  function () {
		  $(this).attr('src' , www_root + 'img/contato.png' );
		  $('#form-demonstracao').hide();
	  }
	);	
	
	
	/* Mais notícias */
	$('#news-mais').hide();
	$("#img-news").toggle(
	  function () {
		if( $(this).attr('src') == www_root + 'img/news_mais.bmp' ){
			 $(this).attr('src' , www_root + 'img/news_menos.bmp' );
		}
	    $('#news-mais').show();
	  },
	  function () {
		  if( $(this).attr('src') == www_root + 'img/news_menos.bmp' ){
				 $(this).attr('src' , www_root + 'img/news_mais.bmp' );
			}
		  $('#news-mais').hide();
	  }
	);	
	
	
	
	//máscara de cadastro
	$("input.cpf").setMask('cpf');
	$("input.cep").setMask('cep');
	$("input.telefone").setMask('phone');
	$("input.cnpj").setMask('cnpj');
	$("input.time").setMask('time');
	$("input.date").setMask('date');
	$("input.decimal").setMask('decimal');
	$("input.ddd").setMask('ddd');
	$("input.phone").setMask('phone2');
	
	$('input[type=submit]').css( 'cursor' , 'pointer' );
	$('input[type=submit]').css( '-moz-border-radius' , '5px 5px 5px 5px' );
	$('input[type=text], input[type=file], textarea').css( 'color' , '#FFF' );
	//$('textarea').css( 'color' , '#FFF' );
	
	/* Cadastro de Newsletters */
	$('#form-newsletter').submit(function(){
		$.post( www_root+'newsletters/add', $("#form-newsletter").serialize()  , function(data) {
			$('.result').html(data);
			if( data == 'Seu e-mail foi cadastrado com sucesso! Obrigado.' ){
				$('#form-newsletter input[type=text]').val('');
			}
		});	
		return false;	
	});
	
	
	/* Arredondar os cantos das imagens */
	
	$.fn.corner.defaults.useNative = false;
	
	$('.imgBox').css({ 'margin-right':'5px', 'height':'auto', 'width':'80px', 'float':'left', 'padding':'0' });
	
	$('.imgBox').corner();
	
	$.fn.corner.defaults.useNative = false;
			
	$("#imgBox2").corner("10px");

	$('.chamada .imagem:eq(0) .bgazul').css('top', '0px');
	$('.chamada .imagem:eq(0) .texto').css('top', '56px');
	$('.chamada .imagem:eq(0)').corner('left');
	
	$('.chamada .imagem:eq(2) .bgazul').css('top', '0px');
	$('.chamada .imagem:eq(2) .texto').css('top', '56px');
	$('.chamada .imagem:eq(2)').corner('right');
	
	$('#pagina-esq .imagem').corner();
	
	/*CLASS CORNER*/
	$(".corner").each(function(i,el){
		width = $(el).width();
		height = $(el).height();
		margin = $(el).css('margin-top')+' '+$(el).css('margin-right')+' '+$(el).css('margin-bottom')+' '+$(el).css('margin-left');
		float = $(el).css('float');
		
		container = $('<div></div>').insertBefore(el);
		
		element = $(el).css('margin',0).remove();
		
		$(container).css('width',width).css('height',height).css('margin',margin).css('float',float).html($(element)).corner();
	});
	
	
	/* Fim */
	
	//Fix Bg
	if($("#pagina-dir").position() != null) {
		$("#conteudo-bg").css('width', ($("#pagina-dir").position().left-15)+'px');
	}
	if($("#conteudo").height() > $("#conteudo-bg").height()) {
		$("#conteudo-bg").css('height', $("#conteudo").height()+'px');
	}

	/*Esmaecer alertas*/
	setTimeout(function(){
		$("#flashMessage").hide();
	},50000);
	
	
	
});

function makeTall(){ 
	if($(".imagem.active").attr('id') != $(this).attr('id')){
		$(".imagem.active").animate({'width':'154px'}, 300, function(){
			$(this).children('.big2').hide();
			$(this).children('.big').hide();
		}).addClass('small').removeClass('active');
		$(this).animate({'width':'588px'}, 300).removeClass('small').addClass('active');
		
		//animação com o bg imagem1
		$(this).children('.big').show();
		$(this).children('.big2').hide();
		
		setTimeout(function(){
			if($(".imagem.active .big2").length > 0){
				$(".imagem.active .big").hide();
				$(".imagem.active .big2").show();
			}
		},5000);
	}
}
function makeShort(){ }



