// 26 juni 2004 Revisie Alphons
// 26 aug 2004 vacaturebank aanpassing for cross-domain-scripting

if(location.hostname.toLowerCase()=="www.tvdebroekhoek.nl" ||
   location.hostname.toLowerCase()=="portaal.tvdebroekhoek.nl")
  if(frames){if(top.frames.length>0)top.location.href=self.location;}

try
{
  strHostName = ""+location.hostname;
  intI = strHostName.indexOf(".tvdebroekhoek.nl");
  strDomain = strHostName.substring(intI);
  if(strDomain==".tvdebroekhoek.nl")
    if(location.href.toLowerCase().indexOf("/ipn/werken_bij_tvdebroekhoek/vacaturebank.asp")>0)
      document.domain = "tvdebroekhoek.nl";
}
catch(e)
{
}

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
{
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where)
		{
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
				this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else
				this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}

	HTMLElement.prototype.innerHTML = function (str)
	{
		var r = this.ownerDocument.createRange();
		r.selectNodeContents(this);
		r.deleteContents();
		var df = r.createContextualFragment(str);
		this.appendChild(df);
		return str;
	}
}
/////////////////////////
function doPrint()
{
	var strUrl = ""+location.href;
	var intI = strUrl.indexOf("?");
	if(intI>0)
		strUrl = strUrl.substring(0,intI);
	window.open(strUrl+"?q=99","_blank","toolbar=0,width=750,height=550,statusbar=0,resizable=1,scrollbars=1");
}

function GenerateMenus()
  {
  var strTmp,intI,intJ;
  intSubMenu = 0;
  objData = document.getElementById("MyData");
  colMenus = objData.childNodes;
  strTmp = '';
  for(intI=0;intI<colMenus.length;intI++)
    {
    objMenu = colMenus.item(intI);
    strTmp += '<table class="Menu" id="Menu'+(intI+1)+'" style="display:none;" cellpadding="0" cellspacing="0">\n';
    strTmp += '<tr><td colspan="2" id="GroenMenuLijntje"></td></tr>';
    for(intJ=0;intJ<objMenu.childNodes.length;intJ++)
      {
      objChild = objMenu.childNodes.item(intJ);
      strTmp += '<tr class="ZL">\n';
      if(objChild.tagName=="DIV")
        {
        strTmp += '  <td onmouseover="doMenuOver(this)" onmouseout="doMenuOut(this)">&nbsp;'+objChild.title+'&nbsp;</td>\n';
        strTmp += '  <td onmouseover="doMenuOver(this)" onmouseout="doMenuOut(this)" width="20" align="right" id="S'+(intSubMenu+1)+'"><img src="' + strMENU_GIF + '">&nbsp;&nbsp;</td>\n';
        intSubMenu++;
        }
      if(objChild.tagName=="A")
        {
        strTmp += '  <td onmouseover="doMenuOver(this)" onmouseout="doMenuOut(this)" onclick="location.href=\''+objChild.href+'\'">&nbsp;'+objChild.innerHTML+'&nbsp;&nbsp;</td>\n';
        strTmp += '  <td onmouseover="doMenuOver(this)" onmouseout="doMenuOut(this)" width="20" align="right">&nbsp;</td>\n';
        }
      if(objChild.tagName=="HR")
        {
        strTmp += '  <td colspan="2"><hr></td>\n';
        }
      }
    strTmp += '<tr><td colspan="2" id="GroenMenuLijntje"></td></tr>';
    strTmp += '</table>\n';
    }
//alert(strTmp);
  return strTmp;
  }

