var ie4up = (document.all) ? true : false;

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters)) 
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				img.style.display = 'block';
				
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<div " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></div>" 
				img.outerHTML = strNewHTML
				
				i = i-1
			}
		}
	}
	
	for (var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		{
			img.style.display = 'block';
		}
	}
}

function NewsTracker()
{
	this.newsobjects = new Array();
	
	this.currentitem = null;
}

	NewsTracker.prototype.AddNewsObject = function (newsobject)
	{
		this.newsobjects[this.newsobjects.length] = newsobject;
	}
	
	NewsTracker.prototype.Start = function ()
	{
		if (this.newsobjects.length > 0)
		{	
			// starten bij het eerste item indien aanwezig
			if (this.currentitem == null)
			{
				this.currentitem = this.newsobjects[0].id
			}
			// er is minimaal al één cyclus geweest
			else
			{
				for (var i = 0; i < this.newsobjects.length; i++)
				{
					if (this.currentitem == this.newsobjects[i].id)
					{
						if (i == (this.newsobjects.length - 1))
						{
							var index = 0;
						}
						else
						{
							var index = i + 1;
						}
					}
				}
						
				this.currentitem = this.newsobjects[index].id;
			}
			
			for (var i = 0; i < this.newsobjects.length; i++)
			{
				if (this.currentitem == this.newsobjects[i].id)
				{
					this.newsobjects[i].target.innerHTML = '<a href="' + this.newsobjects[i].url  + '">' + this.newsobjects[i].title + '</a>';
					this.newsobjects[i].Fade(true);
				}
			}
		}
	}
	
function NewsObject(id, url, title, sourceid, step, hold, speed, opacitymin, opacitymax)
{
	this.id		= id;
	this.url	= url;
	this.title	= title;
	
	this.sourceid	 = sourceid;
	
	this.opacitymin  = opacitymin; 
	this.opacitymax  = opacitymax; 
	this.opacitycur  = opacitymin; 
	
	this.step		 = step;
	this.hold		 = hold;
	this.speed		 = speed;
	
	this.target		 = document.getElementById(sourceid);
	
	this.timer;
}

	NewsObject.prototype.Fade = function (state)
	{
		var self = this;
		
		clearTimeout (this.timer);
		
		if (state)
		{
			this.opacitycur = this.opacitycur + this.step;
			this.opacitycur = (this.opacitycur > this.opacitymax) ? this.opacitymax : this.opacitycur;
			
			if (ie4up)
				this.target.filters.alpha.opacity = this.opacitycur;
			else
				this.target.style.MozOpacity = this.opacitycur / 100;
			
			
			if (this.opacitycur < this.opacitymax)
			{
				this.timer = setTimeout (function(){self.Fade(state)}, this.speed);
			}
			else
			{
				this.timer = setTimeout (function(){self.Fade(false)}, this.hold);
			}
		}
		else
		{
			this.opacitycur = this.opacitycur - this.step;
			this.opacitycur = (this.opacitycur < this.opacitymin) ? this.opacitymin : this.opacitycur;
			
			if (ie4up)
				this.target.filters.alpha.opacity = this.opacitycur;
			else
				this.target.style.MozOpacity = this.opacitycur / 100;
			
			if (this.opacitycur > this.opacitymin)
			{
				this.timer = setTimeout (function(){self.Fade(state)}, this.speed);
			}
			else
			{
				this.timer = setTimeout (function(){newstrackert.Start()}, 1000);
			}
		}
	}

function SwapImage(id, src, text)
{
	document.getElementById(id).src = src;
	document.getElementById('photodescription').innerHTML = text;
}

function Send (form, location)
{
	form.method = 'post';
	form.action = location;
	form.submit();
	
	return false;
}

window.onload = function ()
{
	correctPNG();
	
	newstrackert.Start();
}
