/*
    $Date: 2005-10-28 13:16:58 +0200 (vie, 28 oct 2005) $
    $Rev: 111 $
    $Author: jromeu $    
    
    Librería para la gestión de carruseles de imágenes
*/


CarruselImagenes.timeout = 3000; //Tiempo en milisegundos
CarruselImagenes.col=[];
function CarruselImagenes(name){
    this.div = document.getElementById(name);
    this.ctr=0;
    this.timer=null;
    this.imgs=[];
    this.actions=[];
    this.alts=[];
    this.sizes=[];
    this.new_windows=[];
    this.index=CarruselImagenes.col.length;
    CarruselImagenes.col[this.index]=this;
    this.animString="CarruselImagenes.col["+this.index+"]";
};
CarruselImagenes.comenzar=function(){
    var len=CarruselImagenes.col.length,obj;
    for(var i=0;i<len;i++){
        obj = CarruselImagenes.col[i];
        if(obj && obj.div)
            obj.timer=setTimeout("CarruselImagenes.col["+i+"].rotar()",
                CarruselImagenes.timeout);
    }
};
CarruselImagenes.detener=function(n){
    CarruselImagenes.pararTimeouts(n);
};
CarruselImagenes.pararTimeouts=function(n){
    var obj=CarruselImagenes.col[n];
    if(obj){
        clearTimeout(obj.timer);
        obj.timer=null;
    }
};
CarruselImagenes.reanudar=function(n){
    CarruselImagenes.pararTimeouts(n);
    var obj=CarruselImagenes.col[n];
    if(obj){
        obj.timer=setTimeout("CarruselImagenes.col["+obj.index+"].rotar()",100);
    }
};
CarruselImagenes.prototype.insertarBanner=function(src,href,alt,ancho,alto,nw){
    var img = new Image();
    img.src = src;
    this.imgs[this.imgs.length] = img;
    this.actions[this.actions.length] = href;
    this.alts[this.alts.length] = alt;
    this.sizes[this.sizes.length] = [ancho,alto];
    this.new_windows[this.new_windows.length] = nw;
}
CarruselImagenes.prototype.rotar=function(){
    clearTimeout(this.timer);
    this.timer=null;
    this.ctr = (this.ctr + 1) % this.imgs.length;
    var code = '<img src= "' + this.imgs[this.ctr].src + '"' +
        ' border="0"' +
        ' width="' + this.sizes[this.ctr][0] + '"' +
        ' height="' + this.sizes[this.ctr][1] + '"' +
        '/>';
    if ((this.actions[this.ctr] != null) && (this.actions[this.ctr] != '')) {
        var linkcode = '<a href="';
        if (this.new_windows[this.ctr]==1) {
            linkcode += 'javascript:openpage(\'' + 
                this.actions[this.ctr] + '\')';
        } else {
            linkcode += this.actions[this.ctr];
        }
        linkcode += '">' + code + '</a>';
    }
    this.div.innerHTML = linkcode;
    this.timer=setTimeout("CarruselImagenes.col["+this.index+"].rotar()",
        CarruselImagenes.timeout);
};

