// JavaScript Document
// SlideShow class
// Maakt gebruik van Tween.js

function switchSlide(backwards){
	
	if(backwards==null)
		backwards = false;

	with(this){
		
		if(!backwards && currentSlide+1 == images.length)
			currentSlide = 0;
		else if(!backwards)
			currentSlide++;
		else if(backwards && currentSlide>0)
			currentSlide--;
			
		var tween = new Tween(element.style,'left',Tween.strongEaseOut,element.offsetLeft,-(imageWidth*currentSlide),2,'px');	
		
		tween.start();		

		if(type=='interact'){
			
			if(currentSlide+1 == images.length){
			
				forwardBtn.style.cursor = 'default';
				forwardBtn.onmouseover = '';
				forwardBtn.onmouseout = '';
				forwardBtn.onclick = '';
				
				forwardBtn.src = 'images/forward.png';
				
				backBtn.style.cursor = 'pointer';
				backBtn.onmouseover = function(){ backBtn.src = 'images/back_hover.png';};
				backBtn.onmouseout = function(){ backBtn.src = 'images/back.png';};
				backBtn.onclick = function(){ switchSlide(true);};
			
			}else if(currentSlide==0){
				
				forwardBtn.style.cursor = 'pointer';
				forwardBtn.onmouseover = function(){ forwardBtn.src = 'images/forward_hover.png';};
				forwardBtn.onmouseout = function(){ forwardBtn.src = 'images/forward.png';};
				forwardBtn.onclick = function(){ switchSlide();};
				
				backBtn.style.cursor = '';
				backBtn.onmouseover = '';
				backBtn.onmouseout = '';
				backBtn.onclick = '';
				
				backBtn.src = 'images/back.png';
			
			}else{
			
				forwardBtn.style.cursor = 'pointer';
				forwardBtn.onmouseover = function(){ forwardBtn.src = 'images/forward_hover.png';};
				forwardBtn.onmouseout = function(){ forwardBtn.src = 'images/forward.png';};
				forwardBtn.onclick = function(){ switchSlide();};
			
				backBtn.style.cursor = 'pointer';
				backBtn.onmouseover = function(){ backBtn.src = 'images/back_hover.png';};
				backBtn.onmouseout = function(){ backBtn.src = 'images/back.png';};
				backBtn.onclick = function(){ switchSlide(true);};
			
			}
			
		}else
			setTimeout(function(){ switchSlide(); },5000);
		
	}
  
}

function SlideShow(element, imageWidth, imageHeight, type){
	
	//Sla het element op
	this.element = element;
	//Sla de meegegeven breedte en hoogte op van de slideshow
	this.imageWidth = imageWidth;
	this.imageHeight = imageHeight;	
	//Sla de slides (afbeeldingen) op
	this.images = element.getElementsByTagName("img");
	//Sla het type op
	this.type = type;
	//Variabele opslaan
	this.currentSlide = 0;
	
	if(type=='interact'){
		
		var parent = element.parentNode;
		for(var i=0; i<parent.children.length; i++){
		
			if(parent.children[i].className=='back')
				this.backBtn = parent.children[i];

			if(parent.children[i].className=='forward')
				this.forwardBtn = parent.children[i];
				
		}

	}
	
	with(this){

		element.style.width = (images.length*imageWidth)+'px';
		
		if(type=='interact'){
		
			forwardBtn.style.cursor = 'pointer';
			forwardBtn.onmouseover = function(){ forwardBtn.src = 'images/forward_hover.png';};
			forwardBtn.onmouseout = function(){ forwardBtn.src = 'images/forward.png';};
			forwardBtn.onclick = function(){ switchSlide();};
			
		}else
			setTimeout(function(){ switchSlide(); },4000);
			
	}	

}

//Functie opslaan dat een nieuwe slide laat zien
SlideShow.prototype.switchSlide = switchSlide;

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

