
/**
 * Created by IntelliJ IDEA.
 * User: flaminlab
 * Date: 03-feb-2011
 * Time: 14:58:51
 * To change this template use File | Settings | File Templates.
 */

(function ($) {

    var actual = 0;

    $.fn.cambioIdioma = function(opciones) {

        return this.each(function () {
            var $self = $(this);

            $.fn.cambioIdioma.configuracion = $.extend({}, $.fn.cambioIdioma.predeterminados, opciones);
            var configuracion = $.fn.cambioIdioma.configuracion;

            $.each(configuracion.botonesIdiomas, function(indice, valor) {

                var $botonActual = $("#" +configuracion.botonesIdiomas[indice]);

                if(indice > 0) {
                    //$("#"+configuracion.contenedoresIdiomas[indice], $self).css("display", "none");
                }

                $botonActual.click(function () {

                    //alert(indice);


                    // quitar la clase active de todos los botones y ocultar todos los contenidos
                    $.each(configuracion.botonesIdiomas, function(boton, val) {
                        var $boton = $("#" +configuracion.botonesIdiomas[boton]);
                        var $contenedor = $("#" +configuracion.contenedoresIdiomas[boton]);

                        $boton.removeClass("active");
                        $contenedor.css("display", "none");
                    });


                    var $contenidoActual = $("#"+configuracion.contenedoresIdiomas[indice], $self);
                    var $botonAnterior = $("#"+configuracion.botonesIdiomas[indice], $self);

                    $botonActual.addClass("active");

                    actual = indice;
                    $contenidoActual = $("#"+configuracion.contenedoresIdiomas[indice], $self);

                    $contenidoActual.css("display", "block");
                });

            });
        });
    };

    $.fn.cambioIdioma.idiomaActual = 0;

    $.fn.cambioIdioma.predeterminados = {

        botonesIdiomas: ["eventos_es", "eventos_en"],
        contenedoresIdiomas: [ "noticias_cont_es", "noticias_cont_en" ]

    };

    $.fn.cambioIdioma.configuracion = {};

})(jQuery);

$().ready(function () {

    $("#contenedor_prox_eventos").cambioIdioma({});
    $("#contenido_icontec").cambioIdioma({

        botonesIdiomas: ["icontec_es", "icontec_en"],
        contenedoresIdiomas: [ "txt_icontec_es", "txt_icontec_en" ]

    });

});
