﻿
function cufonear() {
    Cufon.replace(".cufon-h1", { hover: true, fontFamily: 'Helvetica Neue LT Std' });
    Cufon.replace(".cufon-h2", { hover: true, fontFamily: 'Helvetica LT Std' });
    Cufon.replace(".cufon-helvn-bold", { hover: true, fontFamily: 'Helvetica Neue Bold' });
}

function activarSelectores() {

    $('.selector').unbind('click');
    
    $('.selector').click(function () {
    
        $(this).toggleClass("seleccionado");
          
    });
}

function iluminar(objeto) {

    $(objeto).animate({ backgroundColor: "#B9DC23" }, 200);
    $(objeto).animate({ backgroundColor: "#fff" }, 1500);
}

function mostrarSwf(movie, width, height) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '" ID="sf" VIEWASTEXT>');
    document.write('  <param name="movie" value="' + movie + '" />');
    document.write('  <param name="quality" value="high" />');
    document.write('  <param name="wmode" value="window" />');
    document.write('  <param name="allowScriptAccess" value="always" />');
    document.write('  <param name="allowFullScreen" value="true" />');
    document.write('  <embed src="' + movie + '" quality="high" name="sf" allowScriptAccess="always" allowFullScreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" />');
    document.write('</object>');
}

/* GENERICO CARRUSSEL */
/**********************/

function inicializarCarrusel(classeCss) {

    var carruseles = $(classeCss);

    for (var i = 0; i < $(carruseles).length; i++) {

        inicializarCarrusel($(carruseles[i]));

    }
}

function inicializarCarrusel(objeto) {

    var flechaIzquierda = $(objeto).find(".flecha-izquierda");
    var flechaDerecha = $(objeto).find(".flecha-derecha");

    $(flechaIzquierda).click(desplazarIzquierdaCarrusel);
    $(flechaDerecha).click(desplazarDerechaCarrusel);

    $(objeto).find(".elementos li a").click(mostrarZoom);

    var numeroElementos = parseInt($(objeto).find(".visualizador ul li").length);

    var numeroElementosAMostrar = parseInt($(objeto).attr("numero-elementos-mostrados"));
    
    if (numeroElementos <= numeroElementosAMostrar) {
        ocultaFlecha($(flechaIzquierda));
        ocultaFlecha($(flechaDerecha));
    } else {
        ocultaFlecha($(flechaIzquierda));
    }
}

function mostrarZoom() {
        
    var contenedor = $(this).parent().parent().parent().parent().parent().parent().parent();

    var link = $(this).attr('href');

    $(contenedor).find(".zoom").fadeIn();

//    var img = $(contenedor).find(".zoom .pantalla img");

//    if (img.length) { $(contenedor).find(".zoom .pantalla").height(img.height()); }

    $(contenedor).find(".zoom .pantalla").hide();
    $(contenedor).find(".zoom .pantalla").empty();
    $(contenedor).find(".zoom .pantalla").append("<img src=" + link + "/>");
    $(contenedor).find(".zoom .pantalla").fadeIn();
    
    return false;
}

