$(document).ready(function() {
	
	
	/* valida o formulário de contato */
	$('#formContato').validate();
	$('#txtFone').mask("(99) 9999-9999");
	//focus no form
	$('.campo').focus(function(){
		$(this).prev().css('color','#df24a4');
	});
	$('.campo').blur(function(){
		$(this).prev().css('color','#b7067f');
	});
	
	
	// gabiarra
	var w = $('.response-inner > header h3').width() - 30 ;
	$('.response-inner > header').css('background-position',w +'px 3px');
	
	/* anima quando clica */

	 $('.coments a, .reply').live('click',function(){

		 var id = $(this).attr('href');
         var option = $(this).attr('id').split("--");
         var idPost = option[1];
         $('#idComAnt').val(idPost);
         
		 $('html,body').animate({scrollTop:$(id).offset().top},1500);

		 return false;

	 });
	 
	//box de mensagens
	$('.message').append('<em class="closeable" title="clique para fechar"></em>');
	$('.closeable').live("click",function(){
		$(this).parent().fadeOut("slow",function(){
			//$('.closeable').parent().remove();
		});
		return false;
	 });
	
	
	
	/* acordeon */
	$("#acordeon > li > a").click(function(e) {
		var $el = $(this) ;
		if($(this).next().is(':hidden')){
			$("#acordeon li a").removeClass('ativo').next().slideUp();
			$el.removeClass('ativo').next().slideUp();
		 	$(this).toggleClass('ativo').next().slideDown();
			return false;
		}else{
			//if(!$(this).hasClass('ativo')){
				$("#acordeon li a").removeClass('ativo').next().slideUp();
				return false;
			//}
		}
        return false;
    });
	
	/* mapa */
	$('.tabs li a:first').addClass('ativo');
	$('.mapas:first').show();
	$('.tabs li a').click(function(e) {
		e.preventDefault();
		$('.tabs li a').removeClass('ativo');
		$(this).addClass('ativo');
		var $id = $(this).attr('href');
		$('.mapas').hide();
		$($id).show();
		return false;
    });
	
	
	
	 /* post arquivados ano*/
	 $(".list-arquivos  > li > a").live('click',function(){
		  if($(this).next().is(':hidden')){
			 $(".list-arquivos  > li > a").removeClass('ativo').next().slideUp();
			 $(this).toggleClass('ativo').next().slideDown();
			 return false;
		  }else{
			  if($(this).hasClass('ativo')){
				  $(".list-arquivos  > li > a").removeClass('ativo').next().slideUp();
				  return false;
				  }
		  }
			return false;
		});
		
		 /* post arquivados mês*/
		$(".arquivos-mes > li > a").live('click',function(){
		  
		  if($(this).next().is(':hidden')){
			 $(".arquivos-mes > li > a").removeClass('ativo').next().slideUp();
			 $(this).toggleClass('ativo').next().slideDown();
			 return false;
		  }else{
			  if($(this).hasClass('ativo')){
				  $(".arquivos-mes > li > a").removeClass('ativo').next().slideUp();
				  return false;
				  }
		  }
		 
			return false;
		});
		

	 
 // ajustes HTML no maldito IE
 $('.coluna .item:last-child').addClass('fix');
 $('.clipping div:last-child, .anexo-content > a:nth-child(6n+6), .videos > span:nth-child(2n+2)').css('margin-right',0);
 $("a[href^='http']").attr('target','_blank');
 $('.arquivos-dias > li:last-child').css('margin-bottom',0);
 $('.lstFix > li:last-child, article.post-entry:last-child').css('border-bottom','none');
// $(".arquivos-mes > li:odd").addClass('par');
 
 
 
 //fancybox
 $("a[rel^='fancybox']").fancybox({
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			
	
	
	jQuery('.videos img').load(function(){
			$('.videos a').animate({"opacity": "1"}, "slow");
		 });	

 jQuery(window).load(function(){
	 equalHeight($(".box-one"));
	  equalHeight($(".coluna"));
	 if(!$.browser.msie){
		 $('#main').kriesi_image_preloader({delay:200});
		 }
	 
	 $("#openVideo, .iframe").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});
			
			$('#st-accordion li').hide();
			$('#st-accordion li').slice(0, 10).show();
			$('#todosprojetos').click(function(e){
				$('#st-accordion li:hidden').toggle('slow');
				$(this).hide();
				return false;
			});
			
	 
 });

 //efeito menu
 $('#menu a')
  .hover(function() {
	
		 $(this).addClass('ativo');
	 	 $(this).parent().addClass('hover');
    	 $(this).animate({ top: '20px' }, 'fast');

	
  }, function() {
		  $(this).removeClass('ativo');
		  $(this).parent().removeClass('hover');
		  $(this).animate({ top: 0 }, 'fast');
	 
  });
  
 
  //Colunas do mesmo tamanho
	  function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	  }
	  
	  $(".imgHover, .imgHoveren").hover(function(){
			if ( !$.browser.msie ) {
				$(this).stop().animate({"opacity": "1"}, "slow");
			}
			},function() {
				if ( !$.browser.msie ) {
				$(this).stop().animate({"opacity": "0"}, "slow");
				}
			});
  

	// -------------------------------------------------------------------------------------------
// The Image preloader
// -------------------------------------------------------------------------------------------


(function($)
{
	$.fn.kriesi_image_preloader = function(options) 
	{
		var defaults = 
		{
			repeatedCheck: 500,
			fadeInSpeed: 1000,
			delay:600,
			callback: ''
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var imageContainer = jQuery(this),
				images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
				imagesToLoad = images.length;				
				
				imageContainer.operations =
				{	
					preload: function()
					{	
						var stopPreloading = true;
						
						images.each(function(i, event)
						{	
							var image = $(this);
							
							
							if(event.complete == true)
							{	
								imageContainer.operations.showImage(image);
							}
							else
							{
								image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
							}
							
						});
						
						return this;
					},
					
					showImage: function(image)
					{	
						imagesToLoad --;
						if(image.data.currentImage != undefined) { image = image.data.currentImage;}
												
						if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
												 
						if(imagesToLoad == 0)
						{
							if(options.delay > 0)
							{
								images.each(function(i, event)
								{	
									var image = $(this);
									setTimeout(function()
									{	
										image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
									},
									options.delay*(i+1));
								});
								
								if(options.callback != '')
								{
									setTimeout(options.callback, options.delay*images.length);
								}
							}
							else if(options.callback != '')
							{
								(options.callback)();
							}
							
						}
						
					}

				};
				
				imageContainer.operations.preload();
		});
		
	}
})(jQuery);






});
/* 
	Author: José Willams <contato@josewillams.com>
	Novembro de 2011
*/






