$(document).ready(function(){
var ieVer=/*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; }}()||@*/0;
	MaxH=$("#items div").height();
	fff=$("#servicios").height();
	if (ieVer==6) {MaxH+=40;}
	if (ieVer>6) {MaxH+=10;}
	getPage(document.location.href);
	function getPage(url){
		$("#preview").fadeOut(250,function(){
										   $("#preview").html("<span class='loader'></span>");
										   $("#preview").fadeIn(250);
										   l=url.split("#");
										   if(l.length>1){
											   new_url=l[1];
											   if(new_url=="contacto"){
												   modal();
												   new_url=$("#items div ul li:first a").attr("href");
												   l=new_url.split("#");
												   new_url=l[1];
												}
											}else{
												new_url=$("#items div ul li:first a").attr("href");
												l=new_url.split("#");
												new_url=l[1];
											}
											$.ajax({cache: false,error: function(){
																				 $("#preview").html('<h3>Página <em>'+new_url+'</em> no encontrada.</h3>');
																				},
																				url: "includes/"+new_url+".html",
																				success: function(html){
																					$("#preview").fadeOut(250,function(){
																													   $("#preview").html(html);
																													   $("#preview").fadeIn(1000);
																					});
																				}
											});
		});
	}
	
	$("#items div ul li a").click(function(){a=$(this).attr("href");getPage(a);});
	$('.black').hide();
	$('.black').css({opacity:0});
	$('#formulario').hide();
	$('#formulario').css({opacity:0});
	$("#items div ul li:gt(7)").hide();
	MinH=$("#items div").height();
	if (ieVer==6) {MinH+=40;}
	if (ieVer>6) {MinH+=10;}
	$('#items div').css({height:MinH});
	
	$("#items div ul li:gt(7)").css({opacity: 0});
	
	$(".more").toggle(
					  	function () {
							
						  	$("#items div ul li:gt(7)").show();
						  	$("#items div ul li:gt(7)").animate({opacity: 1}, 1500 );
						  	$("#items div").animate({height: MaxH}, 1500,function(){$(".more").text('Vista Compacta');});
						}						,
						function () {
							$("#items div ul li:gt(7)").animate({opacity: 0}, 1500 );
							$("#items div").animate({height: MinH}, 1500,function(){$("#items div ul li:gt(7)").hide();$(".more").text('Vista Completa');});
						}
	);
	$("#items div ul li a").click(function(){
										  a=$(this).attr("href");
										  getPage(a);
										  });
	});


function modal(){
	$('#formulario').show('fast',function (){
										   mytop=($('body').height()/2)-($('#formulario').height()/2);
										   myleft=($('body').width()/2)-($('#formulario').width()/2);
										   $('#formulario').css({top:mytop+"px",left:myleft+"px"});});
	$('.black').show();$('.black').animate({opacity: .8}, 1000 );
	$('#formulario').animate({opacity: 1}, 1000);
}


function nomodal(){
	$('.black').animate({opacity: 0}, 500 );
	$('#formulario').animate({opacity: 0}, 500,function(){
														$('.black').hide();
														$('#formulario').hide();}
														);
	$('#formulario .loading').hide();
	$('#nombre').css("color","#ffffff");
	$('#email').css("color","#ffffff");
	$('#mensaje').css("border","1px solid #ccc");
}


function send(){
	ob=3;
	if($('#nombre').val()=="" || $('#nombre').val()=="No puede estar vacio."){
		ob--;$('#nombre').css("color","#ffff00");
		$('#nombre').val('No puede estar vacio.');
	}
	if($('#mensaje').val()=="" || $('#mensaje').val()=="No puede estar vacio."){
		ob--;$('#mensaje').css("border","2px solid #ffff00");
		$('#mensaje').val('No puede estar vacio.');
	}
	if($('#email').val()=="" || $('#email').val()=="No puede estar vacio."){
		ob--;
		$('#email').css("color","#ffff00");
		$('#email').val('No puede estar vacio.');
	}
	if(ob==3){
		$('#formulario .loading').show();
		$('#formulario').load('enviar.php',{nombre:$('#nombre').val(),email:$('#email').val(),asunto:$('#asunto').val(),mensaje:$('#mensaje').val()});
	}
}
