//************************************************************************
//
// Example Code
//
// var mySlideList1 = [
//	['images/slide1.gif', 'Title 1', 'Title 2'],
//	['images/slide2.gif', 'Title 1', 'Title 2']
// ];
//
// var mySlideShow1 = new objSlideShow('mySlideShow1', mySlideList1);
//
//************************************************************************
//
// Requires fade.js
//
//************************************************************************

function objSlideShow(sName, aArray)
{
	this.currSlideId = -1;
	if (aArray)
	{
		this.aSlides = aArray;
		this.currSlideId = randomId(aArray.length);
	} else {
		this.aSlides = new Array();
	};
	
	this.name = sName;
	this.speed = 5000;
  	this.timer = 0;
  	this.paused = false;
  	this.temp = new Image();
};

objSlideShow.prototype.setup = objSlideShowSetup;
objSlideShow.prototype.prev = objSlideShowPrev;
objSlideShow.prototype.next = objSlideShowNext;
objSlideShow.prototype.show = objSlideShowShow;
objSlideShow.prototype.update = objSlideShowUpdate;
objSlideShow.prototype.play = objSlideShowPlay;
objSlideShow.prototype.pause = objSlideShowPause;
objSlideShow.prototype.resume = objSlideShowResume;

function objSlideShowSetup(){
	this.objDIV = objById('Slide');
	with (this)	
	{
		if (objDIV) {
			objDIV.onmouseover = pause;
			objDIV.onmouseout = resume;
			play();
		} else {
			clearTimeout(timer);
			timer = setTimeout(name+'.setup()', speed);
		};
	};
};

function objSlideShowPrev()
{
	with (this)
	{
		currSlideId--;
		if (currSlideId < 0)
		{
			currSlideId = aSlides.length-1;
		};
		show(currSlideId);
	};
};

function objSlideShowNext()
{
	with (this)
	{
		currSlideId++;
		if (currSlideId >= aSlides.length)
		{
			currSlideId = 0;
		};
		show(currSlideId);
	};
};

function objSlideShowShow(sId)
{
	with (this)
	{
		currSlide = aSlides[sId];
		update();
		//Trigger that image has downloaded
		this.temp.onload = setupSlide;
		this.temp.src = currSlide[0];
		
	};
};

function objSlideShowUpdate()
{
	with (this)
	{
     		//Update Counter
     		var lCtr = objById('SlideCtr');;
     		if (lCtr) 
     		{
     			lCtr.innerHTML = (currSlideId+1) + ' of ' + aSlides.length;
     		};
	};
};

function objSlideShowPlay()
{
  with(this)
  {
	if (!paused){
		next();
	}

  	clearTimeout(timer);
  	timer = setTimeout(name+'.play()', speed);
  };
};

function objSlideShowPause()
{
	this.paused = true;
};

function objSlideShowResume()
{
	this.paused = false;
};

function setupSlide(){
	

	//Make the Slide layer visible 
	lSlide = objById('Slide');
	lSlide.style.visibility = 'visible';

	//Set the image
	lImg = objById('SlideImage');
	if (lImg){
		lShadow = objById('SlideShadow');
		if (lShadow){
			//lShadow.style.width=0;
			setOpacity(lShadow, 0);
		}
		//setOpacity(lImg, 0);
		lImg.src = currSlide[0];
		showSlide();
	};

};

function setupTextLayer(sSlide){
	
	//Set the text
	lHTML = objById('SlideText');
	if (lHTML){
		lText = '<p>';
		if (sSlide[2] != null) {
			if (sSlide[1] != null) {
				lText = lText + sSlide[1];
			} else {
				lText = lText + 'Company: '
			}
			//Edit this line to change the Title 1 Text
			lText = lText + '<strong>' + sSlide[2] + '</strong>';
		};
		if (sSlide[4] != null) {
			if (sSlide[2] != null) {
				lText = lText + '<br/>';
			};
			if (sSlide[3] != null) {
				lText = lText + sSlide[3];
			} else {
				lText = lText + 'Software: '
			};
			//Edit this line to change the Title 2 Text
			lText = lText + '<strong>' + sSlide[4] + '</strong>';
		} else {
			lText = lText + '<br/>';
		}
		lText = lText + '</p>';
		lHTML.innerHTML = lText;
	};
	
};

function showSlide(){
	showLayer('Slide');
	fadeIn('SlideImage',0);
	fadeIn('SlideShadow',0);
	setupTextLayer(currSlide)
};
