
var ap_controller = function(item_num, item_obj, state)
{
	var class_name;

	if (state) {
		class_name = "active";
	} else  {
		class_name = "inactive";
	}
	$id('ap'+item_num+'_button').className = class_name;
	$id('ap'+item_num+'_message').className = class_name;
}


var $id = function (id) { return document.getElementById(id); }

function setOpacity(op, id) {
	var obj = document.getElementById(id);
	if (obj) {
		obj.style.filter = "alpha(opacity="+op+")";				// IE
		obj.style.opacity = (op/100);						// CSS-3
		obj.style.KhtmlOpacity = (op/100);					// Safari, Konqueror
	}
} 



apsClass = function(name, fadeTime, holdTime)
{
	this.interval = 50;							// interval in ms
	this.nAps;
	this.name = name;							// my name
	this.item = 0;
	this.lastItem = 0;
	this.holdTime = holdTime;						// total time to hold image from start of fade
	this.fadeTime = fadeTime;						// how much time to take to do fade
	this.goto_slide = 0;
	
	var i;
	var obj;

	for (this.nAps = 0; ; this.nAps++) {
		obj = document.getElementById('ap'+this.nAps);
		if (obj) {
			setOpacity(0, "ap"+this.nAps);
			obj.style.visibility = 'visible';
		} else {
			break;
		}
	}

	this.fade = function (id, start, end, duration) {
		var opacityInc;
		var i;
		var opacity;
		
		parts = Math.floor(duration / this.interval);			// how many slices per durations
		opacityInc = (end - start) / parts;
		
		for (i = 0, opacity = start, t=0; i < parts; i++) {
			t += this.interval;
			opacity += opacityInc;
			setTimeout("setOpacity(" + opacity + ",'" + id +"')", t);
		}
		setTimeout("setOpacity(" + end + ",'" + id +"')", t);
	}

	this.doit = function()
	{
		this.fade('ap0',0,99,this.fadeTime);				// Fade-in 1st image
		this.item++;
		setTimeout(this.name+".doitLoop()", this.holdTime);		// call forever loop
	}

	this.doitLoop = function()
	{
		clearTimeout(this.to_handle);

		$id('ap'+this.lastItem).style.zIndex = -1;
		$id('ap'+this.item).style.zIndex = 999;

		ap_controller(this.lastItem, $id('ap'+this.lastItem), 0);
		ap_controller(this.item, $id('ap'+this.item), 1);

		this.fade('ap'+this.item,0,99,this.fadeTime);			// Fade-in next item
		this.fade('ap'+this.lastItem,99,0,this.fadeTime);		// Fade-out next item

		this.lastItem = this.item;
		this.item++;						
		if (this.item >= this.nAps) {					// don't use mod (%) -- requires more cycles
			this.item = 0;						// back to the first image
		}

		this.to_handle = setTimeout(this.name+'.doitLoop()', this.holdTime);		// Do 'er again
	}
	this.goto_slide = function(n)
	{
		if (n != this.lastItem) {
			this.item = n;
			this.doitLoop();
		}
	}
}

var aps;

initAps = function()
{
	aps = new apsClass("aps",300, 5000);   // 5000 = 5 sec rotation time

	aps.doit();
}


window.onload=function(){
initAps();
}

   
var divNum = new Array("a1","a2","a3","a4","a5","a6","a7"); 
               
function openClose(theID) {
  for(var i=0; i < divNum.length; i++) {
    if (divNum[i] == theID) {
      if (document.getElementById(divNum[i]).style.display == "block") { document.getElementById(divNum[i]).style.display = "none" }
      else {
        document.getElementById(divNum[i]).style.display = "block"
      }
  } else {
    document.getElementById(divNum[i]).style.display = "none"; }
  }
}