function desplazarIzquierdaCarrusel() {

    var contenedor = $(this).parent().parent();

    var flechaIzquierda = $(contenedor).find(".flecha-izquierda");
    var flechaDerecha = $(contenedor).find(".flecha-derecha");

    var anchoElemento = parseInt($(contenedor).find(".visualizador ul li").width());
    var numeroElementos = parseInt($(contenedor).find(".visualizador ul li").length);
    var numeroElementosAMostrar = parseInt($(contenedor).attr("numero-elementos-mostrados"));
    var numeroElementoInicial = parseInt($(contenedor).attr("numero-elemento-inicial"));
    
    var elementosAnimables = $(contenedor).find("li");
    var tooltips = $(contenedor).find(".panel-tooltip");
    var barraAnimable = $(contenedor).find(".slider");
    var anchoUnidadDesplazamientoBarra = parseInt($(contenedor).attr("ancho-unidad-desplazamiento-barra"));

    if (numeroElementoInicial - numeroElementosAMostrar >= 1) {
        if (numeroElementoInicial - numeroElementosAMostrar == 1) ocultaFlecha($(flechaIzquierda));
        $(elementosAnimables).animate({ "left": "+=" + anchoElemento * numeroElementosAMostrar }, "slow");
        $(tooltips).animate({ "left": "+=" + anchoElemento * numeroElementosAMostrar }, "slow");
        $(barraAnimable).animate({ "left": "-=" + anchoUnidadDesplazamientoBarra * numeroElementosAMostrar }, "slow");
        numeroElementoInicial -= numeroElementosAMostrar;
        $(contenedor).attr("numero-elemento-inicial", numeroElementoInicial);
        muestraFlecha($(flechaDerecha));
    } else {

        var cantidadElementosAMostrar = 0;

        while (numeroElementoInicial > 1) {
            numeroElementoInicial--;
            cantidadElementosAMostrar++;
        }
        $(contenedor).attr("numero-elemento-inicial", numeroElementoInicial);
        $(elementosAnimables).animate({ "left": "+=" + anchoElemento * cantidadElementosAMostrar }, "slow");
        $(tooltips).animate({ "left": "+=" + anchoElemento * cantidadElementosAMostrar }, "slow");
        $(barraAnimable).animate({ "left": "-=" + anchoUnidadDesplazamientoBarra * cantidadElementosAMostrar }, "slow");
        muestraFlecha($(flechaDerecha));
        ocultaFlecha($(flechaIzquierda));
    }

}

function desplazarDerechaCarrusel() {

    var contenedor = $(this).parent().parent();

    var flechaIzquierda = $(contenedor).find(".flecha-izquierda");
    var flechaDerecha = $(contenedor).find(".flecha-derecha");

    var anchoElemento = parseInt($(contenedor).find(".visualizador ul li").width());
    var numeroElementos = parseInt($(contenedor).find(".visualizador ul li").length);
    var numeroElementosAMostrar = parseInt($(contenedor).attr("numero-elementos-mostrados"));
    var numeroElementoInicial = parseInt($(contenedor).attr("numero-elemento-inicial"));

    var elementosAnimables = $(contenedor).find("li");
    var tooltips = $(contenedor).find(".panel-tooltip");
    var barraAnimable = $(contenedor).find(".slider");
    var anchoUnidadDesplazamientoBarra = parseInt($(contenedor).attr("ancho-unidad-desplazamiento-barra"));

    if (numeroElementoInicial + numeroElementosAMostrar <= (numeroElementos - numeroElementosAMostrar)) {

        $(elementosAnimables).animate({ "left": "-=" + anchoElemento * numeroElementosAMostrar }, "slow");
        $(tooltips).animate({ "left": "-=" + anchoElemento * numeroElementosAMostrar }, "slow");
        $(barraAnimable).animate({ "left": "+=" + anchoUnidadDesplazamientoBarra * numeroElementosAMostrar }, "slow");
        numeroElementoInicial += numeroElementosAMostrar;
        $(contenedor).attr("numero-elemento-inicial", numeroElementoInicial);
        muestraFlecha($(flechaIzquierda));
    } else {

        var cantidadElementosAMostrar = 0;

        while (numeroElementoInicial < ((numeroElementos + 1) - numeroElementosAMostrar)) {
            numeroElementoInicial++;
            cantidadElementosAMostrar++;
        }
        $(contenedor).attr("numero-elemento-inicial", numeroElementoInicial);
        $(elementosAnimables).animate({ "left": "-=" + anchoElemento * cantidadElementosAMostrar }, "slow");
        $(tooltips).animate({ "left": "-=" + anchoElemento * cantidadElementosAMostrar }, "slow");
        $(barraAnimable).animate({ "left": "+=" + anchoUnidadDesplazamientoBarra * cantidadElementosAMostrar }, "slow");
        muestraFlecha($(flechaIzquierda));
        ocultaFlecha($(flechaDerecha));
    }

}

function ocultaFlecha(flecha) {

    $(flecha).fadeOut("slow");
}

function muestraFlecha(flecha) {

    $(flecha).fadeIn("slow");
}

function ocultaFlechas(flecha1, flecha2) {

    ocultaFlecha($(flecha1));
    ocultaFlecha($(flecha2));
}

function muestraFlechas(flecha1, flecha2) {

    muestraFlecha($(flecha1));
    muestraFlecha($(flecha2));
}
