var slideshowCacheobj;
var slideshowFadeArray = new Array(); //array to cache slideshow instances
var slideshowFadeClear = new Array(); //array to cache corresponding clearinterval pointers

function slideshow(images, width, height, delay, pause, className)
{
    this.pausecheck = pause;
    this.mouseovercheck = false;
    this.delay = 2000;
    this.imageindex = 0;
    slideshowFadeArray[slideshowFadeArray.length] = this;
    this.slideshowid = slideshowFadeArray.length-1;
    this.canvasbase = 'canvas'+this.slideshowid+'_';
    this.curcanvasnr = 0;
    this.images = images;
    this.height = height;
    this.width = width;
    if (!className) {
        className = 'slideshowjs';
    }
    s = '<div id="master'+this.slideshowid+'" style="position:relative; width:'+this.width+'px; height:'+this.height+'px;">';
        s += '<div class="'+className+'" id="'+this.canvasbase+'0" style="position:absolute; float:left; margin: 0px; padding: 0px; zoom:1; width:'+this.width+'px;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;"></div>';
        s += '<div class="'+className+'" id="'+this.canvasbase+'1" style="position:absolute; float:left; margin: 0px; padding: 0px; zoom:1; width:'+this.width+'px;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;"></div>';
    s += '</div>';
    document.write(s);
    if (this.pausecheck) {
        slideshowCacheobj = this;
        obj = document.getElementById('master'+this.slideshowid);
        obj.onmouseover = function() { slideshowCacheobj.mouseovercheck = true; }
        obj.onmouseout = function() { slideshowCacheobj.mouseovercheck = false; }
    }
    this.rotateimage();
} //function slideshow

function slideshowFadePic(obj)
{
    if (obj.degree<100) {
        obj.degree += 5;
        obj.setOpacity(obj.curobj, obj.degree);
        obj.setOpacity(obj.nextobj, 101-obj.degree);
    } else {
        clearInterval(slideshowFadeClear[obj.slideshowid]);
        setTimeout('slideshowFadeArray['+obj.slideshowid+'].rotateimage()', obj.delay);
    }
} //function slideshowFadePic

slideshow.prototype.setOpacity = function(obj, degree)
{
    if (obj.filters && obj.filters[0]){
        if (typeof obj.filters[0].opacity=='number') { //if IE6+
            obj.filters[0].opacity = degree;
        } else {//else if IE5.5-
            obj.style.filter = 'alpha(opacity='+degree+')';
        }
    } else if (obj.style.MozOpacity) {
        obj.style.MozOpacity = degree/101;
    } else if (obj.style.KhtmlOpacity) {
        obj.style.KhtmlOpacity = degree/100;
    } else if (obj.style.opacity && !obj.filters) {
        obj.style.opacity = degree/101;
    }
} //function slideshow.prototype.setOpacity

slideshow.prototype.rotateimage = function()
{
    if (this.mouseovercheck) {
        slideshowCacheobj = this;
        setTimeout('slideshowCacheobj.rotateimage()', 100);
    } else {
        obj = document.getElementById(this.canvasbase+this.curcanvasnr);
        this.curobj = obj;
        this.nextobj = document.getElementById(this.canvasbase+(1-this.curcanvasnr));
        image = this.images[this.imageindex];
        s = '<img src="'+image[0]+'" height="'+this.height+'" width="'+this.width+'"  hspace="0" vspace="0" style="margin:0px"/>'; //margin 0 is necessairy!
        if (image[1]!='') {
            s += '<p style="width: '+(this.width-2)+'px">'+cm_html(image[1])+'</p>'; //for some reason the normal width goes wrong sometimes in IE
        }
        obj.innerHTML = s;
        this.imageindex = (this.imageindex<this.images.length-1?this.imageindex+1:0);
        this.degree = 10;
        this.setOpacity(obj, 10);
        ++obj.style.zIndex;
        slideshowFadeClear[this.slideshowid] = setInterval('slideshowFadePic(slideshowFadeArray['+this.slideshowid+'])', 50);
        this.curcanvasnr = 1-this.curcanvasnr;
    }
} //function slideshow.prototype.rotateimage
