/**
 * @author Gert Blom
 * @company Blom Internetdiensten
 * @copyright 2009
 */


var Scroller = function(){};

/**
*	General settings
*/
// img-fields with small images
Scroller.smallFields 	= new Array('scroll1', 'scroll2', 'scroll3', 'scroll4' );

// img field with large image
Scroller.largeField 	= 'largepic';

// time for looping large pic (ms)
Scroller.loopTime		= 5000;


/**
*	Other attributes (don't edit)
*/
Scroller.images 		= new Array();
Scroller.loopLarge 		= 1;
Scroller.nrImages;
//Scroller.imgFieldsSmall	= new Array(); // small img fields
//Scroller.imgFieldLarge;
Scroller.currentLarge	= 0;
Scroller.currentSmall	= 0;
Scroller.posTracker		= new Array();

/**
*	Methods
*/
Scroller.init			= function( aImages ) {
	// set images
	this.images = aImages;
	this.nrImages = this.images.length;
	
	var k = 0;
	for ( var i in this.smallFields ) {
		this.posTracker[i] = k; 
		k = this.getNextImage( k );
	}
}


Scroller.previous 		= function() {
	
	var k = this.currentSmall;
	
	var i = this.smallFields.length;
	
	for ( var l = i; l > 0; l-- ) {
		
		k = this.getPreviousImage( k );

		document.getElementById( this.smallFields[l-1] ).src = this.images[k]['file_small'];
		this.posTracker[l-1] = k; // keep track of images
	}
	
	this.currentSmall = k;
	return;
}

Scroller.next 		= function() {

	var k = this.currentSmall + ( this.smallFields.length - 1 );
	
	for ( var i in this.smallFields ) {
		k = this.getNextImage( k );

		document.getElementById( this.smallFields[i] ).src = this.images[k]['file_small'];
		this.posTracker[i] = k; // keep track of images
	}
	this.currentSmall = (k - ( this.smallFields.length - 1 ) );
	return;
}

Scroller.loop			= function() {
		setTimeout( "Scroller.nextLarge();" , this.loopTime );
		return;
}

Scroller.nextLarge		= function() {
	
	if ( this.loopLarge == 1 ) {
		// volgende plaatje
		var i = this.getNextImage( this.currentLarge );

		document.getElementById( this.largeField ).src = this.images[i]['file_large'];
		this.currentLarge = i;
		
		// zet de loop weer aan
		this.loop();
		return;
	}else{
		// geen loop meer
		return;
	}
}

Scroller.getNextImage	= function( current ) {
	if ( ( current + 1 ) < this.nrImages ) {
		return (current + 1);
	}else{
		return 0;
	}
}

Scroller.getPreviousImage	= function( current ) {
	if ( ( current - 1 ) >= 0 ) {
		return (current - 1);
	}else{
		return (this.nrImages -1);
	}
}

Scroller.select		= function( position ) {
	
	this.loopLarge = 0; // loop uitzetten
	document.getElementById( this.largeField ).src = this.images[ this.posTracker[ position-1 ] ]['file_large'];
	this.currentLarge = this.posTracker[ position-1 ];
}
