
bbcjs.trace('<b><font color="green">jst_img.js</font> was included.</b>',2);
bbcjs.images = new Object();
bbcjs.images.prototype = new bbcjs.Module("images", 1, "$Revision: 1.14 $", "$Date: 2005/08/18 15:38:51 $");
bbcjs.images.rolls = new Array();
bbcjs.images.imgs = new Array();
bbcjs.images.preload = function (files, path)
{
bbcjs.trace("preloading images...",3);
var imgs = [];
if (typeof(path) == "undefined") path = "";
for (var i in files)
{
bbcjs.trace("preloadimg: "+files[i],5);
imgs[i] = new Image();
imgs[i].src = path + files[i];
}
bbcjs.images.imgs.concat(imgs);
return imgs;
};
bbcjs.images.imgSwap = function ()
{
var id = this.id ? this.id : this.name;
var t = bbcjs.images.rolls[id];
bbcjs.trace("Swapping image <b>"+id+"</b> from '"+this.src.split("/")[this.src.split("/").length-1]+"' to '"+t.split("/")[t.split("/").length-1]+"'.",4);
bbcjs.images.rolls[id] = this.src;
this.src = t;
};
bbcjs.images.rollInit = function ()
{
var img;
for (var i in bbcjs.images.rolls)
{
if (document.images[i]) img = document.images[i];
else if ((bbcjs.dhtml) && document.getElementById(i)) img = document.getElementById(i);
else bbcjs.trace("Warning - could not find image '"+i+"' in the DOM",2);
if (img)
{
img.onmouseover = bbcjs.images.imgSwap;
img.onmouseout = bbcjs.images.imgSwap;
}
}
};
bbcjs.images.rollPrep = function ()
{
bbcjs.images.preload(bbcjs.images.rolls);
bbcjs.addOnLoadItem("bbcjs.images.rollInit();");
};
bbcjs.images.Slideshow = function (files)
{
bbcjs.trace('new bbcjs.images.Slideshow()');
this.files = files;
this.path = '';
this.target_name = 'slideshow';
this.target = null;
this.speed = 4000;
this.loop = true;
this.autoplay = true;
this.filter = 'blendtrans(duration=1.5)';
this.supportsFilters = typeof(new Image().filters) != 'undefined' ? true : false;
this.images= null;
this.current = null;
this.loop_ended = false;
this.interval = null;
this.id = bbcjs.images.Slideshow.instances.length;
bbcjs.images.Slideshow.instances[bbcjs.images.Slideshow.instances.length] = this;
};
bbcjs.images.Slideshow.instances = new Array();
bbcjs.images.Slideshow.prototype.init = function ()
{
bbcjs.trace('bbcjs.images.Slideshow.init()');
if (bbcjs.documentLoaded) this._init();
else bbcjs.addOnLoadItem("bbcjs.images.Slideshow.instances[" + this.id + "]._init()");
};
bbcjs.images.Slideshow.prototype._init = function ()
{
bbcjs.trace('bbcjs.images.Slideshow._init()', 5);
this.target = document.images[this.target_name];
this.images = bbcjs.images.preload(this.files, this.path);
this.current = 0;
if (this.autoplay) this.play();
};
bbcjs.images.Slideshow.prototype.play = function (speed)
{
bbcjs.trace('bbcjs.images.Slideshow.play()');
var s = speed || this.speed;
if (this.interval) clearInterval(this.interval);
this.interval = setInterval("bbcjs.images.Slideshow.instances["+this.id+"].increment()" , s);
};
bbcjs.images.Slideshow.prototype.reverse = function (speed)
{
bbcjs.trace('bbcjs.images.Slideshow.reverse()');
var s = speed || this.speed;
if (this.interval) clearInterval(this.interval);
this.interval = setInterval("bbcjs.images.Slideshow.instances["+this.id+"].decrement()" , s);
};
bbcjs.images.Slideshow.prototype.stop = function()
{
bbcjs.trace('bbcjs.images.Slideshow.stop()');
if (this.interval) clearInterval(this.interval);
this.interval = null;
};
bbcjs.images.Slideshow.prototype.increment = function ()
{
bbcjs.trace("bbcjs.images.Slideshow.increment()", 5);
var next = this.current;
next ++;
next = next % this.images.length;
if (this.images && this.images[next].complete)
{
this.current = next;
this.loop_ended = (this.current == this.images.length -1)? true : false;
this.show(this.current);
if (this.loop_ended && !this.loop) this.stop();
}
return this.current;
};
bbcjs.images.Slideshow.prototype.decrement = function ()
{
bbcjs.trace("bbcjs.images.Slideshow.decrement()", 5);
var next = this.current;
next --;
next = (next > -1)? next : this.images.length - 1;
if (this.images && this.images[next].complete)
{
this.current = next;
this.loop_ended = (this.current === 0)? true : false;
this.show(this.current);
if (this.loop_ended && ! this.loop) this.stop();
}
};
bbcjs.images.Slideshow.prototype.show = function (img)
{
bbcjs.trace("bbcjs.images.Slideshow.show(" + img + ")", 4);
if (this.images[img])
{
if (this.supportsFilters && this.filter)
{
this.target.style.filter = this.filter;
this.target.filters.item(0).apply();
this.target.filters.item(0).play();
}
this.target.src = this.images[img].src;
if (this.onImageChange)
{
bbcjs.trace("bbcjs.images.Slideshow.onImageChange()",5);
this.onImageChange();
}
if (this.loop_ended && !this.loop && this.onEnd)
{
bbcjs.trace("bbcjs.images.Slideshow.onEnd()",5);
setTimeout("bbcjs.images.Slideshow.instances["+this.id+"].onEnd()", this.speed);
}
return true;
}
else return false;
};
