///////////////////////////////////////////////////////////////////////////
//University of Illinois Extension                                       //
//Office of Web Development                                              //
//Alessandro Bellina - bellina@uiuc.edu                                  //
//Copyright 2006 - Board of Trustees                                     //
//                                                                       //
//This code is not open source, and is protected by copyright law.       //
//Any use other than in U of I Extension websites is strictly prohibited.//
///////////////////////////////////////////////////////////////////////////
function Slideshow (container){
	var loc = new String (document.location);
	var serverString = "http://web.extension.uiuc.edu";
	
	if (loc.indexOf ("http://") == -1){
		var serverString = "https://webs.extension.uiuc.edu";
	}
										
	this.container = container;
	this.container.style.position = "relative";
	this.container.style.width = "300px";
	this.container.style.textAlign = "center";

	this.current = 0;	
	this.pics = new Array();
	this.desc = new Array();
	this.current = null;
	this.backbtn = document.createElement ("span");
	this.backbtn.style.cursor = "pointer";
	
	this.nextbtn = document.createElement ("span");
	this.nextbtn.style.cursor = "pointer";

	this.photoCount = document.createElement ("span");
	this.photoCount.style.padding = "5px";
	this.photoCount.style.position = "absolute";
	this.photoCount.style.left = "10px";
	this.photoCount.style.fontWeight = "bold";
	this.photoCount.style.color = "#666666";
	
	this.photoCount.style.paddingBottom="3px";
	this.photoCount.style.fontSize = "90%";
	this.photoCount.style.float = "left";
		
	this.navigation = document.createElement ("div");
	this.navigation.appendChild (this.photoCount);
	this.navigation.appendChild (this.backbtn);
	this.navigation.appendChild (this.nextbtn);
	this.navigation.style.textAlign = "right";
	this.navigation.style.width = "100%";
	
	this.pictureDisplay = document.createElement ("img");
	this.pictureDisplay.style.border="2px solid #000000";
	this.pictureDisplay.style.margin = "10px";
	this.pictureText = document.createElement ("div");
	this.pictureText.style.margin = "10px";
	this.pictureText.style.fontSize = "90%";
	this.pictureText.style.fontWeight = "bold";
	this.pictureText.style.fontFamily = "Verdana, Arial";
	
	this.backbtnShaded = document.createElement ("span");
	this.backbtnShaded.innerHTML = "<img src='"+serverString+"/pubs/images/back_shaded.gif' border='0'/>";
	this.backbtn.appendChild (this.backbtnShaded);
	
	this.backbtnLink = document.createElement ("a");
	this.backbtnLink.innerHTML = "<img src='"+serverString+"/pubs/images/back.gif' alt='Click to go back' border='0'/>";
	Event.bind (this.backbtnLink, "click", this, function (){
		this.ShowBack();
	});
	
	this.nextbtnShaded = document.createElement ("span");
	this.nextbtnShaded.innerHTML = "<img src='"+serverString+"/pubs/images/next_shaded.gif' border='0'/>";
	
	this.nextbtnLink = document.createElement ("a");
	this.nextbtnLink.innerHTML = "<img src='"+serverString+"/pubs/images/next.gif' alt='Click to go next' border='0'/>";
	this.nextbtn.appendChild (this.nextbtnLink);
	Event.bind (this.nextbtnLink, "click", this, function (){
		this.ShowNext();
	});
}
Slideshow.prototype.printBug = function (){
	this.container.innerHTML = "";

	if (this.pics.length > 1){
		this.container.appendChild (this.navigation);
	}
	this.container.appendChild (this.pictureDisplay);

	this.container.appendChild (this.pictureText);

	this.current = 0;
	this.ShowPicture();
}
Slideshow.prototype.ShowPicture = function (){
	this.photoCount.innerHTML = (this.current+1)+" of "+this.pics.length;
	
	if (this.current == 0){
		this.backbtn.removeChild (this.backbtn.firstChild);
		this.backbtn.appendChild (this.backbtnShaded);
	}else{
		this.backbtn.removeChild (this.backbtn.firstChild);
		this.backbtn.appendChild (this.backbtnLink);
	}
	
	if (this.current == this.pics.length-1){
		this.nextbtn.removeChild (this.nextbtn.firstChild);
		this.nextbtn.appendChild (this.nextbtnShaded);
	}else{
		this.nextbtn.removeChild (this.nextbtn.firstChild);
		this.nextbtn.appendChild (this.nextbtnLink);
	}

	this.pictureDisplay.src = this.pics[this.current];
	this.pictureText.innerHTML =  unescape (this.desc[this.current]);
	
}
Slideshow.prototype.ShowBack = function (){
	this.current --;
	if (this.current <0)
		this.current = this.pics.length-1;
	
	this.ShowPicture ();
}
Slideshow.prototype.ShowNext = function (){
	this.current ++;
	if (this.current >= this.pics.length)
		this.current = 0;
	
	this.ShowPicture ();
}
Slideshow.prototype.appendPhoto = function (description,path){
	this.pics[this.pics.length] = path;
	this.desc[this.desc.length] = description;
}