//Slideshow of images
//NOTE: you add as many images and text areas as you want
//set up using :
// obj = new slideShow  //at the TOP of the page
// then, UNDER the elements involved
// obj.setImgElement(document.getElementById(IMG tag id));
// obj.setTextElements([document.getElementById('Text div id'),document.getElementById('2nd Text div id'),document.getElementById('3rd Text div id 3')]);
// obj.setNextGlyph(document.getElementById('nextbutton'),"/asset_arena/website-furniture/ffwd.png","/stylesheets/grey.png");
// obj.setPrevGlyph(document.getElementById('prevbutton'),"/asset_arena/website-furniture/rwnd.png","pb");
// obj.addImage("first image path",["area 1 text ","a2 text ","a3 text"]);
// obj.addImage("second image path",["a1 text","a2 text","a3 text"]);
// obj.addImage("third image path",["a1 text","a2 text","a3 text"]);
//
//eg:
//<body>
//<script type="text/javascript">
//     var main = new slideShow();
//</script>
//<img id="theimage" src=""/>
//<div id="text1">1</div>
//<div id="text2">2</div>
//<div id="text3">3</div>
//<a href="javascript:main.prev();"><img id="prevbutton" border="0" src="/asset_arena/website-furniture/shim.gif"/></a>
//<a href="javascript:main.next();"><img id="nextbutton" border="0" src="/asset_arena/website-furniture/shim.gif"/></a>
//<a href="javascript:main.start();">Start</a>
//<a href="javascript:alert(main.diagnostic());">Diagnostics</a>
//<script type="text/javascript">
//     main.setImgElement(document.getElementById('theimage'));
//     main.setTextElements([document.getElementById('text1'),document.getElementById('text2'),document.getElementById('text3')]);
//     main.setNextGlyph(document.getElementById('nextbutton'),"/asset_arena/website-furniture/ffwd.png","/asset_arena/website-furniture/shim.gif");
//     main.setPrevGlyph(document.getElementById('prevbutton'),"/asset_arena/website-furniture/rwnd.png","/asset_arena/website-furniture/shim.gif");
//     main.addImage("/asset_arena/image/ow/show.jpg",["a1","a2","a3"]);
//     main.addImage("/asset_arena/image/l2/tell2.jpg",["b1","b2","b3"]);
//     main.addImage("/asset_arena/image/n3/explain3.jpg",["c1","c2","c3"]);
//   </script>   
//
//</body>
 
function slideShow()
{
        //textElements [ ["","",.......], ["",""], ["",""]]	
	this.textElements = new Array();
	this.imgs = new Array();
	this.countElement=null;
	this.imgDomId = null;
	this.textDomIds = null; //new Array();

	this.currentIndex = -1;
	this.maxIndex = -1;
	this.nextGlyph = [null,"",""];
	this.prevGlyph = [null,"",""];

	this.changeFunc = null;
	
	this.kioskMode = false;
	
}	

slideShow.prototype.setChangeFunc = function(func) {

	this.changeFunc = func;

}


slideShow.prototype.setImgElement = function(img){
	this.imgDomId = img;
};

slideShow.prototype.setCountElement = function(ele){
	this.countElement = ele;
};

slideShow.prototype.setTextElements = function(dom_array){
	this.textDomIds = dom_array;
};

slideShow.prototype.addImage = function(src,listoftext){
	this.imgs.push(src);
	this.textElements.push(listoftext);
	this.maxIndex = this.maxIndex + 1;
};

slideShow.prototype.setNextGlyph = function(domid,src,srcblank) {
	this.nextGlyph = [domid,src,srcblank];
};

slideShow.prototype.setPrevGlyph = function(domid,src,srcblank) {
	this.prevGlyph = [domid,src,srcblank];
};

slideShow.prototype.next = function() {
	if(this.currentIndex < this.maxIndex) {
		this.currentIndex++;
		this.switchGlyphs();
		this.imgDomId.src = this.imgs[this.currentIndex];
		//dont do this step in kiosks
		
		if(!this.kioskMode) this.imgDomId.alt = this.textElements[this.currentIndex][0];
		this.countElement.innerHTML = (this.currentIndex+1) + " of " + (this.maxIndex+1);

		//TEXT
		var n;
		for(n=0; n<this.textDomIds.length; n++){			
			this.textDomIds[n].innerHTML = this.textElements[this.currentIndex][n];
		} 
		
	}else { this.switchGlyphs(); }	
};

slideShow.prototype.prev = function() {
	if(this.currentIndex > 0) {
	   this.currentIndex--;
	   //change control glyphs
	   this.switchGlyphs();
	   this.imgDomId.src = this.imgs[this.currentIndex];	   
	   if(!this.kioskMode) this.imgDomId.alt = this.textElements[this.currentIndex][0];
	   this.countElement.innerHTML = (this.currentIndex+1) + " of " + (this.maxIndex+1);
	   //TEXT
	   var n;
	   for(n=0; n<this.textDomIds.length; n++){			
		this.textDomIds[n].innerHTML = this.textElements[this.currentIndex][n];
	   } 
	} else {
	    this.switchGlyphs();
	}

	
};

slideShow.prototype.switchGlyphs = function () {
	//what to do in the case of maxIndex = 0; ? One image
	//show controls at all?
	//if(maxIndex==0)return true;
	if(this.changeFunc != null) this.changeFunc();
	if(this.currentIndex == this.maxIndex) {
		this.nextGlyph[0].src = this.nextGlyph[2];
	}
	else {
		this.nextGlyph[0].src = this.nextGlyph[1];		
	}
	
	if(this.currentIndex > 0) {
		this.prevGlyph[0].src = this.prevGlyph[1];
	}else{
	 	this.prevGlyph[0].src = this.prevGlyph[2];
	}
	if(this.changeFunc != null) this.changeFunc();
};

slideShow.prototype.start = function()
{
	if(this.maxIndex > -1) {
		this.currentIndex = -1;	
		this.next();
		this.imgDomId.src = this.imgs[this.currentIndex];
		this.switchGlyphs();	
	} 
	    
};

slideShow.prototype.diagnostic = function() 
{
  var str = "";
  str = str + "Current Index:"+this.currentIndex+"\n";
  str = str + "MAX Index:"+this.maxIndex+"\n";
  return str;	
}
