$(document).ready(function(){
     
     $('.inativo').attr('href','javascript:void(0);');
	 $('#txtFone').mask("(99) 9999-9999");
     
	 /* ajustes */
	 equalHeight($(".coluna"));
	 jQuery(window).load(function(){
		  equalHeight($(".coluna"));
	   });
	 
	 $("a[href^='http']").attr('target','_blank');
	 $('.portfolio:nth-child(3n+3)').css({marginRight:'0px'});
	 $(".arquivos-dias> li:last-child").css('border-bottom','none');
	 $('#formContato, #formComentario').validate();
	 $('#formCliente').validate();
	
	//focus no form
	$('.campo').focus(function(){
		$(this).prev().css('color','#000');
	});
	$('.campo').blur(function(){
		$(this).prev().css('color','#777');
	});
	 
	 /* efeito menu */
	 $('#mainnav ul').lavaLamp();
	 
	  /* post arquivados ano*/
	 $(".post-arquivos > li > a").live('click',function(){
		  
		  if($(this).next().is(':hidden')){
			 $(".post-arquivos > li > a").removeClass('ativo').next().slideUp();
			 $(this).toggleClass('ativo').next().slideDown();
			 return false;
		  }else{
			  if($(this).hasClass('ativo')){
				  $(".post-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;
		});
		
		

	//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;
	 });
	 
	 /* links de ancora */
	 $('.reply').live('click',function(){
		 var id = $(this).attr('href');
		 $('html,body').animate({scrollTop:$(id).offset().top},1000);
		 return false;
	 });



 
 /* função para deixar elementos com o mesmo tamanho
	equalHeight(classeHtml) */
 function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
 }



/* abre google maps no lightbox*/
function initialize(){
  var latlng = new google.maps.LatLng(-8.031039,-34.914471);
  var myOptions = {zoom: 16,
                   center: latlng,
				   mapTypeId: google.maps.MapTypeId.ROADMAP
				   };
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  var marker = new google.maps.Marker({position: latlng,map: map,title:"Plano4"});   
}

$('.abreMapa').prettyPhoto({
		custom_markup: '<div id="map_canvas" style="width:900px; height:400px"></div>',	
		changepicturecallback: function(){
		                        initialize();
								}
		});	
		
		
		//focus no form
	$('.campo').focus(function(){
		$(this).prev().css('color','#7aba00');
	});
	$('.campo').blur(function(){
		$(this).prev().css('color','#767676');
	});
	
	// -------------------------------------------------------------------------------------------
// 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);

$('.content').kriesi_image_preloader({delay:200});
	
	
	
	
	
	
//fim document					   
});


