var WIB = new Class_WIB()

function changeMain(thisSrc){
	var mainPhoto	= document.getElementById("photoxl");
	var tempPhoto	= mainPhoto.src;
	mainPhoto.src	= thisSrc.src;
}
	
function Class_WIB() {
	this.stap = 0
	this.steps = 15
	this.delay = 15
	this.Pagina = 1
	this.bMoving = false
	this.Interval = false
	this.arrObjects = new Array()
	this.BeweegBreedte = 692
	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, Guid, Foto, Plaats , Straat , Prijs , Owner , Lisnr) {
		this.Nummer = nummer
		this.Guid = Guid
		this.Foto = Foto
		this.Plaats = Plaats
		this.Straat = Straat
		this.Prijs = Prijs
		this.Owner = Owner
		this.Lisnr = Lisnr
		this.ImageLoaded = false
		this.LoadImage = function()
		{
			if ( this.ImageLoaded == false )
			{
				document.getElementById('Image' + this.Nummer).src = this.Foto
				this.ImageLoaded = true
			}
		}
		
		this.GetStatRegStr = function() {
			{
				return ''
			}
		}
		
		this.getHTML = function() {
			var sPlaatsTemp = ( this.Plaats.length > 20 ? this.Plaats.substring(0,18) + '...' : this.Plaats )
			var s = ''
			sEnter = '\n'
			if ( navigator.userAgent.indexOf('Firefox') > -1 ) sEnter = ' '

			s += '<div class="wib-object" style="left:' + (WIB.BeweegBreedte/5)*this.Nummer + 'px;">'
			s += '<a href="objectres.cfm?lisowner=' + this.Owner + '&lisnr=' + this.Lisnr + '"><img id="Image' + this.Nummer + '" '
			//s += '<a href="woning/'+this.Lisnr+'/'+this.Plaats+'-'+this.Straat+'/"><img id="Image' + this.Nummer + '" '
			if ( this.Nummer < 10 )
			{
				s += 'src="' + this.Foto + '"'
				this.ImageLoaded = true
			}
			else
			{
				s += 'src="/gfx/spacer.png"'
			}
			s += ' width="112" height="78" border="0" class="thumb" title="' + sEnter
			' '
			s += this.Plaats + '" /></a>'
			s += ''
			s += '<div style="color:#002F6B; font-family:Tahoma; font-size:11px; margin-left:10px; text-align:left;">' + this.Straat + '<br />' + this.Plaats + '<br />' + this.Prijs + '</div></div>'

			return s
		}
	}	
	
	this.AddObject = function(Guid, Foto, Plaats , Straat , Prijs , Owner , Lisnr) {
		var nummer = this.arrObjects.length
		this.arrObjects[nummer] = new this.Class_WibObject(nummer, Guid, Foto, Plaats , Straat ,  Prijs , Owner , Lisnr)
	}

	this.Start = function()
	{
		this.nAantalObjecten = this.arrObjects.length
		this.xMax = 0
		this.AantalPaginas = Math.ceil(this.nAantalObjecten / 5)
		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').innerHTML = s
		this.SetButtons()
	}
	
	this.SetButtons = function()
	{
		if ( this.nAantalObjecten > 5 )
		{
			document.getElementById('Wib-arrow-r').style.display = ( this.Pagina < this.AantalPaginas ? 'block' : 'none' )
			document.getElementById('Wib-arrow-l').style.display = ( this.Pagina > 1 ? 'block' : 'none' )
		}
		else
		{
			document.getElementById('Wib-arrow-r').style.display = 'none'
			document.getElementById('Wib-arrow-l').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<5; i++ )
			{
				xTemp2 = (this.Pagina * 5 ) + i - 5
				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').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.Move(' + stap + ', ' + direction + ')',15)
		}
	}


}

