// http://www.funda.nl/

function loadIframe(url) 
{
    window.frames['ifrm'].location = url;  
    return false;
}

function Class_WIB()
{
	this.Page = 1
	this.bTurned = false
	this.bMoving = false
	this.Interval = false
	this.speed = (document.all && document.getElementById ? 3 : 10)
	this.arrObjects = new Array()
	this.ScrollerWidth = 710
	this.v = 0
	this.vmax = 0
	this.a = 0
	this.x = 0
	this.t = 0 
	this.nArrObjects = 0

	for(var i=0;i<120;i++)
	{
		this.t += this.speed
		this.x += this.t
		if ( this.x * 2 > this.ScrollerWidth && this.vmax == 0 )
		{
			this.vmax = this.t
			this.Factor = this.ScrollerWidth / (this.x*2)
		}
	}
	this.x = 0
	this.xLocation = 0

	this.Class_WibObject = function(ImgId, Guid, Image, Desc, ImgName, type)
	{
		this.ImgId = ImgId
		this.Guid = Guid
		this.Image = Image
		this.Desc = Desc
		this.ImgName= ImgName
		this.type = type
		this.ImageLoaded = false
		this.URL = 'images/images/' + Image
		
		this.bStatsRegistered = (ImgId < 5)
		
		this.LoadImage = function()
		{
			if ( this.ImageLoaded == false )
			{
				document.getElementById('Image' + this.ImgId).src = this.GetImage()
				this.ImageLoaded = true
			}
		}
		
		this.GetStatRegStr = function()
		{
			if ( this.bStatsRegistered == false )
			{
				this.bStatsRegistered = true
				return this.StatsString
			}
			else
			{
				return ''
			}
		}
		
		this.getHTML = function()
		{
			var s = ''
			sEnter = '\n'
			if ( navigator.userAgent.indexOf('Firefox') > -1 ) sEnter = ''
			s += '<span class="wib_Object" style="left:' + (-10 + this.ImgId*142) + 'px;">'
			s += '	<a href="' + this.URL + '" class="wib" target="_blank">'
			s += '		<img class="WibImage" id="Image' + this.ImgId + '" border="0" '
			if ( this.ImgId < 10 )
			{
				s += 'src="' + this.GetImage() + '"'
				this.ImageLoaded = true
			}
			else
			{
				s += 'src="spacer.gif"'
			}
			s += ' width="120" alt="' + this.Desc + '" /><br>'+ this.ImgName
			// s += ' width="120" height="90" alt="' + this.Desc + '" /><br>'+ this.ImgName
			s += '	</a>'
			s += '</span>'
			return s
		}
		
		this.GetImage = function()
		{
			s = this.Image
			if ( s.indexOf('http') == -1 ) s = 'images/thumbnails/'+ s
			return s
		}
	}	
	
	this.AddObject = function(Guid, Image, Desc, ImgName, type)
	{
		var ImgId = this.arrObjects.length
		this.arrObjects[ImgId] = new this.Class_WibObject(ImgId, Guid, Image, Desc, ImgName, type)
	}

	this.Start = function()
	{
		this.nArrObjects = this.arrObjects.length
		this.xMax = 0
		this.APages = Math.ceil(this.nArrObjects / 5)
		this.xMin = - (this.APages-1) * (142 * 5)
		var s = ''
		for ( var i=0; i<this.nArrObjects; i++ )
		{
			 s += this.arrObjects[i].getHTML(i)
		}
		document.getElementById('WibSpan').innerHTML = s

		document.getElementById("WIB_Stats").innerHTML = 'Total Pages ' + Math.ceil(this.nArrObjects / 5)

		this.SetButtons()
	}
	
	this.SetButtons = function()
	{
		if ( this.nArrObjects > 5 )
		{
			document.getElementById('WIB_knop_right').style.display = ( this.Page < this.APages ? 'block' : 'none' )
			document.getElementById('WIB_knop_left').style.display = ( this.Page > 1 ? 'block' : 'none' )
			var s = ''
			for ( var i=1; i<=this.APages; i++ ) s += '<a href="javascript:WIB.ScrollPage(' + i + ')"' + (this.Page == i ? ' class="sel"' : '') + '>&nbsp;' + i + '&nbsp;</a>'
		}
	}

	this.Mouseover = function(sDirection)
	{
		if ( document.getElementById("wib_img_"+sDirection) )
		{
			document.getElementById("wib_img_"+sDirection).src = 'images/h_' + 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.ScrollPage(this.Page-_ax)
	}
	
	this.ScrollPage = function(n)
	{
		if ( this.bMoving == false )
		{
			this.bMoving = true
			this.a = ( this.Page>n ? 1 : -1 ) * this.speed
			this.PageMove = ( this.Page>n ? this.Page - n : n - this.Page )
			this.Page = n
			if ( this.Page > this.APages ) this.Page = this.APages
			if ( this.Page < 1 ) this.Page = 1
			for ( var i=0; i<5; i++ )
			{
				xTemp2 = (this.Page * 5 ) + i - 5
				if ( xTemp2 < this.nArrObjects )
				{
					this.arrObjects[xTemp2].LoadImage()
					s = this.arrObjects[xTemp2].GetStatRegStr()
				}
			}

			if ( !this.Interval ) this.Interval = setInterval('WIB.Move()',15)

			document.getElementById("WIB_Stats").innerHTML = 'Page ' + this.Page + ' / ' + Math.ceil(this.nArrObjects / 5)
		}
	
	}
	
	this.Move = function()
	{
		this.x += this.v * this.Factor * this.PageMove
		
		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()
		}
		document.getElementById('WibSpan').style.left = this.xLocation + 'px'
	}


}

