$(document).ready(function() {

	$('.block, .minipost_content').hide();
	$('.blockers').append('<p class="cargando">carregando....</p>')
	setTimeout( 'perepe()', 1500);
	$("input").focus(function() {
					if( this.value == this.defaultValue ) {
						this.value = "";
					}
				}).blur(function() {
					if( !this.value.length ) {
						this.value = this.defaultValue;
					}

				});

	
	
});
// cargan cuadros!
function perepe(){
	$('.blockers .cargando').fadeOut("fast", function(){
		$(this).remove();
		$('.left1').fadeIn("fast", function(){
			$('.left2').fadeIn("fast", function(){
					$('.mid1').fadeIn("fast", function(){
						$('.mid2').fadeIn("fast", function(){
							$('.right2').fadeIn("fast", function(){
								$('.right1').fadeIn("fast", function(){
									$('.right3').fadeIn("fast", function(){
										$('.right4').fadeIn("fast", function(){
											$('.right6').fadeIn("fast", function(){
												$('.right5').fadeIn("fast", function(){							

															cargarContenidos();

												});
											});
										});
									});
								});
							});
						});
					});

			});	
		});
	})

}
function cargarContenidos(){
var aCtivo = "";
movimientos(aCtivo);
if(!$.browser.msie){

$('.left1 .inner, .left2 .inner, .mid1 .inner, .mid2 .inner, #logo, .right1 .tit, .right3 .tit,.right4 .tit, .right5 .tit, .newsletter').animate({
	opacity: "1"
}, 800);
}
 	$('#content2 .post').each(function(){
		var titulo = $(this).find('.wp-post-image').attr('title');
		$(this).find('.imgtit').append(titulo);
	});
	$('.left1 .inner').each(function(){
	
		var postID = $(this).children('.post').attr('id');
		postID = postID.replace('post-', '')
		var esto = $(this).children('.post').children('.minipost_content');
		var estomas = $(this).children('.post').children('.vermas');
		$(this).click(function(){
			var url = estomas.attr('href');
			window.open = url;
		});
		$(this).hover(function(){
			
			$.ajax({
				url: location.href,
				type: "GET",
				data: 'p='+postID+'&ext=1',
				success: function(html){
					esto.append(html);
					esto.slideDown("fast", function(){
					esto.css({ color: "rgb(255, 255, 255)"});	
					});
					estomas.hide();
				}
			});
		}, function(){
			esto.slideUp("fast", function(){
				esto.empty();
				estomas.show();
				esto.css({ color: "rgb(64, 64, 64)"});
			});
			
			
		});
	});


}
function movimientos(aCtivo){
	
	// click PORTFOLIO
	$('.right1, #btn1').click(function() {
		aCtivo = $('.mid2').attr('id');
				 aPortfolio(aCtivo);
	});
	
	// click AGENCIA
	$('.right3, #btn3').click(function() {
		aCtivo = $('.mid2').attr('id');
				aAgencia(aCtivo);
	});
	
	// click CONTACTO
	$('.right5, #btn5').click(function(){
		aCtivo = $('.mid2').attr('id');
				aContacto(aCtivo);
	});
	$('.right4').each(function(){
		var valH;
		var valW;
		var posL;
		var posT;
		$(this).hover(function(){
			if(!$(this).hasClass('act')){
				valH = $(this).height();
				valW = $(this).width();
				posL = $(this).position().left;
				posT = $(this).position().top;

				$(this).animate({
			
					width: valW+4+"px",
					height: valH+4+"px",
					left: posL-2+"px",
					top: posT-2+"px"
			
				}, 	function(){

					$(this).animate({
						left: posL+"px",
						top: posT+"px",
						width: valW+"px",
						height: valH+"px"
						}, 100);
					});
			}
	});	

	});
	$('.newsletter .inputSubmit').attr('action', 'javascript:void(0)');
	
	$('.newsletter .inputSubmit').click(function(){
	
		var mailform = $('#mailform').val();
		var data = "page_id=12&submit=2&mailform="+mailform;
		if (mailform == ""){
			$('#mailform').val("Por favor preencha com um endereço de e-mail válido.");
		} else{
		$.ajax({
			data: data,
			type: "GET",
			url: location.href,
			success: function(html){
				$('#mailform').val(html);
			}
		});
		}
	});
	
}
function aPortfolio(aCtivo){
	if(aCtivo === "agencia"){
			if(!$.browser.msie){ $('.right3 .tit, .right5 .tit').animate({opacity: "0"}, 200).show(); 
			$('.right1 .tit').animate({opacity: "0"}, 200, function(){$(this).hide()}); //desaparece titulo
			
			}else{
				$('.right3 .tit, .right5 .tit').hide();
				$('.right1 .tit').hide(); //desaparece titulo
				
			}//desaparece titulo
			
			$('.right3 .inner').animate({
				opacity: "0"
			}, 200, function(){
				$(this).remove();
			});
			$('.right2').animate({ 
				    width: "270px"
				  }, 800);
				
			$('.right3').animate({ 
					    width: "130px",
						left: "810px",
						top: "200px",
						height: "145px",
						backgroundPosition: "-810px -200px"
					  }, 800	, function(){
						$('.right1').animate({
							height: "170px"
						}, 200);
						$('.right3').removeClass('act');
						 //comienza formación
						$('.right1').addClass('act');
						$('.right1 .tit').animate({opacity: "0"}, 200); //desaparece titulo
						$('.right5 .tit').animate({backgroundPosition: "25px 20px"}, 350);
						$('.right5').animate({ 
						    width: "160px"
						  }, 600, function(){
							$('.right3').animate({ 
							   height: "65px",
								top: "375px"
							  }, 700);
							$('.right2').animate({ 
								width: "0"
							  }, 700, function(){
								$('.right1').animate({ 
									height: "345px"}, 700,
									function(){
										aCtivo = 'portfolio';
										$('.mid2').attr('id', aCtivo);
											$.ajax({ url: location.href,
												data: "cat=3", 
												type: "GET",
												success: function(html){
											        $('.right1').append(html).addClass('act');
													if(!$.browser.msie){$('.right3 .tit, .right5 .tit').animate({opacity: "1"}, 200); }else{ $('.right3 .tit, .right5 .tit').show();} //aparece titulo
													$('.right1 .inner').animate({
														opacity: "1"
													},600, function(){
														$('#ulportfolio').jScrollPane();
														
														openPortfolio();
													});
											      }
											});										
									});
							});
						});
						
						//termina formacion
					});


		}else if(aCtivo === "contacto"){
		if(!$.browser.msie){		$('.right3 .tit, .right5 .tit').animate({opacity: "0"}, 200).show();
		$('.right1 .tit').animate({opacity: "0"}, 200, function(){$(this).hide();}); //desaparece titulo
		 }else{
				$('.right3 .tit, .right5 .tit').hide();
				$('.right1 .tit').hide(); //desaparece titulo
				
		}
			
			$('.right5 .inner').animate({
				opacity: "0"
			}, 200, function(){
				$(this).remove();
			});
			$('.right5').animate({ 
					backgroundPosition: "-610px -370px",
					 height: "65px",
					top: "375px"
				}, 500, function(){
					$('.right2').animate({ 
						    width: "270px"
						  }, 400);
					$('.right3').animate({ 
							backgroundPosition: "-810px -200px",
						    top: "200px",
							height: "145px"
						  }, 800, function(){
							$('.right1').animate({
								width: "410px"
							}, 300	, function(){
								$('.right5 .tit').animate({backgroundPosition: "25px 20px"}, 300);
								$('.right5').removeClass('act');
								 //comienza formación
								$('.right1').addClass('act');
								$('.right1 .tit').animate({opacity: "0"}, 200); //desaparece titulo
								$('.right5').animate({ 
								    width: "160px"
								  }, 600, function(){
									$('.right3').animate({ 
									   height: "65px",
										top: "375px"
									  }, 700);
									$('.right2').animate({ 
										width: "0"
									  }, 700, function(){
										$('.right1').animate({ 
											height: "345px"}, 700,
											function(){
												aCtivo = 'portfolio';
												$('.mid2').attr('id', aCtivo);
													$.ajax({ url: location.href,
														data: "cat=3", 
														type: "GET",
														success: function(html){
													        $('.right1').append(html).addClass('act');
															if(!$.browser.msie){	$('.right3 .tit, .right5 .tit').animate({opacity: "1"}, 200); }else{$('.right3 .tit, .right5 .tit').show();} //aparece titulo
															$('.right1 .inner').animate({
																opacity: "1"
															},600	, function(){
																$('#ulportfolio').jScrollPane();
																
																	openPortfolio();
																});
													      }
													});												
											});
									});
								});
								
								//termina formacion
							});
						});
				});


		}else if(aCtivo === "portfolio"){
				
							
						
	} else{	
			if(!$.browser.msie){ $('.right1 .tit, .right3 .tit, .right5 .tit').animate({opacity: "0"}, 200);
			$('.right1 .tit').animate({opacity: "0"}, 200, function(){$(this).hide();}); //desaparece titulo
			} else{
			$('.right1 .tit, .right3 .tit, .right5 .tit').hide();	
			$('.right1 .tit').hide(); //desaparece titulo
			
			}
			$('.right1').addClass('act');
			 //comienza formación
			$('.right5 .tit').animate({backgroundPosition: "25px 20px"}, 350);
			$('#logo').animate({
				opacity: "0"
			}, 400);
			$('.right5').animate({ 
			    width: "160px"
			  }, 500, function(){
				$('.right3').animate({ 
				   height: "65px",
					top: "375px"
				  }, 700);
				$('.right2').animate({ 
					width: "0"
				  }, 700, function(){
					$('.right1').animate({ 
						height: "345px"}, 700,
						 function(){
								aCtivo = 'portfolio';
								$('.mid2').attr('id', aCtivo);
								$.ajax({ url: location.href,
									data: "cat=3", 
									type: "GET",
									success: function(html){
								        $('.right1').append(html).addClass('act');
									if(!$.browser.msie){ $('.right3 .tit, .right5 .tit').animate({opacity: "1"}, 200); }else{	$('.right3 .tit, .right5 .tit').show();
											
									}//aparece titulo
										$('#ulportfolio').jScrollPane();
										$('.right1 .inner').animate({
											opacity: "1"
										},600	, function(){
												openPortfolio();
											});
								      }
								});
						});
				});
			});
			
			//termina formacion
	}
	//
}
function openPortfolio(){
	$('.right1 .inner li a').each(function(){
		var url = location.href;
		var postID = $(this).parent('li').attr('ID');
		url = url+"?p="+postID+"&ext=2";
		$(this).attr('href','javascript:void(0);')
		$(this).click(function(){
			
			$.fn.colorbox({href: url, width: '530', height: '600'}, function(){
				$('#galeria').addClass('infiniteCarousel');
				carousel();
			});
		});
	});
}
function carousel(){
	$('.gallery-item a').attr('href', 'javascript:void(0);')
	var largo = $('.infiniteCarousel').find('dl').length;
	largo *= 450;
	$('.infiniteCarousel').children('.gallery').css({width: largo});
	if(!foto){var foto = 0}
BuscarTemp();
//	var intervalo = setInterval('BuscarTemp();', 5000);	
}
function BuscarTemp(){
	var largo = $('.infiniteCarousel').find('dl').length;
	largo = largo-1;
	var foto = $('.infiniteCarousel').attr('foto');
	$('.fotomas').click(function(){
	foto++;	
	if(foto == largo){
		foto = 0;
		$('.infiniteCarousel').children('.gallery').animate({left: "0"}, 1000);
		$('.infiniteCarousel').attr('foto', foto);
	} else{
		pos = "-"+foto*450;
		$('.infiniteCarousel').children('.gallery').animate({left: pos}, 1000);
		$('.infiniteCarousel').attr('foto', foto);
		
	}
	});
	$('.fotomenos').click(function(){
	foto--;	
	if(foto == 0){
		foto = largo;
		$('.infiniteCarousel').children('.gallery').animate({left: "0"}, 1000);
		$('.infiniteCarousel').attr('foto', foto);
	} else{
		pos = "-"+foto*450;
		$('.infiniteCarousel').children('.gallery').animate({left: pos}, 1000);
		$('.infiniteCarousel').attr('foto', foto);
		
	}
	});
}
function aAgencia(aCtivo){
	if(aCtivo === "agencia"){
		}else if(aCtivo === "contacto"){
			if(!$.browser.msie){
				$('.right3 .tit, .right5 .tit, .right1 .tit').animate({opacity: "0"}, 200).show();
			}else{
				$('.right3 .tit, .right5 .tit, .right1 .tit').hide();
					
			}
			
			$('.right5 .inner').animate({
				opacity: "0"
			}, 200, function(){
				$(this).remove();
			});
			$('.right5').animate({ 
					 height: "65px",
					top: "375px"
				}, 400, function(){
						$('.right5').animate({ 
								backgroundPosition: "-610px -370px"}, 400);
					$('.right2').animate({ 
						    width: "270px"
						  }, 300);
					$('.right3').animate({ 
							backgroundPosition: "-810px -200px",
						    top: "200px",
							height: "145px"
						  }, 800, function(){
							$('.right1').animate({
								width: "410px"
							}, 300	, function(){
								$('.right5').removeClass('act');
								//comienza formacion
								$('.right3').addClass('act');
								if(!$.browser.msie){
									$('.right3 .tit').animate({opacity: "0"}, 200, function(){$(this).hide();}); //desaparece titulo
								}else{
									$('.right3 .tit').hide(); //desaparece titulo
									
								}
								$('.right2').animate({ 
								    width: "0"
								  }, 800);
									$('.right1').animate({ 
									    height: "140px"
									  }, 400);
								$('.right3').animate({ 
									    width: "410px",
										height: "175px",
										left: "530px",
										top: "170px",
										backgroundPosition: "-530px -170px"
								  }, 900, function(){
									aCtivo = 'agencia';
									$('.mid2').attr('id', aCtivo);
										$.ajax({ url: location.href,
											data: "page_id=8", 
											type: "GET",

											success: function(html){
										        $('.right3').append(html);
												if(!$.browser.msie){	
													$('.right5 .tit, .right1 .tit').animate({opacity: "1"}, 200);
												}else{
														$('.right5 .tit, .right1 .tit').show();
												}
												$('.right3 .inner').animate({
													opacity: "1"
												}, 400);
										      }
										});
								});
								//termina formacion
							});
						});
				});


		}else if(aCtivo === "portfolio"){
		if(!$.browser.msie){	$('.right3 .tit, .right5 .tit, .right1 .tit').animate({opacity: "0"}, 200).show();
		}else{
			$('.right3 .tit, .right5 .tit, .right1 .tit').hide();
		}
				$('.right1 .inner').animate({
					opacity: "0"
				}, 200, function(){
					$(this).remove();
					
				});
			$('.right1').animate({ 
				height: "170px"}, 600, function(){
						$('.right2').animate({ 
							width: "270px"
						  },1000);
						$('.right3').animate({ 
							top: "200px"
						  },500, function(){
							$('.right3').animate({ 
								height: "145px"
							  },500);
								$('.right5 .tit').animate({backgroundPosition: "180px 30px"}, 500);
								$('.right5').animate({ 
							    width: "320px"
							  	}, 300, function(){
								$('.right1').removeClass('act');
								//comienza formacion
								$('.right3').addClass('act');
								if(!$.browser.msie){
									$('.right3 .tit').animate({opacity: "0"}, 200, function(){$(this).hide();}); //desaparece titulo
								}else{
									$('.right3 .tit').hide(); //desaparece titulo
									
								}
								$('.right2').animate({ 
								    width: "0"
								  }, 800);
									$('.right1').animate({ 
									    height: "140px"
									  }, 400);
								$('.right3').animate({ 
										height: "175px",
									    width: "410px",
										left: "530px",
										top: "170px",
										backgroundPosition: "-530px -170px"
								  }, 900, function(){
									aCtivo = 'agencia';
									$('.mid2').attr('id', aCtivo);
										$.ajax({ url: location.href,
											data: "page_id=8", 
											type: "GET",

											success: function(html){
										        $('.right3').append(html);
												if(!$.browser.msie){$('.right5 .tit, .right1 .tit').animate({opacity: "1"}, 200);
												}else{
													$('.right5 .tit, .right1 .tit').show();
												}
												$('.right3 .inner').animate({
													opacity: "1"
												}, 400);
										      }
										});
								});
								//termina formacion
							});
						});
				});
	} else{
	if(!$.browser.msie){	$('.right3 .tit, .right5 .tit, .right1 .tit').animate({opacity: "0"}, 200);
		$('.right3 .tit').animate({opacity: "0"}, 200, function(){$(this).hide();}); //desaparece titulo
		 }else{
				$('.right3 .tit').hide(); //desaparece titulo
			$('.right3 .tit, .right5 .tit, .right1 .tit').hide(); 
	}
		
		$('.right3').addClass('act');
		//comienza formacion
	
		$('#logo').animate({
			opacity: "0"
		}, 500);
		$('.right2').animate({ 
		    width: "0"
		  }, 800);
				$('.right1').animate({ 
				    height: "140px"
				  }, 400);
		$('.right3').animate({ 
				height: "175px",
			    width: "410px",
				left: "530px",
				top: "170px",
				backgroundPosition: "-530px -200px"
		  }, 900, function(){
			aCtivo = 'agencia';
			$('.mid2').attr('id', aCtivo);
			$.ajax({ url: location.href,
				data: "page_id=8", 
				type: "GET",
				
				success: function(html){
			        $('.right3').append(html);
					if(!$.browser.msie){		$('.right5 .tit, .right1 .tit').animate({opacity: "1"}, 200); }else{
						$('.right5 .tit, .right1 .tit').show();
					}
					$('.right3 .inner').animate({
						opacity: "1"
					}, 400);
			      }
			});
		});
		//termina formacion
		
	}
}

