/*
Holland Cash slideshows base classes
version : 1
data : 10-04-2008
author : Tim Breedveld
description : Base classes for slide show and timer management
hc_slideshow constructor paremeters:
new hc_slideshow(type, width, height, source, interval, [animationSpeed, margin, element_width, element_height, pause])
types :
1 = from top to bottom
2 = from bottom to top
3 = from left to right
4 = from right to left
5 = 1 element fade in, fade out
source :
2D array starting with index 0
Example:
var source=new Array();
source[0] = ['images/thumbnail_1.jpg', 'http://www.google.com']
source[1] = ['images/thumbnail_2.jpg', 'http://www.nu.nl'];
interval :
In ms (2000 = 2sec)
animationSpeed :
In ms, the smaller the faster
optional, uses default speed when not supplied
margin :
Space between images, optional argument
element_width, element_height :
The width and height of the inner images.
- Optional parameters, if not supplied, width height will be used instead
pause :
boolean, pause on mouseover (true/false);
default = false
*/
/*
Instantiate register class (singleton)
- This way multiple imports are possible
*/
if (hc_slideshow_register_singleton == null)
{
var hc_slideshow_register_singleton = new hc_slideshow_register();
}
/*
Register class for all slideshow instances
- General timer management
- Access management
*/
function hc_slideshow_register()
{
this.listeners = new Object();
this.counter = 0;
//Access to slideshows
this.callfunction = function(callstatus, id)
{
var object = this.listeners[id];
if(callstatus == "pause")
this.listeners[id].pause = true;
if(callstatus == "unpause")
this.listeners[id].pause = false;
}
//Register a slideshow Object and return a unique id
//That can be used in the slideshows for the creation of unique
//elements (is required for getElementById)
this.registerObject = function(slideshow)
{
this.counter++;
this.listeners[this.counter] = slideshow;
return this.counter;
}
//Update and notify all timers
this.notify = function()
{
for(obj_index in this.listeners)
{
var object = this.listeners[obj_index];
object.notify();
}
setTimeout('hc_slideshow_register_singleton.notify()',10);
}
//Start timer
this.notify();
}
/*
Base Class for all slideshows
*/
function hc_slideshow(type, width, height, src, interval, animationSpeed, margin, img_w, img_h, pause)
{
//process arguments
this.width = width;
this.height = height;
this.source = src;
this.interval = interval;
//Check optional arguments
if(animationSpeed != null) this.animationSpeed = animationSpeed;
else this.animationSpeed = 10;
if(margin != null) this.margin = margin;
else this.margin = 0;
if(img_w != null) this.img_width = img_w;
else this.img_width = width;
if(img_h != null) this.img_height = img_h;
else this.img_height = height;
if(pause != null) this.pause = pause;
else this.pause = false;
//Inititalize
this.sourceCounter = 0;
this.id = hc_slideshow_register_singleton.registerObject(this);
this.waiting = false;
this.animationDelta = 1;
this.intervalTimer = this.interval;
this.animationTimer = this.animationSpeed;
//Create the code
this.create_slideShow = function()
{
//special code for the pause on mouseover function
var pauseHTML = '';
if(this.pause)
{
pauseHTML = 'onmouseout="hc_slideshow_register_singleton.callfunction(\'unpause\','+this.id+');" onmouseover="hc_slideshow_register_singleton.callfunction(\'pause\','+this.id+');"';
this.pause = false;
}
document.write('
');
this.ss.create_InnerContent();
document.write('
');
}
//Interval for changing images
this.intervalCall = function()
{
this.ss.interval();
}
//Animation interval
this.animationCall = function()
{
this.ss.animate();
}
//Timer notifier
this.notify = function()
{
if(this.pause)
return true;
if(! this.waiting)
this.animationTimer -= 10;
if((this.animationTimer <= 0) && (! this.waiting))
{
this.animationCall();
this.animationTimer = this.animationSpeed;
}
if ((this.interval > 0) && (this.waiting))
{
this.intervalTimer -= 10;
if(this.intervalTimer <= 0)
{
this.intervalCall();
this.intervalTimer = this.interval;
}
}
else if ((this.interval <= 0) && (this.waiting))
this.intervalCall();
}
//Called when slideshow is in position
this.wait = function()
{
this.waiting = true;
}
//Returns the next image
//Loop through the source array
this.nextElement = function()
{
this.sourceCounter++;
if(this.sourceCounter >= this.source.length)
this.sourceCounter = 0;
return (this.source[this.sourceCounter]);
}
//Extend the proper slideshow
if (type==1)
this.ss = new hc_slideshow_top_bottom(this);
else if (type==2)
this.ss = new hc_slideshow_bottom_top(this);
else if (type==3)
this.ss = new hc_slideshow_left_right(this);
else if (type==4)
this.ss = new hc_slideshow_right_left(this);
else if (type==5)
this.ss = new hc_slideshow_1_opacity(this);
else
window.alert('unknown type.' + type);
//Output
this.create_slideShow();
}
/*
Holland Cash slideshows Helper class
version : 1
data : 10-04-2008
author : Tim Breedveld
description : Simple support functions for holland cash Slideshows
*/
//Get left property (in Int) for an element
function hc_ss_getLeft(id)
{
var e = document.getElementById(id);
if(e == null)
window.alert('no id: ' + id);
var left = e.style.left;
return parseInt(left.substr(0,left.length - 2));
}
//Set left property (in Int) for an element
function hc_ss_setLeft(id, left)
{
var e = document.getElementById(id);
e.style.left = left + 'px';
}
//Set top property (in Int) for an element
function hc_ss_setTop(id, top)
{
var e = document.getElementById(id);
e.style.top = top + 'px';
}
//Get top property (in Int) for an element
function hc_ss_getTop(id)
{
var e = document.getElementById(id);
var top = e.style.top;
return parseInt(top.substr(0,top.length - 2));
}
//Set height property (in Int) for an element
function hc_ss_setHeight(id, height)
{
var e = document.getElementById(id);
e.style.height = height + 'px';
}
//Get height property (in Int) for an element
function hc_ss_getHeight(id)
{
var e = document.getElementById(id);
var height = e.style.height;
return parseInt(height.substr(0,height.length - 2));
}
//Set transparancy property (in Int) for an element
function hc_ss_setOpacity(id, opacity)
{
var e = document.getElementById(id);
if (navigator.appName.indexOf("Netscape")!=-1
&&parseInt(navigator.appVersion)>=5)
e.style.MozOpacity=opacity/100;
else if (navigator.appName.indexOf("Microsoft")!= -1
&&parseInt(navigator.appVersion)>=4)
e.filters.alpha.opacity=opacity;
}
//Set Z-index style property (in Int) for an element
function hc_ss_setZindex(id, the_zindex)
{
var e = document.getElementById(id);
e.style.zIndex = the_zindex;
}/*
Holland Cash mulitple elements sliding slideshows
version : 2
data : 17-09-2008
author : Tim Breedveld
description : mulitple elements sliding slideshows
*/
/*
==================================
SLIDESHOW TOP -> BOTTOM
==================================
*/
function hc_slideshow_top_bottom(parent)
{
//All images on the screen
this.imageRail = new Array();
//Total images
this.totalImages = parseInt(parent.height / (parent.img_height + parent.margin)) + 3;
//Image counters
this.firstImage = 0;
this.lastImage = this.totalImages - 1;
//center line
this.centerLine = parseInt(parent.height / 2) - parseInt(parent.img_height / 2);
//Create the content for the slideshow
this.create_InnerContent = function()
{
var top = parent.height - (parent.img_height + parent.margin);
for (i=0; i');
document.write(parent.nextElement());
document.write('');
this.imageRail[i] = divId;
top = top - (parent.img_height + parent.margin);
}
}
//Continue after pause
this.interval = function()
{
parent.waiting = false;
}
//Animation
this.animate = function()
{
//move last image to front
if(hc_ss_getTop(this.imageRail[this.firstImage]) >= parent.height)
{
f_divId = this.imageRail[this.firstImage];
l_divId = this.imageRail[this.lastImage];
//Load new image
document.getElementById(f_divId).innerHTML = parent.nextElement();
//Place in back
hc_ss_setTop(f_divId ,(hc_ss_getLeft(l_divId) - (parent.margin + parent.img_height)));
//Change counters
this.lastImage = this.firstImage;
this.firstImage += 1;
if(this.firstImage > (this.totalImages - 1))
this.firstImage = 0
}
//Slide other images
for(i=0; i TOP
==================================
*/
function hc_slideshow_bottom_top(parent)
{
//All images on the screen
this.imageRail = new Array();
//Total images
this.totalImages = parseInt(parent.height / (parent.img_height + parent.margin)) + 3;
//Image counters
this.firstImage = 0;
this.lastImage = this.totalImages - 1;
//center line
this.centerLine = parseInt(parent.height / 2) - parseInt(parent.img_height / 2);
//Create the content for the slideshow
this.create_InnerContent = function()
{
var top = 0;
for (i=0; i');
document.write(parent.nextElement());
document.write('');
this.imageRail[i] = divId;
top = top + (parent.img_height + parent.margin);
}
}
//Continue after pause
this.interval = function()
{
parent.waiting = false;
}
//Animation
this.animate = function()
{
//move last image to front
if(hc_ss_getTop(this.imageRail[this.lastImage]) <= (parent.height - parent.img_height))
{
divId = this.imageRail[this.firstImage];
//Load new image
document.getElementById(divId).innerHTML = parent.nextElement();
//Place in front
hc_ss_setTop(divId ,(parent.height + parent.margin));
//Change counters
this.lastImage = this.firstImage;
this.firstImage += 1;
if(this.firstImage >= this.totalImages )
this.firstImage = 0;
}
//Slide other images
for(i=0; i RIGHT
==================================
*/
function hc_slideshow_left_right(parent)
{
//All images on the screen
this.imageRail = new Array();
//Total images
this.totalImages = parseInt(parent.width / (parent.img_width + parent.margin)) + 3;
//Image counters
this.firstImage = 0;
this.lastImage = this.totalImages - 1;
//center line
this.centerLine = parseInt(parent.width / 2) - parseInt(parent.img_width / 2);
//Create the content for the slideshow
this.create_InnerContent = function()
{
var left = parent.width - (parent.img_width + parent.margin);
for (i=0; i');
document.write(parent.nextElement());
document.write('');
this.imageRail[i] = divId;
left =left - (parent.img_width + parent.margin);
}
}
//Continue after pause
this.interval = function()
{
parent.waiting = false;
}
//Animation
this.animate = function()
{
//move last image to front
if(hc_ss_getLeft(this.imageRail[this.firstImage]) >= parent.width)
{
f_divId = this.imageRail[this.firstImage];
l_divId = this.imageRail[this.lastImage];
//Load new image
document.getElementById(f_divId).innerHTML = parent.nextElement();
//Place in back
hc_ss_setLeft(f_divId, (hc_ss_getLeft(l_divId) - (parent.margin + parent.img_width)))
//Change counters
this.lastImage = this.firstImage;
this.firstImage += 1;
if(this.firstImage > (this.totalImages - 1))
this.firstImage = 0;
}
//Slide other images
for(i=0; i');
document.write(parent.nextElement());
document.write('');
this.imageRail[i] = divId;
left = left + (parent.img_width + parent.margin);
}
}
//Continue after pause
this.interval = function()
{
parent.waiting = false;
}
//Animation
this.animate = function()
{
//move last image to front
if(hc_ss_getLeft(this.imageRail[this.lastImage]) <= (parent.width - parent.img_width))
{
divId = this.imageRail[this.firstImage];
//Load new image
document.getElementById(divId).innerHTML = parent.nextElement();
//Place in front
hc_ss_setLeft(divId ,(parent.width + parent.margin));
//Change counters
this.lastImage = this.firstImage;
this.firstImage += 1;
if(this.firstImage >= this.totalImages )
this.firstImage = 0;
}
//Slide other images
for(i=0; i');
document.write(parent.nextElement());
document.write('');
document.write('');
document.write(parent.nextElement());
document.write('
');
hc_ss_setOpacity(this.showId, 0);
hc_ss_setOpacity(this.hideId, 100);
}
//Image interval
//Swap image
this.interval = function()
{
//Swap image for hidden field
var e = document.getElementById(this.hideId);
e.innerHTML = parent.nextElement();
//Swap hidden / show field id's
var oldShowId = this.showId;
this.showId = this.hideId;
this.hideId = oldShowId;
this.show_opacity = 0;
this.hide_opacity = 100;
parent.waiting = false;
}
//Animation
this.animate = function()
{
if(this.show_opacity < 100)
{
this.show_opacity++;
this.hide_opacity--;
if(this.show_opacity > 100) this.show_opacity = 100;
if(this.hide_opacity < 0) this.hide_opacity = 0;
hc_ss_setOpacity(this.showId, this.show_opacity);
hc_ss_setOpacity(this.hideId, this.hide_opacity);
if( this.show_opacity > 99 )
{
hc_ss_setZindex(this.showId, 1002);
hc_ss_setZindex(this.hideId, 1001);
}
}
else
parent.wait();
}
}document.write("
");