// JavaScript Document
//funciones para manejar el carrusel
function intval(v) {
    v = parseInt(v);
    return isNaN(v) ? 0: v;
}

function carouselScrollRight() {
    detalleServiciosWidth = intval($("#carruselServicios").css("width"));
    pos = intval($("#carruselServicios").css("left"));
    if (((pos % clipArea) == 0) && ((detalleServiciosWidth + pos) > clipArea)) $("#carruselServicios").animate({
        left: pos - clipArea
    },
    'normal');
}

function carouselScrollLeft() {
    pos = intval($("#carruselServicios").css("left"));
    if ((pos < 0) && ((pos % clipArea) == 0)) $("#carruselServicios").animate({
        left: pos + clipArea
    },
    'normal');
}

function buscarServicio(id) {
    detalleServiciosWidth = intval($("#carruselServicios").css("width"));
    pos = intval($("#carruselServicios").css("left"));
    idServicio = id;
    posCalc = (idServicio * clipArea) * -1;
    $('#carruselServicios').animate({
        left: posCalc
    },
    'normal').fadeIn();
    $("#controlador li a").css("background-color", "#4D4B4E");
    $("#controlador li[rel=" + idServicio + "] a").css("background-color", "#009900");
}

function setCarousel() {
    detalleServiciosArray = $(".detalleServicio").get();
    $("#carruselServicios").css("width", clipArea * detalleServiciosArray.length + "px");

    if (detalleServiciosArray.length == 1) {
        $("#prev").hide();
        $("#next").hide();
    }
}



function recargarCriterios(){
	  $.ajax({
			type: "GET",
			url: "listado.php",
			data: "<?=$laURL?>&buscar=<?=$buscar?>&nombreCategoria=<?=$nombreCategoria?>&filtro="+$("#filterCombo").val()+"&orden="+$("#orderCombo").val(),
			dataType: "html",
			success: function(datos){
				$('#listado').html(datos);
				  }
			});
}

function procesoBusqueda(busqueda){
			$.ajax({
				type: "GET",
				url: "listado.php",
				data: "<?=$buscarURL?>&orden=<?=$orden?>&filtro=<?=$filtro?>&pag=<?=$pag?>&nombreCategoria=<?=$nombreCategoria?>&buscar="+busqueda,
				dataType: "html",
				success: function(datos){				
				$('#listado').html(datos);
				}
			});
}

function activarMenu(categoria){
	//console.log($(".level_2").children().addClass('activo'));
	$(".level_2").each(function(i){
	  menu=$(this);
	  if(menu.children().attr('id')==categoria){
	  	menu.children().addClass('activo');
	  }	  
	 });
}