var oud =0;
var nieuw=0;
var delay = 300;
var images;
var lengte=0;
function pictureviewer()
{
  this.position = 0;
  //this.playhead = new Playhead();
  element_id = "left";
  var container = document.getElementById(element_id);
  this.images = container.getElementsByTagName('IMG');
  images = this.images;
  lengte = images.length;
	//this.setStates();
  document.getElementById('pic'+oud).className="showpic";
  document.getElementById('pic'+oud).style.opacity=100;
  setTimeout("fade('pic'+oud);",5000);
}

function fade(images)
{
	
	setTimeout("shiftOpacity('pic'+oud, 500);",500);
	setTimeout("changeAll('pic'+oud)",1000);
	
  	nieuw = oud+1;
  	if(nieuw==lengte)
  	{
  		nieuw=0;
  	}
  	setTimeout("changeAll2('pic'+nieuw)",1000);
  	setTimeout("shiftOpacity('pic'+nieuw, 500);",1100);
  	setTimeout("fade('pic'+nieuw);",5000);
  	
  	
}

function changeAll(elementId)
{

	document.getElementById(elementId).className="nopic";
	document.getElementById(elementId).style.opacity=0;
	oud=nieuw;
}

function changeAll2(elementId)
{
	document.getElementById(elementId).className="showpic";
	var object = document.getElementById(elementId).style; 
	object.opacity = 0;
	object.MozOpacity = 0;
	object.KhtmlOpacity = 0;
	object.filter = "alpha(opacity=0)";
	
}

function fadeOut(image)
{
}


function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}



function setMaand(date , p_id, name)
{
	var tja = p_id.split(",");
	location.href = '?p_Id='+p_id+'&name='+name+'&jaar='+date+ '&id='+tja[1];
}
