SlideShow.prototype.imgUrl = function(id) {
    return "/public/ss/"+this.imgs[id%this.imgs.length]
}
SlideShow.prototype.loadNext = function() {
    this.cache.src =  this.imgUrl(this.idx+1);
    this.timer = setTimeout("ss.showNext()", this.interval);
    this.waiting = true;
}
SlideShow.prototype.cacheComplete = function() {
    if (!this.cache.complete) {
        return false;
    }
    if (typeof this.cache.naturalWidth != "undefined" && this.cache.naturalWidth == 0) {
        return false;
    }
    return true;
}
SlideShow.prototype.showNext = function() {

    if (!this.cacheComplete()) {
        this.timer = setTimeout("ss.showNext()",1000);
        return;
    }
    this.waiting = false;
    this.idx++;
    if (this.idx%2==0) {
        this.top.src = this.imgUrl(this.idx);
    } else {
        this.bottom.style.backgroundImage = "url('"+this.imgUrl(this.idx)+"')";
    }
    this.adjustControl();
    this.transition(0);
}
SlideShow.prototype.adjustControl = function() {
    for (var i=0;i<this.imgs.length;++i) {
        var led = document.getElementById("ss"+i);
        document.getElementById("ss"+i).src = "/public/ss/"+((i==(this.idx%this.imgs.length))?"on.png":"off.png");
    }
}
SlideShow.prototype.transition = function(stage) {
    if (stage++<40) {
        var percent = stage/40;
        if (this.idx%2==1) {
            percent = 1 - percent;
        }
        this.top.style.filter = 'alpha(opacity='+(percent*100)+')';
        this.top.style.opacity = percent;
        this.timer = setTimeout("ss.transition("+stage+")",1);
    } else {
        ss.loadNext();
    }
}
SlideShow.prototype.sel = function(id) {
    clearTimeout(this.timer);
    this.idx = id;
    this.top.src = this.imgUrl(id);
    this.top.style.filter = 'alpha(opacity=100)';
    this.top.style.opacity = 1;
    this.manual = true;
    this.waiting = false;
    this.adjustControl();
}
SlideShow.prototype.userNext = function(id) {
    if (this.manual) {
        this.sel(this.idx+1);
    } else if (this.waiting) {
        clearTimeout(this.timer);
        this.showNext();
    }
}
function SlideShow(imgs, interval, w, h) {
    this.top = document.getElementById("ss_img");
    this.bottom = this.top.parentNode;
    this.idx = 0;
    this.imgs = imgs;
    this.interval = interval;
    this.cache = new Image(w,h);
    this.manual = false;
    this.loadNext();
}

function sw_render(len) {
    var txt = "Open your free account today";
    var cursor = true; var nexttime = 25;
    var lnk_start = 10; var lnk_len = 12;
    if (len<0) {
        txt = ""; cursor = len%2; nexttime = 300;
    } else if (len>=txt.length) {
        cursor = len%2; nexttime = 300;
    } else {
        txt = txt.substr(0,len);
    }
    if (len>lnk_start) {
        var txta = txt.substring(0, lnk_start) + '<a href="/ctrl?action=newaccount">' +
          txt.substr(lnk_start, lnk_len)+'</a>';
        if (len>lnk_start+lnk_len) {
         txta += txt.substr(lnk_start+lnk_len);
        }
        txt = txta;
    }
    document.getElementById("sw_cursor").style.visibility = cursor?"visible":"hidden";
    if (len<=txt.length+1) {
        document.getElementById("sw_target").innerHTML = "> "+txt;
    }
    setTimeout('sw_render('+(len+1)+')', nexttime);
}

setTimeout("sw_render(-15)", 250);
var ss = new SlideShow(slideShowImages, 5000, 400, 300);
