﻿/*Constants, which have to be declared as variables thanks to the stupidity of
Javascript*/
var PANELNAME = 'panel';

var PANELONCLASS = 'showpanel';
var PANELOFFCLASS = 'hidepanel';

var PANEL = 0

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');
	}          
}*/

/*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);    
    i = i + 1;   
   }else{
    change(loopcount, PANELOFFCLASS, PANEL);    
   }
  }
  
}

/*Change class of div specified*/
function change(elementid, newClass, isthumb) {
    
  var elementname;
  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); 

}
function initImage(imageId) {
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
}
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
}
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;	
}

    