var currentItem = Array();

function routePopup() {
  var w = 600;
	var h = 280;
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  popup = window.open("/cms/sites/cmp36/route.php","route", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left="+winl+",top="+wint);
}

function swapElements(elm1, elm2) {
	  var x = elm1.style.left;
		var y = elm1.style.top;
		var display = elm1.style.display;
		
		elm1.style.left = elm2.style.left;
		elm1.style.top = elm2.style.top; 
		elm1.style.display = elm2.style.display;
		
		elm2.style.left = x;
		elm2.style.top = y;
		elm2.style.display = display;
}

// hack to disable drop area for the invisbile element
function findHiddenElm(id) {
  var elm = document.getElementById(id);
	if (elm) return elm;
	var elm = document.getElementById("_"+id);
	if (elm) {
  	elm.id = id;
	  return elm;

	}
}

function hideElement(elm) {
  if (elm.id.charAt(0) != '_') {
    elm.id = "_"+elm.id;
	}
}

function showPrev(id) {
  var currentImg = document.getElementById("foto_"+id+"_"+currentItem[id]);
	if (currentImg && (currentItem[id]>1)) {
    var newImg = findHiddenElm("foto_"+id+"_"+(currentItem[id]-1));
		swapElements(currentImg, newImg);
		currentImg.id = "_"+currentImg.id; 
		currentItem[id]--;		
		showButtons(id,currentItem[id]);		
		hideElement(currentImg);
	}

	ReCalcSizes();
}

function showButtons(id,item) {
  var button = document.getElementById("shownext"+id);
  if (currentItem[id]==7) {
  	button.style.display='none';
  }
  else {
  	button.style.display='block';
  }
	
  var button = document.getElementById("showprev"+id);
  if (currentItem[id]==1) {
  	button.style.display='none';
  }
  else {
  	button.style.display='block';
  }
	
	var text = document.getElementById("showtext"+id);
  if (currentItem[id]==1) {
  	text.style.display='none';
  }
  else {
  	text.style.display='block';
		text.innerHTML = item+"/7";
  }
}

function showNext(id) {
  var currentImg = document.getElementById("foto_"+id+"_"+currentItem[id]);
	if (currentImg && (currentItem[id]<7)) {
    var newImg = findHiddenElm("foto_"+id+"_"+(currentItem[id]+1));
		swapElements(currentImg, newImg);
		currentItem[id]++;
		showButtons(id,currentItem[id]);		
		hideElement(currentImg);
	}
	
	ReCalcSizes();
}


function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function resizeFrame(theSize) {
 if (theSize < document.body.clientHeight - 310) theSize = document.body.clientHeight - 310;

 if (theSize<500) theSize=500;
 var theFrame = document.getElementById("content");
 var heightInc = findPosY(theFrame) - 100;
 theFrame.style.height = theSize+1;

 var line = document.getElementById("leftline2");
 if (line) line.style.height = theSize+heightInc+250;
 
 if (theFrame.Document) {
 		var sidebar = theFrame.Document.getElementById("sidebar");
		if (sidebar) {
			sidebar.style.height = theSize - 20;
			sidebar.style.display = "block";
		}
 }

 var theSeparator = document.getElementById("separator");
 if (theSeparator) theSeparator.style.height = theSize+10;
 var theSeparator = document.getElementById("separator2");
 if (theSeparator) theSeparator.style.height = theSize+10;
 
 var line = document.getElementById("rightline");
 if (line) line.style.height = theSize+heightInc+100;
 var line = document.getElementById("leftline1");
 if (line) line.style.height = theSize+heightInc+100;
 var line = document.getElementById("leftline2");
 if (line) line.style.height = theSize+heightInc+100;

 var line = document.getElementById("projectBar3");
 if (line) line.style.height = theSize+heightInc+20;
 var line = document.getElementById("projectBar");
 if (line) line.style.height = theSize+heightInc+120;

 var line = document.getElementById("left1");
 if (line) line.style.height = theSize+heightInc+110;
 var line = document.getElementById("left2");
 if (line) line.style.height = theSize+heightInc+110;
}

function subitemSummary(itemID) {
  if (itemID) {
  	rootitem = FlatTree[itemID];
		i = 1;
		document.write('<ul>');
		while (i < rootitem.childs.length) {
  		  document.write('<a href="'+rootitem.childs[i].filename+'&xsltfilename=templates/cmp36/xsl/iframe/vacature.xsl">');
				document.write('<li class="text_grey">'+rootitem.childs[i].label+'</li>');
  		  document.write('</a><br>');

				i++;
		}
		document.write('</ul>');
	}	
}

function toonNieuwsbriefArchief() {
	var archief = document.getElementById("nieuwsbriefarchief");
	var link = document.getElementById("nieuwsbriefarchieflink");
	archief.style.display = "block";
	link.style.display = "none";
	return false;
}

function nieuwsarchief(modus) {
 rootitem = CatTree[0].childs[0].childs[6];

 if (rootitem.childs.length) {
  document.write("<br><br><b>Nieuwsarchief:</b><br>");
  for (x=0;x < rootitem.childs.length;x++) {
	 if(modus == 'public') {
    document.write('<a href="-.html' + rootitem.childs[x]['ID'] + '&toptreeitemID=2839&companyID=36&xsltfilename=templates/cmp36/xsl/vervolg_overview.xsl" target="_parent">' + rootitem.childs[x]['label'] + '</a><br>');
	 } else {
    document.write('<a href="javascript:OpenPageByID(' + rootitem.childs[x]['ID'] + ')">' + rootitem.childs[x]['label'] + '</a><br>');
	 }
  }

	if (treeitemID != 2851) {
	 if(modus == 'public') {
	  document.write('<br><a href="Nieuws-2851.php" target="_parent">Terug naar het nieuwsoverzicht</a>');
	 } else {
	  document.write('<br><a href="javascript:OpenPageByID(2851)">Terug naar het nieuwsoverzicht</a>');
	 }
	}
 }
}

function setstatus(){
	if (isNLLang == 1)
	{
		window.status='Zwartwoud projectinrichting - Creatief denken en doen';
	} else {
		window.status='Zwartwoud projectdesign - Innovative concepts and performance';
	}

	return true
}

if (document.layers) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

document.onmouseover=setstatus
document.onmouseout=setstatus


// Nieuw, javascript plaats code:
function buildSWF(file, flashvars, lang, intro)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%" id="home_met_button" align="top">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="' + file + '"/>');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="scale" value="noscale" />');
	document.write('<param name="salign" value="lt" />');
    document.write('<param name="bgcolor" value="#ffffff" />');
    document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="flashvars" value="' + flashvars  + '"showintro=' + intro + '&lang=' + lang + '"  />');
	document.write('<embed src="' + file + '" quality="high" scale="noscale" salign="lt" bgcolor="#ffffff" width="100%" height="100%" name="home_met_button" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function buildSWFDoc(str)
{
	document.write(str);
}
