function returnObjById( id )
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function drop(id, container) {
    node=returnObjById(id);
	node.style.display='block';
}

function shrink(id) {
    node=returnObjById(id);
	node.style.display='none';
}

var so = {clock : null};
function slideshow(id, images, delay, fade, times) {
	// fade the images passed via the images array into each other
	// preload images
	so.cache=new Array;
	for (var i=0; i<images.length; i++) {
	  so.cache[i]=new Image;
	  so.cache[i].src=images[i];
	}
	
	node=returnObjById(id);
	//node.style.float="none";
	node.style.opacity=1;
	node.style.filter="alpha(opacity=100)";
	node.src=images[0];
	
	if (arguments.length < 2) {
		alert ("Error - wrong number of arguments passed");
		return;
	} else if (arguments.length == 2) {
	// set defaults
		delay=5;
		fade=1;
		times=5;
	} else if (arguments.length == 3) {
		fade=1;
		times=5;
	} else if (arguments.length == 4) {
		times=5;
	}
	
	so.node=node;
	so.images=images;
	so.delay=delay;
	so.fade=fade;
	so.times=times;
	so.reps=(20*(delay+fade))*images.length*times;
	so.decr=100/(10*fade);
	so.cnt=1;
	so.opaq=100;
	// set timer to run the slideshow times times
	if (so.clock == null) {
		so.clock = window.setInterval("runShow()",50);
	}
}

function runShow() {
// check - is show up?
	if (so.cnt > so.reps) {
		window.clearInterval(so.clock);
		so.clock=null;
		so.node.opacity=1;
		so.node.style.filter="alpha(opacity=100)";
		return;
	}
// are we fading or holding?
	var onerep=so.reps/(so.times * so.images.length);
	var time=so.cnt % onerep;
	if (time >= (20*so.delay)) {
		so.cnt2 = (time % (20*so.delay)) +1;
		swapImg();
	}
	so.cnt++;
}

function swapImg() {
// time to switch images?
	if (so.cnt2 == (10*so.fade)) {
		var fullrep=so.reps/so.times;
		var time=so.cnt % fullrep;
		var onerep=so.reps/(so.times * so.images.length);
		var ctr=Math.ceil(time/onerep);
		var idx=(ctr % so.images.length);
		so.node.src=so.images[idx];
	}
	
// fade out or in	
	if (so.cnt2 <= (10*so.fade)) {
		so.opaq -= so.decr;
	} else {
		so.opaq += so.decr;
	}
	// keep under 1 to avoid popping effect in netscape, older firefox
	so.node.style.opacity=(so.opaq/100 == 1 ? 0.9999 : so.opaq/100);
	so.node.style.filter="alpha(opacity=" + so.opaq +")";
	
	so.cnt2++;
}
