$(document).ready(function(){
	
	$('a.ajax').attr('href','#');
	
	animacion_menu = function(valor){
		$('.marco').animate({ top : valor }, 1000);
	}
	
	animacion_contenido = function(valor){
		$('.derecho').animate({ top : valor }, 1000);
	}
	
	$('.menu li a').click(function(){
		$('li a').removeClass('activo');
		$(this).addClass('activo');
	});
	
	$('<div class="bloque2"></div><div class="bloque3"></div><div class="bloque4"></div><div class="bloque5"></div><div class="bloque6"></div></div>').insertAfter('.bloque');
	$('.bloque').attr('class','bloque1').load('index.php .bloque');
	$('.bloque2').load('maquetacion-emailing.php .bloque');
	$('.bloque3').load('adaptacion-plantillas-cms.php .bloque');
	$('.bloque4').load('otros-servicios.php .bloque');
	$('.bloque5').load('contacto.php .bloque');
	$('.bloque6').load('ultimos-trabajos.php .bloque');
	
	$('a.maquetacion').click(function(){
		animacion_menu(171);
		animacion_contenido(136);
		document.title='Maquetación  web | Topnics';
	});
	$('a.emailing').click(function(){
		animacion_menu(200);
		animacion_contenido(-404);
		document.title='Maquetación especial para campañas de emailings | Topnics';
	});
	$('a.plantillas').click(function(){
		animacion_menu(229);
		animacion_contenido(-944);
		document.title='Plantillas para CMS | Topnics';
	});
	$('a.servicios').click(function(){
		animacion_menu(258);
		animacion_contenido(-1484);
		document.title='Otros servicios | Topnics';
	});
	$('a.contacto').click(function(){
		animacion_menu(287);
		animacion_contenido(-2024);
		document.title='Contacto | Topnics';
	});
	$('a.trabajos').click(function(){
		animacion_menu(316);
		animacion_contenido(-2564);
		document.title='Últimos trabajos | Topnics';
	});
	
	//Enviar formulario
	$('#formulario').livequery('submit',function(){
		// Precarga
		$('#formulario').ajaxStart(function(){
			$('.precarga').fadeIn('slow');
		});
		$('#formulario').ajaxStop(function(){
			$('.precarga').css('display','none');
			$('.mensaje').fadeIn('slow');
		});
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			// Respuesta
			success: function(data) {
				$('.respuesta').html(data);
				$('.precarga').css('display','none');
			}
		});     
		return false;
	});
	
	//Popups formulario
	$('.enlace_legal').livequery( 'click',function(){
		$('.legal').fadeIn('slow');
	});
	$('.legal .cerrar').livequery( 'click',function(){
		$('.legal').fadeOut('slow');
	});
	$('.mensaje .cerrar').livequery( 'click',function(){
		$('.mensaje').fadeOut('slow');
		$('.precarga').css('display','none');
	});
});
