/**
 * Fading background images
 */
var files = new Array(2);
var cur = 1;

window.onload = function() {
  window.onload;

  var fader = document.getElementById('fader');
  
  if (fader) {
    var faderimg = document.getElementById('faderimg');
    
    if (faderimg) {
      fader.style.background = faderimg.src +' no-repeat';
      
      files[0] = '/images/fader/black.php?width='+ faderimg.width +'&height='+ faderimg.height;
      files[1] = faderimg.src;
      
      setTimeout("nextImage();", 3000);
    }
  }
  
  /**
   * Automatisch eerst error-veld in het contactformulier activeren als die er is
   */
  var err1 = document.getElementById('contactform_firsterror');
  
  if (err1) {
    for (i in err1.childNodes) {
      if (err1.childNodes[i].tagName && err1.childNodes[i].tagName.toLowerCase()=='input') {
        err1.childNodes[i].focus();
      }
    }
  }
}

/*
// BEGIN CHECKBOXCONVERTER

// Image Check Box (15-11-2005)
// by Vic Phillips http://vicsjavascripts.org.uk

// The Script converts an existing Check Box to an Image Check Box
// using function icbCBoxtoImgCB(.......

// The image check box has images for the true and false conditions
// The true or false conditions are reflected in a 'real' check box.
// This allows standard techniques to be employed when submitting the form.
// Verify the state against the same id/name
// as the id of the original image/checkbox.
// There may be a many image check boxes on a page as required.

// Initialise the check boxes 'onload' of the page.
// ie
// <body onload="icbCBoxtoImgCB(*id*,*state*,'*ImageTrue*','*ImageFalse*','*width*,*height*);" >
// where
// *id*         = id of the image checkbox (string)
// *state*      = the initial condition (true or false )
// *ImageTrue*  = the image to be displayed for the 'true' condition (string)
// *ImageFalse* = the image to be displayed for the 'false' condition (string)
// *width*      = the width of the image (optional)(digits)
// *height*     = the height of the image (optional)(digits)

// The function icbCheckBoxMoniter(icb) may be used to action external functions
// the function is passed with the checkbox object when the checkbox checked state changes

// All variables name ect are prefixed with 'icb'
// to minimise conflicts with other javascripts.
// Tested with IE6, NS7, MozillaFF and Opera7


function icbCheckBoxMoniter(icb){
 alert('CheckBox '+icb.id+' is '+icb.checked);
}

// No Need to Change
var icbCursor='pointer';
if (document.all){ icbCursor='hand'; }


function icbCBoxtoImgCB(icb,icbs,icbT,icbF,icbw,icbh){
  // Create Image Element, Append Before the Check Box, Add OnClick Event & Load Correct Image
 icbNewImg=document.createElement('img');
 icbNewImg.id='icb'+icb;
 icbcb=document.getElementById(icb);
 icbcb.parentNode.insertBefore(icbNewImg,icbcb);
 icbNewImg.style.cursor=icbCursor;
 if (icbw!=null&&icbh!=null){ icbNewImg.width=icbw; icbNewImg.height=icbh; }
 icbNewImg.cb=icbcb;
 icbNewImg.icbT=icbT;
 icbNewImg.icbF=icbF;
 icbNewImg.onclick=function(){ icbImgCBox(this); };
 if (icbs){ icbNewImg.src=icbT; } else { icbNewImg.src=icbF; }
 // Hide the real Check Box
 icbcb.checked=icbs;
 icbcb.style.position='absolute';
 icbcb.style.visibility='hidden';
}

function icbImgCBox(icb){
 if (icb.cb.checked){
  icb.src=icb.icbF;
  icb.cb.checked=false;
 }
 else {
  icb.src=icb.icbT;
  icb.cb.checked=true;
 }
 icbCheckBoxMoniter(icb.cb);
}
// END CHECKBOXCONVERTER
*/

function nextImage() {
  cur++;
  if(cur==files.length) cur = 0;
  blendimage('fader','faderimg', files[cur],2000);
  setTimeout("nextImage();", 3000);
}

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++;
		}
	}
}

//change the opacity for different browsers
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 doNothing() {
  //nothing here
}

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 blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 1;
	
	//set the current image as background
  document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

	//make image transparent
	changeOpac(0, imageid);

	setTimeout("doBlending("+timer+","+speed+",'"+imageid+"','"+imagefile+"')", 100);
	
}

function doBlending(timer, speed, imageid, imagefile) {
	//make new image
	document.getElementById(imageid).src = imagefile;
  
  //fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}