var stopstart = 'pause';

function playPanels(){
	currentPanel++;
	if (currentPanel == totalPanels) {currentPanel=0;}
	sp2.showPanel(currentPanel);
	highlightButton(currentPanel);
}

function panelAction(panelNum) {
	if(panelNum == 'p'){
		sp2.showPreviousPanel()
		stopPanel();
		if (currentPanel>0){currentPanel--;} else { gotoPanel(totalPanels-1); }
		highlightButton(currentPanel);
	} else if (panelNum == 'n') {
		sp2.showNextPanel()
		stopPanel();
		if(currentPanel<totalPanels-1){currentPanel++;} else { gotoPanel(0); }
		highlightButton(currentPanel);
	} else if (panelNum == 's') {
		if (stopstart == 'pause') {
			stopPanel();
		} else {		
			startPanel(currentPanel);
		}		
	} else {
		gotoPanel(panelNum);
	}
}

function gotoPanel(panelNum) {
		sp2.showPanel(panelNum);
		stopPanel();
		currentPanel=panelNum;
		highlightButton(currentPanel);	
	}

function stopPanel() {
	stopstart = 'play';
	setText('play');
	clearInterval(panelTimer);
	if (typeof(newPanelTimer)!='undefined') {
		clearInterval(newPanelTimer);
	}
	
}

function startPanel() {
	stopstart = 'pause';
	setText('pause');
	currentPanel++;
	if (currentPanel == totalPanels) { currentPanel=0; } 	
	sp2.showPanel(currentPanel);
	highlightButton(currentPanel);
	newPanelTimer=setInterval(playPanels,delay);
}

function setText(text) {
	document.getElementById('startstopbutton').innerHTML = text;
}

function highlightButton(num) {
	for(forVar=0;forVar<totalPanels;forVar++){
		var buttonName = 'bannerNavButton'+forVar;
		if (forVar==num) {
			document.getElementById(buttonName).className = 'bannerNavActive';
			createCookie('currentPanel',forVar,0)
		} else {
			document.getElementById(buttonName).className = 'bannerNavInactive';
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}





/*var stopstart = 'pause';

function playPanels(){
	currentPanel++;
	if (currentPanel == totalPanels) {currentPanel=0;}
	sp2.showPanel(currentPanel);
	sp3.showPanel(currentPanel);
	highlightButton(currentPanel);
}

function panelAction(panelNum) {
	if(panelNum == 'p'){
		sp2.showPreviousPanel()
		sp3.showPreviousPanel()
		stopPanel();
		if (currentPanel>0){currentPanel--;}
		highlightButton(currentPanel);
	} else if (panelNum == 'n') {
		sp2.showNextPanel()
		sp3.showNextPanel()
		stopPanel();
		if(currentPanel<totalPanels-1){currentPanel++;}
		highlightButton(currentPanel);
	} else if (panelNum == 's') {
		if (stopstart == 'pause') {
			stopPanel();
		} else {		
			startPanel(currentPanel);
		}		
	} else {
		sp2.showPanel(panelNum);
		sp3.showPanel(panelNum);
		stopPanel();
		currentPanel=panelNum;
		highlightButton(currentPanel);
	}
}

function stopPanel() {
	stopstart = 'play';
	setText('play');
	clearInterval(panelTimer);
	if (typeof(newPanelTimer)!='undefined') {
		clearInterval(newPanelTimer);
	}
	
}

function startPanel() {
	stopstart = 'pause';
	setText('pause');
	currentPanel++;
	if (currentPanel == totalPanels) { currentPanel=0; } 	
	sp2.showPanel(currentPanel);
	sp3.showPanel(currentPanel);
	highlightButton(currentPanel);
	newPanelTimer=setInterval(playPanels,delay);
}

function setText(text) {
	document.getElementById('startstopbutton').innerHTML = text;
}

function highlightButton(num) {
	for(forVar=0;forVar<totalPanels;forVar++){
		var buttonName = 'bannerNavButton'+forVar;
		if (forVar==num) {
			document.getElementById(buttonName).className = 'bannerNavActive';
			createCookie('currentPanel',forVar,0)
		} else {
			document.getElementById(buttonName).className = 'bannerNavInactive';
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
*/



