// JavaScript Document
var counter = 0;
var posicion = 570;
var distancia = -570;
var direccion = true;
var totalclientes;
var intervalo;

function rotarClientes(){
	
	$('.cliente:eq('+counter+')').animate({left: distancia},"slow",function(){
		$(this).css("left",posicion+"px");																   
	});
	if(direccion){
		if(counter < totalclientes-1){
			counter++;	
		}else{
			counter = 0;	
		}
	}else{
		if(counter > 0){
			counter--;	
		}else{
			counter = totalclientes-1;
		}	
	}
	$('.cliente:eq('+counter+')')
	.css("left",posicion+"px")
	.animate({left: 0},"slow");

}
$(document).ready(function(){
	totalclientes = $('.cliente').size();
	$('.cliente:eq('+ counter +')').animate({left:0},"slow",function(){
		intervalo = setInterval(rotarClientes,5000);															 
	});
	
	$('#anterior a').bind("click", function(){		
		clearInterval(intervalo);
		if(!direccion){
			posicion = -570;
			distancia = 570;
			direccion = true;
		}
		$('.cliente:eq('+counter+')').animate({left: distancia},"slow",function(){
			$(this).css("left",posicion+"px");																   
		});
		if(counter < totalclientes -1){
			counter++;	
		}else{
			counter = 0;	
		}	
		$('.cliente:eq('+counter+')')
		.css("left",posicion+"px")
		.animate({left: 0},"slow", function(){
			intervalo = setInterval(rotarClientes,5000);								
		});	
		
		return false;
	})
	$('#siguiente a').bind("click", function(){
		clearInterval(intervalo);
		if(direccion){
			posicion = 570;
			distancia = -570;
			direccion = false;
		}
		$('.cliente:eq('+counter+')').animate({left: distancia},"slow",function(){
			$(this).css("left",posicion+"px");																   
		});
		if(counter > 0){
			counter--;	
		}else{
			counter = totalclientes - 1;	
		}	
		$('.cliente:eq('+counter+')')
		.css("left",posicion+"px")
		.animate({left: 0},"slow", function(){
			intervalo = setInterval(rotarClientes,5000);								
		});
		
		return false;
	})
	
	//validacion de formularios		
	$('form.validar').validate({
		 rules: {
			token_repetir: {
		      equalTo: "#token"
		    }
		},
		submitHandler: function(form) {			   
			form.submit();
		}
	})
	
	$('.categoria').toggle(function(event){				
		var items = $(event.target).parent().parent().find('.subcategoria:first').find('li').size() + 1;
		var alto = items * 28;
		var alto = alto - 2;
		$(event.target).parent().parent().animate({height: alto+"px"}, "fast");								  
	}, function(event){
		$(event.target).parent().parent().animate({height: "26px"}, "fast");
	})
	
	//galeria	
	$('#clientegaleria a').lightBox({fixedNavigation:true});
	
	//eventos
	$('#buscarcampo').focus();
	
	//estatus
	$('#estatus').animate({top:0},"slow",function(){
		setTimeout("ocultarestado()",5000);
	})	
	
	$('.denunciar a').click(function(event){
		$params = $(this).attr('rel').split("-");
		$.get("../request.php", { get: $params[0], params: $(this).attr('href')+"-"+$params[1] }, function(data){
			if(data){
				$(event.target).parent().html('<small>Comentario denunciado</small>');
			}
		});
		return false;
	})
	
	$('.btn_registrarse').toggle(function(e){
		$('#registrarse_form').slideDown("slow");
	}, function(e){
		$('#registrarse_form').slideUp("slow");
	})
	
	$('.check').click(function(){
		if($(".check:checked").length > 0){
			$val = $(this).val();
			$('input[name="check"]').val($val);
		//alert($('input[name="check"]').val());
		//alert($(".check:checked").length);
		}else{
			$('input[name="check"]').val('');
		}
	})
	
})

function ocultarestado(){
	$('#estatus').animate({top: "-50px"},"slow");
}
