var viendo_contact = false;
var ancho_tira_imagenes = 0;

$(document).ready(function() {
	
	
	 $(".tira_imagenes .img").each(function () {
		  ancho_tira_imagenes += $(this).width();
	 });
	
	$(".bar_slide").hover(function() { tiritaAbre(this); }, function() { tiritaCierra(this); });
	
	$('#slides').slides({
		preload: true,
		preloadImage: 'elementos/loading.gif',
		play: 5000,
		pause: 2500,
		hoverPause: false
	});
	
	$(".preview").hover(function() { $(this).children('.info_box').show(); }, function() { $(this).children('.info_box').hide(); });
	
	$("#btn_contact").click(function (evento) {
		evento.preventDefault();
		if (viendo_contact) {
			$("#contact").slideUp();
			$(this).children("img").attr("src", "elementos/bot_contact_off.jpg");
			viendo_contact = false;
		} else {
			$("#contact").slideDown();
			$(this).children("img").attr("src", "elementos/bot_contact.jpg");
			viendo_contact = true;
		}	
	});
	
	$("#flecha_next").click(function (evento) {
		evento.preventDefault();
		maximo = (ancho_tira_imagenes * -1) + 50 + $(".tira_imagenes .img:first").width();
		if (($(".tira_imagenes").position().left > maximo) && ($(".tira_imagenes").queue().length <= 0)) {
			$("#slide_contiene .tira_imagenes .img .video").css('display', 'none');
			if (($(".tira_imagenes").position().left - $(".tira_imagenes .img:first").width()) <= maximo) {
					$(this).addClass('disabled');
			}
			if ($(this).hasClass('tipo16_9')) {
				// Movimiento grande para 16:9
				$(".tira_imagenes").animate({left: '-=644'}, 200, 'linear');
			} else {
				
				$(".tira_imagenes").animate({left: '-=482'}, 200, 'linear');
			}
			$("#flecha_back").removeClass('disabled');
		} 
		
		
	});
	$("#flecha_back").click(function (evento) {
		evento.preventDefault();
		if (($(".tira_imagenes").position().left < 50) && ($(".tira_imagenes").queue().length <= 0)) {
			$("#slide_contiene .tira_imagenes .img .video").css('display', 'none');
			if (($(".tira_imagenes").position().left + $(".tira_imagenes .img:first").width()) >= 50) {
					$(this).addClass('disabled');
			}
			if ($(this).hasClass('tipo16_9')) {
				// Movimiento grande para 16:9
				$(".tira_imagenes").animate({left: '+=644'}, 200, 'linear');
			} else {
				$(".tira_imagenes").animate({left: '+=482'}, 200, 'linear');
			}
			$("#flecha_next").removeClass('disabled');	
		}
		
	});
	
	$("#slide_contiene .tira_imagenes .img .btn_play").click(function (evento) {
		evento.preventDefault();
		$("#slide_contiene .tira_imagenes .img .video").show();
	});
	
	$("#contact input, #contact textarea").click(function (evento) {
		evento.preventDefault();
		if ($(this).val()==$(this).attr('alt')) {
			$(this).val('');
			$(this).addClass('active');
		}
	});
	$("#contact input, #contact textarea").blur(function (evento) {
		evento.preventDefault();
		if ($(this).val()=='') {
			$(this).val($(this).attr('alt'));
			$(this).removeClass('active');
		}
	});
	
	$("#feedback").click(function (evento) {
		evento.preventDefault();
		$.post("keep.php", { nombre: $('#Nombre').val(), email: $('#Email').val(), comments: $('#Comments').val(), aj: 1 });
		$(".tapita").show();
	});
	
	$("#register").click(function (evento) {
		evento.preventDefault();
		$.post("keep.php", { mail: $('#Suscribe').val(), aj: 1 });
		$(".tapita2").show();
	});
	
});
