﻿/*Constants, which have to be declared as variables thanks to the stupidity of
Javascript*/
var PANELNAME = 'panel';
var THUMBNAME = 'thumb';

var PANELONCLASS = 'showpanel';
var PANELOFFCLASS = 'hidepanel';
var THUMBONCLASS = 'solid';
var THUMBOFFCLASS = 'faded';

var PANEL = 0
var THUMB = 1

var COUNTSTART = 1
var COUNTINCREMENT = 1
/*End constants*/

/*Real variables*/
var incount = COUNTSTART;
var iHandle;
var numberofpanels;
var slideshowinterval;

var i = 0;
/*End real variables*/


/*Initialize user defined variables, and kick off the slideshow*/
function Play(inputnumpanels, inputinterval){
  numberofpanels = inputnumpanels;
  slideshowinterval = inputinterval;
  slideshow();  
  showhidePauseButton(true);
  showhidePlayButton(false); 
     
}

/*Sets function call and interval for the slideshow*/
function slideshow(){
    
	iHandle = setInterval(slideshow_move, slideshowinterval);
		
}

/*Switches the active div, and increments counter*/
function slideshow_move() {
    
   	switchpanel(incount);   
	counterInc();	
	if(i>1)    
	{
	   initImage('thephoto1');
	}
	initImage('thephoto1');
    initImage('thephoto2'); 
    initImage('thephoto3');   
    initImage('thephoto4');    
}

/*Calls class to change class for each div, depending on which item is active*/
function switchpanel(activepanel){
  
  var loopcount;  
  for(loopcount = COUNTSTART;loopcount<=numberofpanels;loopcount++){
   if (loopcount == activepanel){    
    change(loopcount, PANELONCLASS, PANEL);
    change(loopcount, THUMBONCLASS, THUMB);   
    i = i + 1;   
   }else{
    change(loopcount, PANELOFFCLASS, PANEL);
    change(loopcount, THUMBOFFCLASS, THUMB);
   }
  }
  
}

/*Change class of div specified*/
function change(elementid, newClass, isthumb) {
    
  var elementname;
  if (isthumb) {
   elementname = THUMBNAME
  }else{
   elementname = PANELNAME
  }
  identity=setelementid(elementname,elementid);
  identity.className=newClass;
  
  return;
}

/*Returns the doc element for tinkering*/
function setelementid(elementname, elementid){
  
  return document.getElementById(elementname + elementid);
    

}

/*Increments counter*/
function counterInc() {
  incount = incount + COUNTINCREMENT;
  if (incount > (numberofpanels)) {incount = COUNTSTART};
}


function GetObjectById(ObjectID){    
    return document.getElementById(ObjectID);    
}


function Set_Visibility(myDiv, visibilityFlag)
{   
    if (myDiv != null)
    {
        if (visibilityFlag == false){
            myDiv.style.display='None';
            myDiv.style.visibility = "hidden";            
        }
        
        else{            
            myDiv.style.display='Block'; 
            myDiv.style.visibility = "visible";            
        }                
    }    
}

function Pause(){
    clearInterval(iHandle)
    
    showhidePauseButton(false);
    showhidePlayButton(true);    
}


function showhidePauseButton(flag){
    var bnt = GetObjectById('bntPause1');
    Set_Visibility(bnt, flag); 
    
    bnt = GetObjectById('bntPause2');
    Set_Visibility(bnt, flag); 
    
    bnt = GetObjectById('bntPause3');
    Set_Visibility(bnt, flag); 
    
    bnt = GetObjectById('bntPause4');
    Set_Visibility(bnt, flag); 
    
   // bnt = GetObjectById('bntPause5');
  //  Set_Visibility(bnt, flag); 
}


function showhidePlayButton(flag){
    var bnt = GetObjectById('bntPlay1');
    Set_Visibility(bnt, flag); 
    
    bnt = GetObjectById('bntPlay2');
    Set_Visibility(bnt, flag); 
    
    bnt = GetObjectById('bntPlay3');
    Set_Visibility(bnt, flag); 
    
    bnt = GetObjectById('bntPlay4');
    Set_Visibility(bnt, flag); 
    
 //   bnt = GetObjectById('bntPlay5');
 //   Set_Visibility(bnt, flag); 

}
 

