/*
 * Funciones ALKLA
 *
 * Copyright (c) 2010 Alkla Estudio de Diseņo
 * http://www.alkla.es
 *
 */
 
$(document).ready(function(){
	
	// Tipografia
	$('input.button').each(function(){
        $(this).after(unescape('%3Ca class="button"%3Eaa%3C/a%3E'));
        $(this).hide();
        $(this).next('a.button').text($(this).val()).click(function(){
            $(this).prev('input.button').click();
			return false;
        });
    });
	$('#commentform input#submit').each(function(){
        $(this).after(unescape('%3Ca class="button"%3Eaa%3C/a%3E'));
        $(this).hide();
        $(this).next('a.button').text($(this).val()).click(function(){
            $(this).prev('#commentform input#submit').click();
			return false;
        });
    });
	Cufon.replace("h2,h3,h4,blockquote");
	Cufon.replace("body.single #main h1");
	Cufon.replace("body.search #main h1");
	Cufon.replace("body.error404 #main h1");
	Cufon.replace("body.page-template-page-curriculum-php #main h1");
	Cufon.replace("#breadcrumbs");
	Cufon.replace("#site-menu a", { hover: true });
	Cufon.replace("#site-submenu a", { hover: true });
	Cufon.replace("a.button", { hover: true });
	Cufon.replace("a.button_big", { hover: true });
	Cufon.replace("#index-slidenav a", { hover: true });
	Cufon.replace("a.comment-reply-link", { hover: true });
	
	
	// CSS
	
	
	// Listeners
	$("#contacto-form input.button").bind('click', validar_contacto);
	$("#contacto_panel-form").bind('submit', validar_contacto_panel);
	$("#panel-trigger a").bind('click', panel_open);
	$("#panel a").bind('click', panel_close);
	$("#button-back").bind('click', return_back);
	$("#equipo .equipo_box").bind('mouseenter', tooltip_show);
	$("#equipo .equipo_box").bind('mouseleave', tooltip_hide);
	$("a.equipo_link").bind('click', do_null);
	
	
	// Menu
	var menu = $("#searchmenu").val();
	$("#site-menu ul").lavaLamp({
		fx: 'easeOutExpo',
		speed: 800,
		startItem: menu,
		includeMargins: false
	});
	

	// Slide
	$('#sidebar-news_slide').cycle({ 
		fx: 'scrollHorz', 
		easing: 'easeOutQuint',
		speed: 1000, 
		timeout: 10000,
		pager:  '#sidebar-news_slidenav'
	});
	$('#index-slide').cycle({ 
		fx: 'fade', 
		speed: 600, 
		timeout: 10000,
		pager:  '#index-slidenav'
	});
	
	
	// Carrusel
	$("#index-marcas_slide ul").simplyScroll({
		autoMode: 'loop',
		speed: 4
	});
	
	
});



function return_back ()
{
	history.back(1);
	return false;
}



/**********************************************/
/*
/*   TOOLTIP
/*
/**********************************************/

function tooltip_show()
{
	$(this).children('.tooltip').addClass('active');
	$(this).children('.tooltip').css({
		top: 0,
		display: 'block',
		opacity: 0,
	}).animate({
    	opacity: 1,
    	top: '-=60',
  	}, 500, function() {
		
  	});

}
function tooltip_hide()
{
	$(this).children('.tooltip').removeClass('active');
	$(this).children('.tooltip').css({
		opacity: 1,
	}).animate({
    	opacity: 0,
    	top: '+=60',
  	}, 500, function() {
		
  	});
}

function do_null()
{
	return false;	
}


/**********************************************/
/*
/*   PANEL
/*
/**********************************************/

function panel_open()
{
	$('#panel-trigger').animate({
		bottom: '-=60'
  	}, 500, function() {
		$('#panel').show();
    	$('#panel').animate({
			bottom: '+=230'
		}, 1000, function() {
		});
  	});
	return false;
}
function panel_close()
{
	$('#panel').animate({
		bottom: '-=230'
  	}, 1000, function() {
		$('#panel-trigger').show();
    	$('#panel-trigger').animate({
			bottom: '+=60'
		}, 1000, function() {
		});
  	});
	return false;
}

function validar_contacto_panel()
{

	var email = $("#contacto_panel-email").val();
	var linkedin = $("#contacto_panel-linkedin").val();
	var mensaje = $("#contacto_panel-mensaje").val();
	var path = $("#contacto_panel-path").val();
	var error = false;
	var error_msg = "";

	if (email == ""){
		error = true;
	}
	if (linkedin == ""){
		error = true;
	}
	
	if (!error){	
		var param = "email=" + email + "&linkedin=" + linkedin + "&mensaje=" + mensaje;
		
		$.ajax({
			async:true,
			type: "post",
			dataType: "xml",
			contentType: "application/x-www-form-urlencoded",
			url: path + "/library/contacto_panel.php",
			data:param,
			success:validar_contacto_panel_complete,
			timeout:10000,
			error:null
		});
	}
	return false;
}
function validar_contacto_panel_complete(t)
{
	panel_close();
}


/**********************************************/
/*
/*   CONTACTO
/*
/**********************************************/

function validar_contacto()
{
	var email = $("#contacto-email").val();
	var nombre = $("#contacto-nombre").val();
	var telefono = $("#contacto-telefono").val();
	var mensaje = $("#contacto-mensaje").val();
	var path = $("#contacto-path").val();
	var error = false;
	var error_msg = "";
	
	$("#contacto-msg").removeClass();

	if (nombre == ""){
		error = true;
		error_msg = error_msg + $("#contacto-error_nombre").val() + '<br/>';
	}
	if (email == ""){
		error = true;
		error_msg = error_msg + $("#contacto-error_email").val() + '<br/>';
	}
	
	if (!error){	
		var param = "email=" + email + "&nombre=" + nombre + "&telefono=" + telefono + "&mensaje=" + mensaje;
		$("#contacto-msg").html("...");
		$.ajax({
			async:true,
			type: "post",
			dataType: "xml",
			contentType: "application/x-www-form-urlencoded",
			url: path + "/library/contacto.php",
			data:param,
			success:validar_contacto_complete,
			timeout:10000,
			error:null
		});
	}else{
		$("#contacto-msg").addClass("error");
		$("#contacto-msg").html(error_msg);
	}
	return false;
}
function validar_contacto_complete(t)
{	
	var path = $("#contacto-path").val();
	var error_msg = $("#contacto-ok").val();
	$("#contacto-msg").html(error_msg);
	document.getElementById("contacto-form").reset();
}

