function Class_WIB()
{
	this.stap = 0
	this.delay = 15
	this.PaginaStap = 1
	this.Pagina = 1
	this.bTurned = false
	this.bMoving = false
	this.Interval = false
	this.accelleratie = (document.all && document.getElementById ? 3 : 8)
	this.arrObjects = new Array()
	this.BeweegBreedte = 400
	this.v = 0
	this.vmax = 0
	this.a = 0
	this.x = 0
	this.t = 0 
	this.nAantalObjecten = 0

	for(var i=0;i<120;i++)
	{
		this.t += this.accelleratie
		this.x += this.t
		if ( this.x * 2 > this.BeweegBreedte && this.vmax == 0 )
		{
			this.vmax = this.t
			this.Factor = this.BeweegBreedte / (this.x*2)
		}
	}
	this.x = 0
	this.xLocation = 0

	this.Class_WibObject = function(nummer, Guid, Foto, Adres, Postcode, Plaats, Type, Oppervlak, Kamers, Bouwjaar, Prijs, sStatsString)
	{
		this.Nummer = nummer
		this.Guid = Guid
		this.Foto = Foto
		this.Adres = Adres
		this.Postcode = Postcode
		this.Plaats = Plaats
		this.Type = Type
		this.Oppervlak = Oppervlak
		this.Kamers = Kamers
		this.Bouwjaar = Bouwjaar
		this.Prijs = Prijs
		this.ImageLoaded = false
		this.StatsString = sStatsString
		this.URL = "#";
		
	/*
		var objPicture_Current = document.getElementById("current_picture");
		if(objPicture_Current != null){
			objPicture_Current.src = Foto.replace("-vignette", "");
		}
	*/	
		// Bij de eerste 5 is de bStatsRegisteren true. Bij de rest false
		this.bStatsRegistered = (nummer < 5)
		
		this.LoadImage = function()
		{
			if ( this.ImageLoaded == false )
			{
				document.getElementById('Image' + this.Nummer).src = this.GetFoto('120')
				this.ImageLoaded = true
			}
		}
		
		this.GetStatRegStr = function()
		{
			if ( this.bStatsRegistered == false )
			{
				this.bStatsRegistered = true
				return this.StatsString
			}
			else
			{
				return ''
			}
		}
		
		this.getHTML = function()
		{
			var sPlaatsTemp = ( this.Plaats.length > 18 ? this.Plaats.substring(0,18) + '...' : this.Plaats )
			var s = ''
			sEnter = '\n'
			if ( navigator.userAgent.indexOf('Firefox') > -1 ) sEnter = ''
			s += '<span class="wib_Object" style="left:' + (-10 + this.Nummer*101) + 'px;">'


			s += '	<a href="javascript:setPhoto(\''+ this.Foto.replace("-vignette", "")  +'\')" class="wib">'
			s += '		<img class="WibImage" id="Image' + this.Nummer + '" border="0" '
			if ( this.Nummer < 10 )
			{
				s += 'src="' + this.GetFoto('120') + '"'
				this.ImageLoaded = true
			}
			else
			{
				s += 'src="/img/spacer.gif"'
			}
			s += ' width="120" height="80" />'//<br>'
//			s += '		<nobr><b>' + sPlaatsTemp + '</b></nobr><br />'
			//s += '		&euro;&nbsp;' + this.Prijs + ''
			s += '	</a>'
			s += '</span>'
			return s
		}
		
		this.GetFoto = function(sFormaat)
		{
			if ( sFormaat != '' ) sFormaat = '_' + sFormaat
			s = this.Foto
			//if ( s.indexOf('http') == -1 ) s = 'http://images.funda.nl/woningen/img/' + s.substring(0,2) + '/' + s.substring(0,5) + '/' + s.replace('.jpg', '') + sFormaat + '.jpg'
			return s
		}
	}	
	
	this.AddObject = function(Guid, Foto, Adres, Postcode, Plaats, Type, Oppervlak, Kamers, Bouwjaar, Prijs, sStatsString)
	{
		var nummer = this.arrObjects.length
		this.arrObjects[nummer] = new this.Class_WibObject(nummer, Guid, Foto, Adres, Postcode, Plaats, Type, Oppervlak, Kamers, Bouwjaar, Prijs, sStatsString)
	}

	this.Start = function()
	{
		this.nAantalObjecten = this.arrObjects.length
		this.xMax = 0
		this.AantalPaginas = Math.ceil(this.nAantalObjecten / 5)
		this.xMin = - (this.AantalPaginas-1) * (101 * 5)
		var s = ''
		for ( var i=0; i<this.nAantalObjecten; i++ )
		{
			 s += this.arrObjects[i].getHTML(i)
		}
		document.getElementById('WibSpan').innerHTML = s
		this.SetButtons()
	}
	
	this.SetButtons = function()
	{
		
		if ( this.nAantalObjecten > 5 )
		{
			document.getElementById('WIB_knop_rechts').style.display = ( this.Pagina < this.AantalPaginas ? 'block' : 'none' )
			document.getElementById('WIB_knop_links').style.display = ( this.Pagina > 1 ? 'block' : 'none' )
			var s = ''
			for ( var i=1; i<=this.AantalPaginas; i++ ) s += '<a href="javascript:WIB.GaNaarPagina(' + i + ')"' + (this.Pagina == i ? ' class="sel"' : '') + '>&nbsp;' + i + '&nbsp;</a>'
			//document.getElementById('wib_pagenumber').innerHTML = s
		}
		
		if(this.nAantalObjecten == 5){
			document.getElementById('WIB_knop_rechts').style.display = ( this.Pagina < this.AantalPaginas ? 'block' : 'none' )
		}
	}

	this.Mouseover = function(sDirection)
	{
		if ( document.getElementById('wib_img_' + sDirection) )
		{
//			document.getElementById('wib_img_' + sDirection).src = '/img/2/wib/' + sDirection + '_hover.gif'
			document.getElementById('wib_img_' + sDirection).src = '..//images//' + sDirection + '.gif'
		}
	}

	this.Mouseout = function(sDirection)
	{
		if ( document.getElementById('wib_img_' + sDirection) )
		{
			document.getElementById('wib_img_' + sDirection).src = '..//images//' + sDirection + '.gif'
		}
	}
	
	this.MouseDown = function(_ax)
	{
		this.GaNaarPagina(this.Pagina-_ax)
	}
	
	this.GaNaarPagina = function(n)
	{
		if ( this.bMoving == false )
		{
			this.bMoving = true
			this.a = ( this.Pagina>n ? 1 : -1 ) * this.accelleratie
			this.PaginaMove = ( this.Pagina>n ? this.Pagina - n : n - this.Pagina )
			this.Pagina = n
			if ( this.Pagina > this.AantalPaginas ) this.Pagina = this.AantalPaginas
			if ( this.Pagina < 1 ) this.Pagina = 1
			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 ( sStats != '' ) 
			{
				document.getElementById('WIB_Stats').src = '/koop/wibRegStats.asp?stats=' + sStats
			}
			*/
			if ( !this.Interval ) this.Interval = setInterval('WIB.Move()',15)
		}
	}
	
	this.Move = function()
	{
		this.x += this.v * this.Factor * this.PaginaMove
		
		this.xLocation = Math.round(this.x)
		if ( this.x > this.xMax ) this.x = this.xMax
		if ( this.x < this.xMin ) this.x = this.xMin
		if ( this.bTurned == false && ( this.v >= this.vmax || this.v <= -this.vmax ))
		{
			this.a = -this.a
			this.bTurned = true
		}
		else
		{
			this.v += this.a
		}
		if ( this.v == 0 )
		{
			this.bTurned = false
			this.a = 0
			clearInterval(this.Interval)
			this.bMoving = false
			this.Interval = false
			this.SetButtons()
			this.PaginaStap = 1
		}
		document.getElementById('WibSpan').style.left = this.xLocation + 'px'
	}


}

function setPhoto(image_src){
	var objPicture_Current = document.getElementById("current_picture");
	if(objPicture_Current != null){
		objPicture_Current.src = image_src;
	}
}
