﻿function Class_WIB(iGlider)
{
	this.nrGlider = iGlider
	this.stap = 0
	this.steps = 15
	this.delay = 15
	this.Pagina = 1
	this.bMoving = false
	this.Interval = false
	this.arrObjects = new Array()
	this.BeweegBreedte = 645
	this.nAantalObjecten = 0
	if ( navigator.userAgent.indexOf('Firefox') > -1 ) this.steps = Math.ceil(this.steps/2)
	this.steps *= 2
	this.nFactor = new Array()
	var x = 0
	var v = 0
	var a = 1
	for(var i=0; i<=this.steps; i++)
	{
		if (i == this.steps/2) a = 0
		if (i > this.steps/2) a = -1
		v+=a
		x+=v
		this.nFactor[i] = x
	}
	for(i=0; i<=this.steps; i++)
	{
		this.nFactor[i] /= x
	}

	this.Class_WibObject = function(nummer, Foto, Url, Titel)
	{
		this.Nummer = nummer
		this.Foto = Foto
		this.Titel = Titel
		this.URL = Url
		this.ImageLoaded = false
		
		// Bij de eerste 3 is de bStatsRegisteren true. Bij de rest false
		this.bStatsRegistered = (nummer < 3)
		
		this.LoadImage = function()
		{
			if ( this.ImageLoaded == false )
			{
				document.getElementById('Image' + this.Nummer + this.nrGlider).src = this.Foto
				this.ImageLoaded = true
			}
		}
		
		this.GetStatRegStr = function()
		{
			if ( this.bStatsRegistered == false )
			{
				this.bStatsRegistered = true
				return this.Guid
			}
			else
			{
				return ''
			}
		}
		
		this.getHTML = function()
		{
			var s = ''
			sEnter = '\n'
			if ( navigator.userAgent.indexOf('Firefox') > -1 ) sEnter = ' '
			s += '<div class="wib-object" style="left:' + (718/3)*this.Nummer + 'px;"><div class="galleryImgArea">'
			s += '<a href="' + this.URL + '">'
			s += '<img id="Image' + this.Nummer + this.nrGlider + '" '
			s += 'src="' + this.Foto + '"'
			this.ImageLoaded = true
			s += ' width="100" height="100" alt="Foto" title="' + this.Titel + '" />' + sEnter
			tmpTitel = this.Titel;
			if (tmpTitel.length > 27) {
				tmpTitel = tmpTitel.substr(0,27) + '...';
			}
			s += tmpTitel + '<br />'
			s += '</a>'
			s += '</div></div>'

			return s
		}
	}	
	
	this.AddObject = function(Foto, Url, Titel)
	{
		var nummer = this.arrObjects.length
		this.arrObjects[nummer] = new this.Class_WibObject(nummer, Foto, Url, Titel)
	}

	this.Start = function()
	{
		this.nAantalObjecten = this.arrObjects.length
		this.xMax = 0
		this.AantalPaginas = Math.ceil(this.nAantalObjecten / 3)
		this.xMin = - (this.AantalPaginas-1) * (this.BeweegBreedte)
		var s = ''
		for ( var i=0; i<this.nAantalObjecten; i++ )
		{
			 s += this.arrObjects[i].getHTML(i)
		}
		//document.getElementById('wib-inner'+this.nrGlider).innerHTML = s
		this.SetButtons()
	}
	
	this.SetButtons = function()
	{
		if ( this.nAantalObjecten > 3 )
		{
		    if (this.Pagina == 1) {
		        document.getElementById("Wib-arrow-l1").src = "/Resources/Images/BackInactive.png";
		        document.getElementById("Wib-arrow-l1").style.cursor = "default";
		    } else {
		        document.getElementById("Wib-arrow-l1").src = "/Resources/Images/BackActive.png";
		        document.getElementById("Wib-arrow-l1").style.cursor = "pointer";
		    }
		    
		    if (this.Pagina == this.AantalPaginas) {
		        document.getElementById("Wib-arrow-r1").src = "/Resources/Images/NextInActive.png";
		        document.getElementById("Wib-arrow-r1").style.cursor = "default";
		    } else {
		        document.getElementById("Wib-arrow-r1").src = "/Resources/Images/NextActive.png";
		        document.getElementById("Wib-arrow-r1").style.cursor = "pointer";
		    }
			//document.getElementById('Wib-arrow-r'+this.nrGlider).style.display = ( this.Pagina < this.AantalPaginas ? 'block' : 'none' )
			//document.getElementById('Wib-arrow-l'+this.nrGlider).style.display = ( this.Pagina > 1 ? 'block' : 'none' )
		}
		else
		{
			document.getElementById('Wib-arrow-r'+this.nrGlider).style.display = 'none'
			document.getElementById('Wib-arrow-l'+this.nrGlider).style.display = 'none'
		}
	}

	this.Click = function(ax)
	{
		if ( this.bMoving == false )
		{
			var paginaVorige = this.Pagina
			this.Pagina += ax
			if ( this.Pagina > this.AantalPaginas ) this.Pagina = this.AantalPaginas
			if ( this.Pagina < 1 ) this.Pagina = 1
			if ( paginaVorige == this.Pagina ) return
			this.bMoving = true
			
			sStats = ''
			for ( var i=0; i<3; i++ )
			{
				xTemp2 = (this.Pagina * 3 ) + i - 3
				if ( xTemp2 < this.nAantalObjecten )
				{
					this.arrObjects[xTemp2].LoadImage()
					s = this.arrObjects[xTemp2].GetStatRegStr()
					sStats += s + ( s == '' ? '' : ',' )
				}
			}
			if ( !this.Moving ) this.Move(0, ax)
			this.bMoving = true
		}
	}
	
	this.Move = function(stap, direction)
	{
		this.x = this.nFactor[stap] * direction * this.BeweegBreedte + (this.Pagina - direction - 1) * this.BeweegBreedte

		this.xLocation = Math.round(this.x)
		if ( this.x > this.xMax ) this.x = this.xMax
		if ( this.x < this.xMin ) this.x = this.xMin
		
		document.getElementById('wib-inner'+this.nrGlider).style.left = -this.xLocation + 'px'
		if ( stap == this.steps )
		{
			this.bTurned = false
			this.a = 0
			clearInterval(this.Interval)
			this.bMoving = false
			this.Interval = false
			this.SetButtons()
			this.PaginaStap = 1
		}
		else
		{
			stap ++
			setTimeout('WIB'+this.nrGlider+'.Move(' + stap + ', ' + direction + ')',15)
		}
	}


}


