function swapImgRestore () {
  var i,x,a=document.sr;
  for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
    x.src = x.oSrc;
}

function preloadImages () {
  var d = document;
  if (d.images) {
    if (!d.p) d.p = new Array ();
    var i, j = d.p.length, a = preloadImages.arguments;
    for (i = 0; i < a.length; i++) {
      if (a[i].indexOf ("#") != 0) {
        d.p[j] = new Image;
        d.p[j++].src = a[i];
      }
    }
  }
}

function findObj (n, d) { //v4.01
  var p,i,x;
  if (!d) d = document;
  if ((p = n.indexOf ("?")) > 0 && parent.frames.length) {
    d = parent.frames[n.substring (p+1)].document;
    n = n.substring (0,p);
  }
  if (!(x = d[n]) && d.all) x = d.all[n];
  for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
  for (i = 0; !x && d.layers && i < d.layers.length; i++) x = findObj (n, d.layers[i].document);
  if (!x && d.getElementById) x = d.getElementById (n);
  return x;
}

function swapImage() {
  var i, j = 0, x, a = swapImage.arguments;
  document.sr = new Array;
  for (i = 0; i < (a.length - 2); i += 3) {
    if ((x = findObj (a[i])) != null) {
      document.sr[j++] = x;
      if (!x.oSrc) x.oSrc = x.src;
      x.src=a[i+2];
    }
  }
}

function showPortrait (id, gender, ispartner, imgSrc) {
  findObj ('team' + id).src = imgFolder + (gender == 'm' ? 'man' : 'woman') + '_over.gif';
  if (ispartner == 1) findObj ('portraitlarge').src = imgSrc;
  else findObj ('portraitsmall').src = imgSrc;
  findObj ('portraitname').innerHTML = staff[id]['name'];
  findObj ('portraitdescr').innerHTML = staff[id]['function'];
}

function hidePortrait (id, gender, ispartner) {
  findObj ('team' + id).src = imgFolder + (gender == 'm' ? 'man' : 'woman') + '_off.gif';
  if (ispartner == 1) findObj ('portraitlarge').src = imgFolder + 'portrait_empty.gif';
  else findObj ('portraitsmall').src = imgFolder + 'portrait_small_empty.gif';
  findObj ('portraitname').innerHTML = '';
  findObj ('portraitdescr').innerHTML = '';
}

function loaded () {
  if (document.loadRegistry == null) return;
  for (var i in document.loadRegistry) {
    var f = new Function ("a ", " "+document.loadRegistry[i]+" ");
    f ();
  }
}

function registerLoaded (f) {
  if (document.loadRegistry == null) document.loadRegistry = new Array ();
  document.loadRegistry[document.loadRegistry.length] = f;
}

function hideFocusPreview (id) {
	var obj1 = findObj ('imgpreview'+id);
	var obj2 = findObj ('focustitle');
	if (obj1.style) obj1 = obj1.style;
	if (obj2.style) obj2 = obj2.style;
	obj1.display = 'none';
	obj2.display = '';
}

function showFocusPreview (id) {
	var obj1 = findObj ('imgpreview'+id);
	var obj2 = findObj ('focustitle');
	if (obj1.style) obj1 = obj1.style;
	if (obj2.style) obj2 = obj2.style;
	obj2.display = 'none';
	obj1.display = '';
}

function scrollFocus (xPos) {
	window.scrollTo (xPos, 0);
}

function submitContactForm () {
	if (!(findObj ('salutation')[0].checked || findObj ('salutation')[1].checked)) {
		alert (contact_form_error_salutation);
	}
	else if (findObj ('firstname').value == '') {
		alert (contact_form_error_firstname);
		findObj ('firstname').focus ();
	}
	else if (findObj ('name').value == '') {
		alert (contact_form_error_name);
		findObj ('name').focus ();
	}
	else if (findObj ('phone').value == '') {
		alert (contact_form_error_phone);
		findObj ('phone').focus ();
	}
	else if (findObj ('message').value == '') {
		alert (contact_form_error_msg);
		findObj ('message').focus ();
	}
	else {
		if (confirm (contact_form_confirm)) findObj ('contactform').submit ();
	}
}
function showDescriptionPage (destination, current, effect) {
	if (!effect) {
		document.getElementById ('descr_' + current).style.display = 'none';
		document.getElementById ('descr_' + destination).style.display = 'block';
	}
	else if (effect == 'slide') {
		// fix the size before setting absolute
		var c = $('#descr_' + current);
		var d = $('#descr_' + destination);
		c.parent ().css ('width', c.width ());
		c.parent ().css ('height', c.parent ().height ());
		c.parent ().css ('overflow', 'hidden');
		c.css ('width', c.width ());
		d.css ('width', c.width ());
		c.css ('top', '0px');
		d.css ('top', '0px');
		if (current < destination) {
			c.css ('left', '0px');
			d.css ('left', c.width () + 20);
		}
		else {
			c.css ('left', '0px');
			d.css ('left', -1 * (c.width () + 20));
		}
		c.css ('position', 'absolute');
		d.css ('position', 'absolute');
		d.css ('display', 'block');
		// now move it
		if (current < destination) {
			c.animate ({left: -1 * (c.width () + 20)}, 300);
			d.animate ({left: 0}, 300);
		}
		else {
			c.animate ({left: (c.width () + 20)}, 300);
			d.animate ({left: 0}, 300);
		}
	}
	else if (effect == 'fade') {
		$('#descr_' + current).fadeOut (300, function f () { $('#descr_' + destination).fadeIn (300) } );
	}
}