function aContacto(aCtivo){
	if(aCtivo === "agencia"){
			if(!$.browser.msie){
				$('.right5 .tit, .right3 .tit, .right1 .tit').animate({opacity: "0"}, 200).show();
			}else{
				$('.right5 .tit, .right3 .tit, .right1 .tit').hide();
				
			}
		$('.right3 .inner').animate({
			opacity: "0"
		},200, function(){
			$(this).remove();
		});
		
			$('.right2').animate({ 
				    width: "270px"
				  }, 800);
				
			$('.right3').animate({ 
						top: "200px",
						height: "145px",
					    width: "130px",
						left: "810px",
						backgroundPosition: "-810px -200px"
					  }, 800	, function(){
						$('.right1').animate({
							height: "170px"
						}, 200);
						$('.right1').removeClass('act');
						
						//comienza formacion
						$('.right5').addClass('act');
						if(!$.browser.msie){
						$('.right5 .tit').animate({opacity: "0"}, 200, function(){$(this).hide();}); //desaparece titulo
						}else{
							$('.right5 .tit').hide(); //desaparece titulo
							
						}
						$('.right1').animate({
							width: "250px"
						}, 400, function(){
							$('.right3').animate({ 
									backgroundPosition: "-810px -0px",
								    top: "0",
									height: "170px"
								  }, 800);
							$('.right2').animate({ 
								    width: "80px"
								  }, 800, function(){
									$('.right5').animate({ 
											backgroundPosition: "-620px -200px",
											 height: "240px",
											top: "200px"
										}, 400, function(){

								aCtivo = "contacto";
								$('.mid2').attr('id', aCtivo);
								$.ajax({ url: location.href,
									data: "page_id=12", 
									type: "GET",

									success: function(html){
								        $('.right5').append(html);
										if(!$.browser.msie){$('.right3 .tit, .right1 .tit').animate({opacity: "1"}, 200);
										}else{
											$('.right3 .tit, .right1 .tit').show();
										}
										$('.right5 .inner').animate({
											opacity: "1"
										}, 400, function(){
												openContacto();
											});
								      }
								});
										});
								});

						});
						//termina formacion
					});


		}else if(aCtivo === "contacto"){
	
						
		}else if(aCtivo === "portfolio"){
			if(!$.browser.msie){$('.right5 .tit, .right3 .tit, .right1 .tit').animate({opacity: "0"}, 200).show();
		}else{
			$('.right5 .tit, .right3 .tit, .right1 .tit').hide();
		}
				$('.right1 .inner').animate({
					opacity: "0.1"
				}, 200	, function(){
						$(this).remove();

					});
			$('.right1').animate({ 
				height: "170px"}, 600, function(){
						$('.right2').animate({ 
							width: "270px"
						  },1000);
						$('.right3').animate({ 
							top: "200px"
						  },500, function(){
							$('.right3').animate({ 
								height: "145px"
							  },500);
								$('.right5').animate({ 
							    width: "320px"
							  	}, 300, function(){
								$('.right1').removeClass('act');
								
								//comienza formacion
								$('.right5').addClass('act');
								if(!$.browser.msie){$('.right5 .tit').animate({opacity: "0"}, 200, function(){$(this).hide();}); //desaparece titulo
								}else{
									$('.right5 .tit').hide();
								}
								$('.right1').animate({
									width: "250px"
								}, 400, function(){
									$('.right3').animate({ 
											backgroundPosition: "-810px -0px",
										    top: "0",
											height: "170px"
										  }, 800);
									$('.right2').animate({ 
										    width: "80px"
										  }, 800, function(){
											$('.right5').animate({ 
													backgroundPosition: "-620px -200px",
													 height: "240px",
													top: "200px"
												}, 400, function(){

										aCtivo = "contacto";
										$('.mid2').attr('id', aCtivo);
										$.ajax({ url: location.href,
											data: "page_id=12", 
											type: "GET",

											success: function(html){
										        $('.right5').append(html);
												if(!$.browser.msie){
												$('.right3 .tit, .right1 .tit').animate({opacity: "1"}, 200);
												}else{
												$('.right3 .tit, .right1 .tit').show();	
												}
												$('.right5 .inner').animate({
													opacity: "1"
												}, 400	, function(){
														openContacto();
													});
										      }
										});
												});
										});

								});
								//termina formacion
							});
						});
				});
	}	else{
								//comienza formacion
								if(!$.browser.msie){	$('.right5 .tit, .right3 .tit, .right1 .tit').animate({opacity: "0"}, 200);
								$('.right5 .tit').animate({opacity: "0"}, 200, function(){$(this).hide();}); //desaparece titulo
								 }else{
									$('.right5 .tit').hide(); //desaparece titulo
									$('.right5 .tit, .right3 .tit, .right1 .tit').hide();
								}
								$('.right5').addClass('act');
								$('#logo').animate({
									opacity: "0"
								}, 400);
								$('.right1').animate({
									width: "250px"
								}, 400, function(){
									$('.right3').animate({ 
											backgroundPosition: "-810px -0px",
										    top: "0",
											height: "170px"
										  }, 800);
									$('.right2').animate({ 
										    width: "80px"
										  }, 800, function(){
											$('.right5').animate({ 
													backgroundPosition: "-620px -200px",
													 height: "240px",
													top: "200px"
												}, 400, function(){

										aCtivo = "contacto";
										$('.mid2').attr('id', aCtivo);
											$.ajax({ url: location.href,
												data: "page_id=12", 
												type: "GET",

												success: function(html){
											        $('.right5').append(html);
													if(!$.browser.msie){	$('.right3 .tit, .right1 .tit').animate({opacity: "1"}, 200);
													}else{ $('.right3 .tit, .right1 .tit').show(); }
											
													$('.right5 .inner').animate({
														opacity: "1"
													}, 400, function(){
														openContacto();
													});
											      }
											});
												});
										});

								});
								//termina formacion
	}
}
function openContacto(){
	$('#contato_submit').attr('action', 'javascript:void(0);');
	
	
	$('#contato_submit .submit').click(function(){
		var nome = $('#nome').val();
		var email = $('#email').val();
		var cidade = $('#cidade').val();
		var endereco = $('#endereco').val();
		var bairro = $('#bairro').val();
		var mensagem = $('#mensagem').val();
		var data = "page_id=12&submit=1&nome="+nome+"&email="+email+"&cidade="+cidade+"&endereco="+endereco+"&bairro="+bairro;
		if (nome == ""){
			$('.right5 .post_content').empty().append("Por favor preencha com um nome.");
		} else if (email == ""){
			$('.right5 .post_content').empty().append("Por favor preencha com um endereço de e-mail válido.");
		} else{
		$.ajax({
			data: data,
			type: "GET",
			url: location.href,
			success: function(html){
				$('.right5 .post_content').empty().append(html);
			}
		});
		}
	});
}

