/*!
 * miGaleria JavaScript Library v1.0.0
 * juanlcastrom@hotmail.com
 *
 * Copyright (c) 2011 Juan Luis Castro
 * Dual licensed under the MIT and GPL licenses.
 *
 * Ultima Revisión : 2011-04-09
 * Revision: 0001
 */
var GaleriaFotos = function(options) {

    // Elementos parametrizables.
    this.contenedor = "body";
    this.ancho = "150px";
    this.alto = "200px";
    this.posx = "0px";
    this.posy = "0px";
    this.borde = "1px solid #990011";
    this.tiempoCambio = 1000;
    this.tiempoDevuelta = 1000;
    this.obj = '';
    // this.opacidad = "0.5";

    // Otros elementos.
    this.elementos = 0;
    this.parado = false;

    this.actual =  0;
    this.ltInterval = 0;
    this.lnAncho = 150;

    $.extend(this, options);

    $(this.contenedor).css("position","relative");
    $(this.contenedor).css("left",this.posx);
    $(this.contenedor).css("top",this.posy);
    $(this.contenedor).css("border",this.borde);
    $(this.contenedor).css("width",this.ancho);
    $(this.contenedor).css("height",this.alto);
    $(this.contenedor).css("overflow","hidden");
    
    $(this.contenedor).children().css("position","absolute");
    $(this.contenedor).children().css("width",this.ancho);
    $(this.contenedor).children().css("height",this.alto);
    
    this.lnAncho = $(this.contenedor).width();

    var n = 0;
    var _ancho = this.lnAncho;

    $(this.contenedor).children().each(function()
    {
        $(this).css("left", "0px");
        $(this).css("left",n *(_ancho) +"px");
        n++;
    });

    this.elementos = n;
   
    this.animar = function () {
        // alert(this.parado);
        if ( !this.parado ) {
            
            if ( this.actual >= this.elementos-1 ) {
                this.actual = 0;
                var lnDer = this.lnAncho * (this.elementos - 1);
                    
                $(this.contenedor).children().animate({left:'+='+lnDer},this.tiempoCambio);
                return;
            }

            if (!this.parado) {
                lnId = this.ltInterval;
                // alert(lnId);
                // alert(lnId);
                clearInterval(lnId);
                var lcFN = this.obj+".animar()";
                
                if (this.actual == 0)
                { $(this.contenedor).children().delay(500).animate({left:'-='+this.lnAncho},this.tiempoCambio).delay(500);}               
                else 
                { $(this.contenedor).children().animate({left:'-='+this.lnAncho},this.tiempoCambio)}

                this.actual +=1;
                
                var lnId = setInterval(lcFN,3000);
                this.ltInterval = lnId;
            }
        }
    }


    this.anima = function(obj) {
        // alert(ltInterval);
        this.obj = obj;
        var lnId = setInterval(this.obj+'.animar()',3000);
        this.ltInterval = lnId;
    }

    this.comenzar = function() {
        this.parado = false;
    }

    this.parar = function() { 
        this.parado = true;
    }
}