function GenerateSubMenus()
  {
  var strTmp,intI,intJ;
  intSubMenu = 0;
  objData = document.getElementById("MyData");
  colMenus = objData.childNodes;
  strTmp = '';
  for(intI=0;intI<colMenus.length;intI++)
    {
    objMenu = colMenus.item(intI);
    for(intJ=0;intJ<objMenu.childNodes.length;intJ++)
      {
      objChild = objMenu.childNodes.item(intJ);
      if(objChild.tagName=="DIV")
        {
        intL = objChild.childNodes.length;
        strTmp += '<table class="SubMenu" id="SubMenu'+(intSubMenu+1)+'" style="display:none;" cellpadding="0" cellspacing="0">\n';
        strTmp += '<tr><td id="GroenMenuLijntje"></td></tr>';
        for(intK=0;intK<intL;intK++)
          {
          objSubChild = objChild.childNodes.item(intK);
          strTmp += '<tr>\n';
          if(objSubChild.tagName=="A")
            {
            strTmp += '  <td onmouseover="doMenuOver(this)" onmouseout="doMenuOut(this)" onclick="location.href=\''+objSubChild.href+'\'">&nbsp;'+objSubChild.innerHTML+'&nbsp;</td>\n';
            }
          if(objSubChild.tagName=="HR")
            {
            strTmp += '  <td><hr></td>\n';
            }
          strTmp += '</tr>\n';
          }
        strTmp += '<tr><td id="GroenMenuLijntje"></td></tr>';
        strTmp += '</table>\n';
        intSubMenu++;
        }
      }
    }
//alert(strTmp);
  return strTmp;
  }

function GenerateAllMenus()
  {
  var strTmp = '<div id="AllMenus">';
  strTmp += GenerateMenus();
  strTmp += GenerateSubMenus();
  strTmp += '</div>';
  document.body.insertAdjacentHTML("beforeEnd",strTmp);
  //document.getElementById("AllMenus").onmouseover = doMenuOver;
  //document.getElementById("AllMenus").onmouseout = doMenuOut;
  }

function HideMenu()
  {
  var colMenus = document.getElementById("MyData").childNodes;
  var intI;
  for(intI=0;intI<colMenus.length;intI++)
    document.getElementById("Q"+(intI+1)).className = "C0";
  try { objMenu.style.display="none"; } catch(e) {}
  }

function HideSubMenu()
  {
  try { objSubMenu.style.display="none"; } catch(e) {}
  }

function HideAllMenus()
  {
  try { window.clearTimeout(intHideTimer); } catch(e) {}
  try { window.clearTimeout(intSubmenuTimer); } catch(e) {}
  HideSubMenu();
  HideMenu();
  }

function doXY(objE)
  {
  var intX=0;
  var intY=0;
  while(objE!=null)
    {
    intX += objE.offsetLeft;
    intY += objE.offsetTop;
    objE = objE.offsetParent;
    }
  var objE = new Object();
  objE.x = intX;
  objE.y = intY;
  return objE;
  }


function MyBrowserCheck()
{
	var b = navigator.appName;
	if (b == "Netscape") this.b = "NS";
	else if (b == "Microsoft Internet Explorer") this.b = "IE";
	else this.b = b;
	this.v = parseInt(navigator.appVersion);
	this.NS = (this.b == "NS" && this.v>=4);
	this.NS4 = (this.b == "NS" && this.v == 4);
	this.NS5 = (this.b == "NS" && this.v == 5);
	this.IE = (this.b == "IE" && this.v>=4);
	this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
	this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	if (this.IE5 || this.NS5) this.VER5 = true;
	if (this.IE4 || this.NS4) this.VER4 = true;
	this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
	this.min = (this.NS||this.IE);
}

function InitSmallBalls(objPositie)
{
	if(!document.getElementById("dot1"))
		return;

	var intI;
	SPACING = 16; // distance ball to ball
	LEADERTIME = 10;
	FOLLOWTIME = 10;
	//set st styles in variables
	styleDot1 = (is.VER5) ? document.getElementById("dot1").style : (is.NS) ? document.layers["dot1"] : document.all["dot1"].style;
	styleDot2 = (is.VER5) ? document.getElementById("dot2").style : (is.NS) ? document.layers["dot2"] : document.all["dot2"].style;
	styleDot3 = (is.VER5) ? document.getElementById("dot3").style : (is.NS) ? document.layers["dot3"] : document.all["dot3"].style;
	styleDot4 = (is.VER5) ? document.getElementById("dot4").style : (is.NS) ? document.layers["dot4"] : document.all["dot4"].style;
	styleDot5 = (is.VER5) ? document.getElementById("dot5").style : (is.NS) ? document.layers["dot5"] : document.all["dot5"].style;
	
	arStyle = new Array(styleDot1,styleDot2,styleDot3,styleDot4,styleDot5);
	arId = new Array();

	//set start positions
	for (intI=0;intI<5 ; intI++)
	{
		arId[intI] = -1; // Niet aktie
		if (intI == 0)
		{
			arStyle[intI].left = objPositie.x+5;
			arStyle[intI].top = objPositie.y-15;
		}
		else
		{
			arStyle[intI].left = parseInt(arStyle[intI-1].left) + SPACING;		
			arStyle[intI].top = objPositie.y-15;
		}
		arStyle[intI].display=""; // zichtbaar maken
	}	
}

