function slideShowClass(divID,controlsID){
	this.id = divID;
	this.slides = new slidesClass();
	this.div = document.getElementById(this.id);
	this.controls = new Object();
	this.controls.div = document.getElementById(controlsID);
};
	
slideShowClass.prototype.writeShow = function(){
	this.setCurrent();
};

slideShowClass.prototype.writeControls = function(){
	var table = document.createElement("table");
	table.border = "0";
	table.cellPadding = "0";
	table.cellSpacing = "0";

	var tbody = document.createElement("tbody");
	var row = document.createElement("tr");
	var prevCell = document.createElement("td");
	var counterCell = document.createElement("td");
	var nextCell = document.createElement("td");

	var backArrow = (navigator.userAgent.indexOf("MSIE")>=0)?"&#9668;":"&#9664;";
	var frwdArrow = (navigator.userAgent.indexOf("MSIE")>=0)?"&#9658;":"&#9654;";

	this.controls.prevBtn = document.createElement("a");
	this.controls.nextBtn = document.createElement("a");
	this.controls.counter = document.createElement("span");

	this.controls.prevBtn.onfocus = function(){this.blur(); return false;};
	this.controls.nextBtn.onfocus = function(){this.blur(); return false;};

	this.controls.prevBtn.setAttribute("href","javascript:void(0)");
	this.controls.nextBtn.setAttribute("href","javascript:void(0)");

	this.controls.div.innerHTML = "";
	
	this.controls.prevBtn.id = "prevBtn";
	this.controls.prevBtn.className = "btnLinkOff";
	this.controls.prevBtn.innerHTML = backArrow;
	this.controls.prevBtn.onclick = bindMoveMethod(this,-1);
	prevCell.appendChild(this.controls.prevBtn);
	//this.controls.div.appendChild(this.controls.prevBtn);
	
	this.controls.counter.className="counter";
	this.controls.counter.style.display = "inline";
	var counterText = "Image "+(this.slides.currentIndex+1)+" of "+this.slides.items.length;
	this.controls.counter.appendChild(document.createTextNode(counterText));
	counterCell.appendChild(this.controls.counter);
	this.controls.counter.style.margin="0";
	counterCell.style.paddingLeft="5px";
	counterCell.style.paddingRight="5px";
	//this.controls.div.appendChild(this.controls.counter);
	
	this.controls.nextBtn.id = "nextBtn";
	this.controls.nextBtn.className="btnLinkOff";
	this.controls.nextBtn.innerHTML = frwdArrow;
	this.controls.nextBtn.onclick = bindMoveMethod(this,1);
	nextCell.appendChild(this.controls.nextBtn);
	//this.controls.div.appendChild(this.controls.nextBtn);
	
	row.appendChild(prevCell);
	row.appendChild(counterCell);
	row.appendChild(nextCell);
	tbody.appendChild(row);
	table.appendChild(tbody);
	table.style.marginLeft="10px";
	
	this.controls.div.appendChild(table);
	
	var prevOn = this.slides.currentIndex>0;
	var nextOn = this.slides.currentIndex<this.slides.items.length-1;
	btnInit(this.controls.prevBtn.id,false,true,13,false,false,false,true,true);
	btnInit(this.controls.nextBtn.id,false,true,13,false,false,false,true,true);
};

function bindMoveMethod(parentObj,offset){
	return function(){parentObj.move(offset);};
};

slideShowClass.prototype.move = function(move){
	this.get(this.slides.currentIndex + move);
};

slideShowClass.prototype.get = function(index){
	//if(index<0 || index>=this.slides.items.length) return;
	this.slides.currentIndex = index;
	this.setCurrent();
};

slideShowClass.prototype.setCurrent = function(){
	this.div.innerHTML = "";
	var imgContainerDiv = document.createElement("div");
	imgContainerDiv.className = "slideContainerDiv";
	
	this.slides.currentIndex = (this.slides.currentIndex>=this.slides.items.length)? 0:this.slides.currentIndex;
	this.slides.currentIndex = (this.slides.currentIndex<0)? this.slides.items.length-1:this.slides.currentIndex;
	
	var curSlide = this.slides.items[this.slides.currentIndex];
	var checkImg = new Image();
	var curImg = document.createElement("img");
	curImg.setAttribute("src",curSlide.src);
	curImg.setAttribute("alt",curSlide.altText);
	curImg.id= this.id+"_image";
	imgContainerDiv.appendChild(curImg);
	this.div.appendChild(imgContainerDiv);
	
	if(curSlide.captionTitle!=null){
		curSlide.captionTitle.div.innerHTML = curSlide.captionTitle.text;
		curSlide.caption.div.appendChild(curSlide.captionTitle.div);
	}
	if(curSlide.captionText!=null){
		curSlide.captionText.div.innerHTML = curSlide.captionText.text;
		curSlide.caption.div.appendChild(curSlide.captionText.div);
	}
	if(curSlide.captionTitle || curSlide.captionText){
		this.div.appendChild(curSlide.caption.div);
	}

	this.writeControls();
};

function slidesClass(){
	this.items = new Array();
	this.currentIndex = 0;
};

slidesClass.prototype.add = function(imgSrc,uri,altText,captionTitle,captionText){
	this.items[this.items.length] = new slideClass(imgSrc,null,altText,captionTitle,captionText);
	return this.items[this.items.length-1];
};



function slideClass(imgSrc,uri,altText,captionTitle,captionText){
	this.src = imgSrc;
	this.link = uri;
	this.altText = altText;
	this.obj = new Image();
	this.obj.src = this.src;

	this.caption = new Object();
	this.caption.div = document.createElement("div");
	this.caption.div.className = "caption";

	this.captionTitle = new Object;
	this.captionTitle.text = captionTitle;
	this.captionTitle.div = document.createElement("p");
	this.captionTitle.div.className = "captionTitle";

	this.captionText = new Object;
	this.captionText.text = captionText;
	this.captionText.div = document.createElement("span");
};

