function BackBlack()
{
	if( $("#BackBlack").length <= 0 )
	{
		var b = document.createElement("div");
		$(b).attr("id","BackBlack");
		$(b).css({
			width: 800,
			height: 600,
			position: "absolute",
			left: $(".contenedor").offset().left,
			top: $(".contenedor").offset().top,
			background: "#000",
			opacity: 0,
			zIndex: 998
		});
		
		$(b).appendTo("body");
		
		$(b).animate({opacity:.8},1000);
	}
	else
	{
		$("#BackBlack").fadeOut(1000).queue(function(){
			$(this).remove();
		});
	}
}

function Abrir( que )
{
	switch( que )
	{
		case "estefano":
			AbrirEstefano();
			
			$("title").html( $("title").html() + " - ¿Quién soy?" );
		break;
		case "portfolio":
			AbrirPortfolio();
			
			$("title").html( $("title").html() + " - Mi portfolio de trabajo" );
		break;
		case "twitter":
			$(".content-twitter").animate({top:-300},1000);
			ObtenerLosTwitts();
			
			$("title").html( $("title").html() + " - Mis ultimos Twitts" );
		break;
		case "contacto":
			AbrirContacto();
			
			$("title").html( $("title").html() + " - Contactate conmigo" );
		break;
	}
}

function AbrirEstefano()
{
	if( $("#detalles_estefano").length <= 0 )
	{
		var Estefano = document.createElement("div");
		$(Estefano).attr("id","detalles_estefano");
		$(Estefano).css({
			width: 550,
			height: 340,
			background: "url(imagenes/estefano_estefano_vac.png) no-repeat",
			position: "absolute",
			left: ( $(".contenedor").offset().left ) + 150,
			top: ( $(".contenedor").offset().top ) + 100,
			zIndex: 999,
			display: "none"
		});
		
		BackBlack();
		
		$(Estefano).appendTo("body");
		
		var Fecha = new Date();
		var AnioActual = Fecha.getFullYear();
		
		$(Estefano).html("<div style='width: 405px; height: 285px; font-family: Arial; line-height: 150%; font-size: 10pt; padding: 20px;'>Mi nombre es <b>Estefano Salazar.</b><br />Tengo <b>" + (parseInt(AnioActual)-1991) + " años</b>.<br />Soy un joven <b>activo y sociable</b>.<br />Soy <b>desarrollador web</b> desde el año <b>2006</b>.<br />Trabajo con <b>php (patron mvc), mysql, javascript (framework jquery), ajax, html y css</b>.<br />Poseo experiencia <b>desarrollando aplicaciones en c#.net, mssql server y perl</b>.<br />Administro <b>servidores</b> bajo plataformas <b>FreeBSD, Linux CentOS y Windows Server</b>.<br />Llevo <b>2 años de trabajo en grupo</b> donde me desenvuelvo con <b>eficacia y rapidez</b>.<br />Se <b>explayarme con claridad, como así también se escuchar</b>.</div>");
		
		$(Estefano).fadeIn(500);
		
		BotonCerrar( "estefano" );
	}
	else
	{
		$("#detalles_estefano").fadeOut(500).queue(function(){
			$(this).remove();
		});
	}
}

function AbrirPortfolio()
{
	if( $("#detalles_portfolio").length <= 0 )
	{
		var Portfolio = document.createElement("div");
		$(Portfolio).attr("id","detalles_portfolio");
		$(Portfolio).css({
			width: 710,
			height: 440,
			background: "url(imagenes/estefano_portfolio.png) no-repeat",
			position: "absolute",
			left: ( $(".contenedor").offset().left ) + 60,
			top: ( $(".contenedor").offset().top ) + 100,
			zIndex: 999,
			display: "none",
			overflow: "hidden"
		});
		
		//$(Portfolio).attr("title","Click para cerrar");
		
		BackBlack();
		
		$(Portfolio).appendTo("body");
		
		$(Portfolio).fadeIn(500);
		
		$.ajax({
			url: "ajax/web.portfolio.php",
			data: "a=t",
			async: false,
			success: function(data){
				$(Portfolio).html(data + "<div class='cerrar-portfolio'></div>");
			}
		});
		
		BotonCerrar( "portfolio" );
	}
	else
	{
		$("#detalles_portfolio").fadeOut(500).queue(function(){
			$(this).remove();
		});
	}
}

function AbrirContacto()
{
	if( $("#detalles_contacto").length <= 0 )
	{
		var Contacto = document.createElement("div");
		$(Contacto).attr("id","detalles_contacto");
		$(Contacto).css({
			width: 550,
			height: 340,
			background: "url(imagenes/estefano_contacto.png) no-repeat",
			position: "absolute",
			left: ( $(".contenedor").offset().left ) + 150,
			top: ( $(".contenedor").offset().top ) + 100,
			zIndex: 999,
			display: "none"
		});
		
		BackBlack();
		
		$(Contacto).appendTo("body");
		
		$(Contacto).html("<div id='formulario_contacto' style='width: 405px; height: 285px; font-family: Arial; line-height: 150%; font-size: 10pt; padding: 20px;'></div>");
		
		$.ajax({
			url: "ajax/web.contacto.php",
			data: "acc=get",
			async: false,
			success: function(data){
				$("#formulario_contacto").html(data);
			}
		});
		
		$(Contacto).fadeIn(500);
		
		BotonCerrar( "contacto" );
	}
	else
	{
		$("#detalles_contacto").fadeOut(500).queue(function(){
			$(this).remove();
		});
	}
}

function BotonCerrar( elemento )
{	
	var Cerrar = document.createElement("div");
	$(Cerrar).attr("id","cerrar_elementos");
	$(Cerrar).css({
		width: 24,
		height: 24,
		position: "absolute",
		left: $("#detalles_" + elemento).offset().left,
		top: $("#detalles_" + elemento).offset().top - 24,
		zIndex: 1000
	});
	
	$(Cerrar).appendTo( "body" );
	
	$(Cerrar).attr("title","Click para cerrar");
	
	$(Cerrar).html("<a href='#' onclick='CierraTodo(\"" + elemento + "\"); return false;'><img src='imagenes/cerrar.png' /></a>");
	
	$("title").html( "Estefano Salazar" );
}

function CierraTodo( Seccion )
{
	$("#cerrar_elementos").remove();
	BackBlack();
	switch( Seccion )
	{
		case "portfolio":
			AbrirPortfolio();
			window.location = "#!";
		break;
		case "estefano":
			AbrirEstefano();
			window.location = "#!";
		break;
		case "contacto":
			AbrirContacto();
			window.location = "#!";
		break;
		default:
			alert( "Error" );
			window.location = "#!";
		break;
	}
}

$(window).ready(function(){
	$(".contenedor").css({
		marginTop: ( $(window).height() - 600 ) / 2
	});
});

function envia_contacto()
{
	if( $("#ct_nombre").val() && $("#ct_apellido").val() && $("#ct_email") )
	{
		var Nombre, Apellido, Email, Mensaje;
		Nombre = escape( $("#ct_nombre").val() );
		Apellido = escape( $("#ct_apellido").val() );
		Email = escape( $("#ct_email").val() );
		Mensaje = escape( $("#ct_mensaje").val() );
		
		$.ajax({
			url: "ajax/web.save_contact.php",
			data: "acc=save&n=" + Nombre + "&a=" + Apellido + "&e=" + Email + "&m=" + Mensaje,
			type: "post",
			async: false,
			success: function(data){
				alert( data );
				
				CierraTodo("contacto");
			}
		});
	}
}

