//-------- Names of CSS styles used in the javascript
var SS_STYLE_FRAME = "ss_slideshowFrame";
var SS_STYLE_TITLE = "ss_slideshowTitle";
var SS_STYLE_PROGRESS = "ss_slideProgress";
var SS_STYLE_CONTROLS = "ss_slideControls";
var SS_STYLE_CONTROL_LEFT = "ss_leftButton";
var SS_STYLE_CONTROL_RIGHT = "ss_rightButton";
var SS_STYLE_SLIDEHOLDER = "ss_slideHolder";

//-------- SlideShow object
function SlideShow(frameId) {
	this.frame = document.getElementById(frameId);
	//Set frame class
	this.frame.className = SS_STYLE_FRAME;
	
	this.addDisplayElements();
};
	
SlideShow.prototype.setSlides = function(slideshowId) {
	var slideshow = document.getElementById(slideshowId);
	this.titleDiv.innerHTML = slideshow.title;
	this.slides = slideshow.getElementsByTagName("LI");
	this.currentIndex = 0;
	this.firstTime = 0;
	this.redraw();
};

SlideShow.prototype.redraw = function() {
	this.progressDiv.innerHTML = (this.currentIndex+1) + " of " + this.slides.length;
	this.leftButton.style.display = (this.currentIndex == 0) ? "none" : "";
	this.rightButton.style.display = (this.currentIndex == (this.slides.length - 1)) ? "none" : "";
	this.slideDiv.innerHTML = this.slides[this.currentIndex].innerHTML;
	if (this.firstTime > 0)
	{
		// refresh yonder ads
		nbcsp.firePageViewEvent(false,true,true);
	}
	this.firstTime = this.firstTime+1;	
};

SlideShow.prototype.goLeft = function() {
	this.currentIndex--;
	this.redraw();
};

SlideShow.prototype.goRight = function() {
	this.currentIndex++;
	this.redraw();
};

SlideShow.prototype.addDisplayElements = function() {
	//--Add display elements to the frame
	//Create slideshow title placement
	this.titleDiv = document.createElement("DIV");
	this.titleDiv.className = SS_STYLE_TITLE;
	this.frame.appendChild(this.titleDiv);
	
	//Create slideshow progress indicator
	this.progressDiv = document.createElement("DIV");
	this.progressDiv.className = SS_STYLE_PROGRESS;
	this.frame.appendChild(this.progressDiv);
	
	//Create slideshow controls
	this.controlsDiv = document.createElement("DIV");
	this.controlsDiv.className = SS_STYLE_CONTROLS;
	this.frame.appendChild(this.controlsDiv);
	
	this.frame.appendChild(document.createElement("BR"));
	
	//Create slideshow slide holder
	this.slideDiv = document.createElement("DIV");
	this.slideDiv.className = SS_STYLE_SLIDEHOLDER;
	this.frame.appendChild(this.slideDiv);

	// Create left button element
	this.leftButton = document.createElement("INPUT");
	this.leftButton.type="button";
	var t = this;
	this.leftButton.onclick = function () {
		t.goLeft();	
	};
//	this.leftButton.value="<";
	this.leftButton.className = SS_STYLE_CONTROL_LEFT;
	this.controlsDiv.appendChild(this.leftButton);
	
	// Create right button element
	this.rightButton = document.createElement("INPUT");
	this.rightButton.type="button";
//	this.rightButton.value=">";
	this.rightButton.onclick = function () {
		t.goRight();	
	};
	this.rightButton.className = SS_STYLE_CONTROL_RIGHT;
	this.controlsDiv.appendChild(this.rightButton);
};