function MoveSmallBalls(targetpos)
{
	if(!document.getElementById("dot1"))
		return;

	var intI,intTargetpos;
	for(intI=0;intI<5;intI++)
	{
		clearInterval(arId[intI]);
		arId[intI] = -1;
	}

	if (targetpos < parseInt(arStyle[0].left))
	{ // move all left
		intTargetpos = 1*targetpos;
		arId[0] = setInterval("LeadSmallBalls(" +intTargetpos + ",arStyle[0],-1)", LEADERTIME);
		arId[1] = setInterval("FollowSmallBalls(arStyle[1], arStyle[0],1,-1)", FOLLOWTIME);
		arId[2] = setInterval("FollowSmallBalls(arStyle[2], arStyle[1],2,-1)", FOLLOWTIME);
		arId[3] = setInterval("FollowSmallBalls(arStyle[3], arStyle[2],3,-1)", FOLLOWTIME);
		arId[4] = setInterval("FollowSmallBalls(arStyle[4], arStyle[3],4,-1)", FOLLOWTIME);
		return;
	}

	if (targetpos > parseInt(arStyle[4].left))
	{ // move all right
		intTargetpos = 1*targetpos+4*SPACING+7; // Most right dot is leader
		arId[0] = setInterval("LeadSmallBalls(" +intTargetpos + ",arStyle[4],1)", LEADERTIME);
		arId[1] = setInterval("FollowSmallBalls(arStyle[3], arStyle[4],1,1)", FOLLOWTIME);
		arId[2] = setInterval("FollowSmallBalls(arStyle[2], arStyle[3],2,1)", FOLLOWTIME);
		arId[3] = setInterval("FollowSmallBalls(arStyle[1], arStyle[2],3,1)", FOLLOWTIME);
		arId[4] = setInterval("FollowSmallBalls(arStyle[0], arStyle[1],4,1)", FOLLOWTIME);
		return;
	}
}

function LeadSmallBalls(intTargetpos, styleA, intDirection)
{		
	var intAdvance;
	var intDiff = Math.abs(intTargetpos - parseInt(styleA.left));
	if(intDiff==0)
	{ // Ready
		clearInterval(arId[0]);
		arId[0]=-1;
	}
	else
	{ // Go direction, minimum 1 px.
		intAdvance = Math.max(1,Math.floor(intDiff/8));
		styleA.left = parseInt(styleA.left) + intDirection*intAdvance;
	}
}

function FollowSmallBalls(followdot, leaddot, intId, intDirection)
{
	var intAdvance;
	var intDiff = Math.abs(parseInt(leaddot.left) - parseInt(followdot.left))-SPACING;
	if(intDiff<=2)
	{
		if(arId[intId-1] == -1)
		{
			clearInterval(arId[intId]);
			arId[intId] = -1;
		}
	}
	else
	{
		intAdvance = Math.max(1,Math.floor(intDiff/8));
		followdot.left = parseInt(followdot.left) + intDirection*intAdvance;
	}
}




function doMove(intPos)
  {
  var objE;
  if(intPos==0) // init
    objE = document.getElementById("Q1");
  else
    objE = document.getElementById("Q"+intPos);

  var Positie = doXY(objE);

  var intNewPosX = Positie.x+5;
  var intNewPosY = Positie.y-15;

  HideAllMenus();

  if(intPos==0)
    {
    InitSmallBalls(Positie)
    }
  else
    {
    try { HideFlash(); } catch(e) {}
    document.getElementById("Q"+intPos).className="C1";
    objMenu = document.getElementById("Menu"+intPos);
    objMenu.style.left=Positie.x;
    objMenu.style.top =Positie.y+30;
    objMenu.style.display="";
    MoveSmallBalls(intNewPosX);
    }
  }

