// ### website/js/general.js
// ### Peter van der Meer & Dennis Verspuij
// ### Copyright(c) 2005 SpuyMore Web/Applications

function setSwapZIndex() {// assign startup z-indices if not assigned
  var i,a=setSwapZIndex.arguments;arr=new Array();
  if(findObj(a[0]).style.zIndex==0)
    for(i=0;i<(a.length);i++) {
      arr[i]=findObj(a[i]);
      arr[i].style.zIndex=(i*10+10);
    }
}

function swapZIndex() {				// swap z-index of elements
  var i,a=swapZIndex.arguments;arr=new Array();
  var topl=a.length*10; 			// top level
  var diff=topl-(findObj(a[0]).style.zIndex); 	// difference between current z-index and top level 
  for(i=0;i<(a.length);i++) {
    arr[i]=findObj(a[i]);
    if(arr[i].style.zIndex>10 && diff>0) 			// lower all elements exept for the lowest
      arr[i].style.zIndex-=10;
  }
  arr[0].style.zIndex=topl;			// assign top value to current element
}

function swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var oTimer = null, aTimerArguments;
function swapImageTimed() { //v1.0 (Dennis Verspuij, SpuyMore Web/Applications)
	if (oTimer) clearTimeout(oTimer);
	aTimerArguments = swapImageTimed.arguments;
	oTimer = setTimeout(function(){
		oTimer = null; for(var a=aTimerArguments,i=1;i<(a.length-2);i+=3) swapImage(a[1],a[2],a[3]); aTimerArguments = null;
  }, aTimerArguments[0]);
}

function swapImgRestoreTimed() { //v1.0 (Dennis Verspuij, SpuyMore Web/Applications)
	if (oTimer) clearTimeout(oTimer);
	swapImgRestore();
}

/*** DHTML MENU'S ***/

var dmTimeOut='';
var oActiveMenu='';

function toggleDropdowns(bShow)
{
  // Hides the selects behind the collection and category filters when the info submenu is shown
  var oDropdowns, aFilters;
  if (('all' in window.document) && (oDropdowns = window.document.getElementById('dropdowns')) &&
      ((aFilters = oDropdowns.getElementsByTagName('SELECT')).length >= 3))
  {
    aFilters.item(1).style.visibility = 
    aFilters.item(2).style.visibility = bShow ? 'visible' : 'hidden';
  }
}

function dOpen(menuId) { // (c)SpuyMore v1.0
  oActiveMenu=menuId;
  if((obj=findObj(menuId).style).display!='block')obj.display='block';
  dCloseNow();
}

function dClose() { // (c)SpuyMore v1.0
  dmTimeOut=setTimeout('dCloseNow(true)',300);
}

function dCloseNow(bShowDropDowns) { // (c)SpuyMore v1.0
  toggleDropdowns(bShowDropDowns); // Broekies only
  clearTimeout(dmTimeOut);
  var i=0;
  while(o=findObj(m="hmenu"+i)){ // close horizontal menu's, if not active
    if(oActiveMenu!=m)o.style.display='none';
    i++;
  };
  var i=0;
  while(o=findObj(m="vmenu"+i)){ // close vertical menu's, if not active
    if(oActiveMenu!=m)o.style.display='none';
    i++;
  };
  oActiveMenu='';
}