function doSubMenu()
  {
  try
    {
    objOldSubMenu=objSubMenu;
    objSubMenu=objNewSubMenu;
    objSubMenu.style.display="";
    if(objSubMenu!=objOldSubMenu) objOldSubMenu.style.display="none";
    }
  catch(e)
    {
    }
  }

function doMenuOver(objE)
  {
  try { window.clearTimeout(intHideTimer); } catch(e) {}
  try { window.clearTimeout(intSubmenuTimer); } catch(e) {}
  if(objE.tagName!="TD") return;

  if(objE.innerHTML!="")
    {
    objTr = objE.parentNode;
    objTr.className = "ZH";
    if(objTr.getElementsByTagName("TD").length>1)
      {
      objTd = objTr.getElementsByTagName("TD").item(1);
      if(objTd.id.charAt(0)=="S")
        {
        Positie = doXY(objTd);
        objNewSubMenu = document.getElementById("SubMenu"+objTd.id.substring(1));
        objNewSubMenu.style.left = Positie.x+14;
        objNewSubMenu.style.top  = Positie.y;
        intSubmenuTimer = window.setTimeout("doSubMenu()",250);
        }
     else
        {
        HideSubMenu();
        }
      }
    }
  }

function doMenuOut(objE)
  {
  if(objE.tagName=="TD")
    {
    objTr = objE.parentNode;
    objTr.className = "ZL";
    }
  intHideTimer = window.setTimeout("HideAllMenus()",500);
  }

function doMyButtons()
  {
  HideAllMenus();
  var objE = event.srcElement;
  if(objE.id.charAt(0)=="Q")
    doMove(1*objE.id.substring(1));
  }

function doMyButtonsNS(objE)
  {
  HideAllMenus();
  if(objE.id.charAt(0)=="Q")
    doMove(1*objE.id.substring(1));
  }


function doExtra(intPos)
{
  var objE = document.getElementById("Q"+intPos);
  var Positie = doXY(objE);
  var intNewPosX = Positie.x+5;
  MoveSmallBalls(intNewPosX);
}

function doInitMove()
  {
  if(!document.getElementById("MyButtons"))
    return;
  var intI,strUrl,colA,colDiv,objA,objDiv,objMenu;
  doMove(0);
  strUrl = ""+location.href;
  strUrl = strUrl.replace(/\/\.\//g,"\/"); // Tridion Bug
  intI=strUrl.indexOf("?");
  if(intI>0) strUrl = strUrl.substring(0,intI);
  colA = document.getElementById("MyData").getElementsByTagName("A");
  for(intI=0;intI<colA.length;intI++)
    {
    objA = colA.item(intI);
    if(objA.href.replace(/\/\.\//g,"\/")==strUrl)
      {
      objMenu = objA.parentNode;
      if(objMenu.parentNode.id!="MyData")
        objMenu = objMenu.parentNode;
      colDiv = document.getElementById("MyData").childNodes;
      for(intI=0;intI<colDiv.length;intI++)
        {
        objDiv = colDiv.item(intI);
        if(objDiv==objMenu)
          {
          doExtra(intI+1);
          return;
          }
        }
      break;
      }
    }
  }

function doVulTitles()
  {
  var intI,strTmp="";
  var colMenus = document.getElementById("MyData").childNodes;
  for(intI=0;intI<colMenus.length;intI++)
    {
    if(intI>0)
      strTmp += '<span class="C2">|</span>';
    strTmp += '<span id="Q'+(intI+1)+'" class="C0" onmouseover="doMyButtonsNS(this)">'+colMenus.item(intI).title+'</span>';
    }
  document.getElementById("MyButtons").innerHTML = strTmp;
  }

function doNormalOver()
  {
  if(!document.getElementById("MyButtons"))
    return;
  doVulTitles();
  is = new MyBrowserCheck();
  GenerateAllMenus();
  objMenu = null;
  objSubMenu = null;
  doInitMove();
  document.getElementById("MyButtons").style.visibility="visible";
  if(document.all)
    document.getElementById("MyButtons").onmouseover = doMyButtons;
  }

function doInit()
  {
  is = new MyBrowserCheck();
  try { doNormalOver(); } catch(e) {}
  try { PrivateInit(); } catch(e) {}
  try { PrivateInit2(); } catch(e) {}
  }
window.onload = doInit;
window.onresize = doInitMove;
