/*BlockSliderAction wordt gebruikt om te voorkomen dat tijdens het uitvoeren van een sliderfunctie de andere sliders ook iets gaan doen.*/

var blockSliderAction = false;


/* Flash gedoe */
var movieName = "flashradar";
var sliderdown;
var errorCheck = false;
var error = false;
var frame = 0;

function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  } else {
    return document[movieName]
  }
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded(theMovie) {
  // First make sure the movie's defined.
  if (((typeof(theMovie)) != "undefined") && (errorCheck))
  {
	  // If it is, check how much of it is loaded.
	 if (theMovie.PercentLoaded() == 100) {
	 	errorCheck = false;
	 	return true;
	 }
  }
  else {
    // If the movie isn't defined, it's not loaded.
    errorCheck = true;
    return false;
  }
}


function testError() {
  var errMsg = arguments[0];
	   if((errMsg.search(/error calling/i) != -1) || (errMsg.search(/private/i) != -1))
	   {
	   error = true;
	   }
  }
      

function playframe(thisframe) {
	error = false;
	var frame = thisframe;
	if (movieIsLoaded(thisMovie(movieName)) == true )
	  {
		  thisMovie(movieName).allowDomain = function () 
		  {
		  return true;
		  }
		self.onerror = testError;
			
		if (!error) 
		{ 
		   setTimeout('thisMovie(movieName).GotoFrame(frame)',1);     
		}
	   } 
}


function playmovie() {
  if (movieIsLoaded(thisMovie(movieName))) {
	 thisMovie(movieName).Play();
  }
}


/* Eind flash gedoe */

document.getElementsByClassName = function (needle)
 {
	   var my_array = document.getElementsByTagName('*');
       var retvalue = new Array();
        var i, j;
        for (i = 0, j = 0; i < my_array.length; i++)
       {
           var c = ' ' + my_array[i].className + ' ';
           if (c.indexOf(' ' + needle + ' ') != -1)
              retvalue[j++] = my_array[i];
       }
		 return retvalue;
}



function init () {
	 qInit = document.getElementsByClassName('slider');
	 if (qInit == '') {
		 return;
	 }
	 z = qInit[0].id;
	 var t = 'div#'+z + ' a.close';
	 pijl = document.getElementsBySelector(t);
	 pijl[0].style.display='none';
	 setTimeout('slideOut(z)',50);
} 


function slideIn() { //Deze functie haalt alle tekst weg, sliders omhoog en classnames worden gereset
	divsSlider = document.getElementsByClassName('slider');
	divsText = document.getElementsByClassName('text');
	divsPijltje = document.getElementsByClassName('close');
	divsPijltjeOpen = document.getElementsByClassName('open');
	divsScrollBoxes = document.getElementsByClassName('scroll');
	divsTopmenuActive = document.getElementsByClassName('topmenu active');
	hideAllFlash();
	
	for (i = 0; i < divsSlider.length; i ++ ){
		divsSlider[i].style.marginTop = "-210px";
	}
	for (i = 0; i < divsText.length; i ++ ){
		divsText[i].style.display = "none";
	}
	for (i=0;i<divsScrollBoxes.length; i++) {
	divsScrollBoxes[i].style.marginTop = "0px";
	}
	for (i = 0; i < divsPijltje.length; i ++ ){
		divsPijltje[i].style.display = 'none';
		}
	for (i = 0; i < divsPijltjeOpen.length; i ++ ){
		divsPijltjeOpen[i].style.display = 'block';
		}
	for (i = 0; i< divsTopmenuActive.length; i ++) {
		 divsTopmenuActive[i].className = 'topmenu';
		}
}


function slideInSlow (divname) { //slide de foto in (en verberg de tekst)
	   var theDiv = divname;
	//	timeout = setTimeout("hideFlash(theDiv);",1);
	
	  /* text laten staan toch
	  var s = theDiv.substr(6);
	  s = 'text' + s;
	  text = document.getElementById(s);
	  text.style.display = 'none'; */
	  
	  /* als de text blijft staan blijft het menu ook actief!
	  divsTopmenuActive = document.getElementsByClassName('topmenu active');
	  for (i = 0; i< divsTopmenuActive.length; i ++) {
		 divsTopmenuActive[i].className = 'topmenu';
		} */
	 changeArrow(theDiv); 
	 slideDivSliderIn(theDiv);
	}
	function slideOutSlow(divname) {
	var theDiv = divname;
	changeArrow(theDiv);
	slideDivSliderOut(theDiv);
}


function slideOut(divname) { //slide uit en beeld de tekst af
		
	if (!blockSliderAction) {
		var theDiv= divname;
		var s = theDiv.substr(6);
		s = 'text' + s;
		items = document.getElementsByClassName('topmenu active');
		var r = 'top' + theDiv;
		x = document.getElementById(r);
		var a = 'div#'+divname + ' a.close'; 
		a = document.getElementsBySelector(a);
		for (i = 0; i< items.length; i ++) {
		if (items[i].id != r) {
			slideIn();
		}
		else if ((items[i].id == r) && (a[0].style.display != 'none')){
		slideInSlow(theDiv);
		return false;
			}
		}
		
		slideDivSliderOut(theDiv);
		if (document.getElementById(s)) {
		showText(s);
		}
	
		x.className = 'topmenu active'; 
		changeArrow(theDiv);
	}
}



function slideDivSliderOut(divname) { //animatie slider uit
	div = document.getElementById(divname);
	identiteit = divname;
	playframe(frame);
	if ((!div.style.marginTop) && (identiteit != 'slidergroot')) {
    div.style.marginTop = "-210px";
	    }
    if (!div.style.marginTop) {
	    div.style.marginTop = "-370px";
		    }
	
	if ((parseInt(div.style.marginTop) == -15) && (document.getElementById('player1'))) {
    //alleen als div player1 is gevonden, dan flash laten zien. Voorkomt javascript error
    //showFlash(identiteit);
	timeoutFlash = setTimeout("showFlash(identiteit);",1);
	//Op de een of andere manier doet Safari moeilijk. Een timeout lost dit op wonderbaarlijke wijze op.
	//Probleem op de een of andere manier opgelost.
	}
	if ((parseInt(div.style.marginTop)< 0) && (identiteit != 'slidergroot')) {
	var the_margin = parseInt(div.style.marginTop) + 5;
	div.style.marginTop = the_margin + "px";	
	timeoutFlash = setTimeout("slideDivSliderOut(identiteit);",5);
	frame = 210 + the_margin-3;
	
	}
	else if (parseInt(div.style.marginTop) < 0) {
	var the_margin = parseInt(div.style.marginTop) + 10;
	div.style.marginTop = the_margin + "px";	
	timeout = setTimeout("slideDivSliderOut(identiteit);",5);
	frame = 370 + the_margin+40;	
	
	}
}


function slideDivSliderIn(divname) { //animatie slider in
	div = document.getElementById(divname);
	identiteit = divname;
	if (parseInt(div.style.marginTop) > -200) {
		if (document.getElementById('player1')) {
				timeoutFlash = setTimeout("hideFlash(identiteit);",1);	
				
			}
		}
		//var versionindex=navigator.userAgent.indexOf("Firefox")+8 dit kan nog gebruikt worden
		//if (parseInt(navigator.userAgent.charAt(versionindex))>=1)
	if (identiteit == 'slidergroot') {
		if (parseInt(div.style.marginTop) > -370) {
			var the_margin = parseInt(div.style.marginTop) - 10;
			div.style.marginTop = the_margin + "px";
			timeout = setTimeout("slideDivSliderIn(identiteit);",1);
			frame=370+the_margin-10;
			playframe(frame);
		//	frame --;
			}
		}
	else {
		if (parseInt(div.style.marginTop) > -210) {
			var the_margin = parseInt(div.style.marginTop) - 5;
		div.style.marginTop = the_margin + "px";
		timeout = setTimeout("slideDivSliderIn(identiteit);",1);
		frame=210+the_margin-10;
		playframe(frame);
	//	frame --;
		}
    }
}



function changeArrow(parentdiv) { //verander open / sluit link

	var x = 'div#'+parentdiv + ' a.close';
	pijlclose = document.getElementsBySelector(x);
	var y = 'div#'+parentdiv + ' a.open';
	pijlopen = document.getElementsBySelector(y);
	if (pijlclose[0].style.display == 'none') {
		
	pijlopen[0].style.display = 'none';
	pijlclose[0].style.display = 'block';
	}
	else if (pijlclose[0].style.display == 'block') {
	pijlclose[0].style.display = 'none';
	pijlopen[0].style.display = 'block';
       }
	
}



function showText(divname) {
	
	div = document.getElementById(divname);
	div.style.display = "block";
		//schuif(divname);
}



function CreateControl(DivID, CLSID, ObjectID,
                       WIDTH, HEIGHT, MOVIE)
  { 
	// wordt gebruikt om flash in de pagina te zetten. Door een of ander stom patent zaakje is het object anders niet geactiveerd in IE. Grrrr.
  var d = document.getElementById(DivID);
  d.innerHTML = 
    '<object classid=' + CLSID + ' id=' + ObjectID + 
    ' width=' + WIDTH + ' height=' + HEIGHT +'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" style="z-index:-100;">' +
    '<param name="MOVIE" VALUE=' + MOVIE + '><param name="PLAY" VALUE="false"><param name="LOOP" VALUE="false"><param name="QUALITY" VALUE="high"><param name="SCALE" VALUE="SHOWALL"><embed ID = "' + ObjectID + '" SRC ="' + MOVIE + '" WIDTH="100%" HEIGHT="100%" PLAY="false" LOOP="false" QUALITY="high" SCALE="SHOWALL" swLiveConnect="true" PLUGINSPAGE="http://www.macromedia.com/go/flashplayer"></embed></object>';
}
	
function showFlash(divname) {

	var theDiv = divname;
	var s = theDiv.substr(6);
	
	s = 'player' + s;

	div = document.getElementById(s);
	div.style.display = "block";
	}

function hideFlash(divname) {

	var theDiv = divname;
	var s = theDiv.substr(6);
	
	s = 'player' + s;

	div = document.getElementById(s);
	div.innerHTML = "";
	div.style.display = "none";
	}

function hideAllFlash() {
	divsPlayer = document.getElementsByClassName('player');
	for (i = 0; i<divsPlayer.length; i++) 
	{
		number = i+1;
		name = 'player'+number;
		hideFlash(name);
	}
}
	

function shiftUp(divname,target) {
	blockSliderAction = true;
	div = document.getElementById(divname);
	identiteit = divname;
	targetMargin = target;
	if (!div.style.marginTop) {
    div.style.marginTop = "-58px";
	    }
	currentMargin = parseInt(div.style.marginTop);
	if (currentMargin != target) {
		var the_margin = parseInt(div.style.marginTop) - 4;
		div.style.marginTop = the_margin + "px";	
		timeout = setTimeout("shiftUp(identiteit,targetMargin);",1);
	} else {
	blockSliderAction = false;
	}
}
	
function shiftDown(divname,target) {
	blockSliderAction = true;
	div = document.getElementById(divname);
	identiteit = divname;
	targetMargin = target;
	if (!div.style.marginTop) {
    div.style.marginTop = "-58px";
	    }
	currentMargin = parseInt(div.style.marginTop);
	if (currentMargin != target) {
		var the_margin = parseInt(div.style.marginTop) + 4;
		div.style.marginTop = the_margin + "px";	
		timeout = setTimeout("shiftDown(identiteit,targetMargin);",1);
	} else {
		blockSliderAction = false;
	}
	
}
	
function shiftGalleryUp(divname,fotos) {

	theDiv = document.getElementById(divname);
	if (!theDiv.style.marginTop) {
    theDiv.style.marginTop = "-58px";
	    }
	    
	var margin = parseInt(theDiv.style.marginTop);
	getoondeFoto = -1*(margin + 58)/164 + 1;
	
	if (getoondeFoto != fotos) {
		var target = -1*(getoondeFoto)*164 - 58;
		shiftUp(divname,target);
		getoondeFoto++;
	}
	showGalleryArrow(divname,'pijlDown');
	if (getoondeFoto == fotos)  {
		hideGalleryArrow(divname,'pijlUp');
	} 		
}

function shiftGalleryDown(divname,fotos) {

	theDiv = document.getElementById(divname);
	if (!theDiv.style.marginTop) {
    theDiv.style.marginTop = "-58px";
	    }
	    
	var margin = parseInt(theDiv.style.marginTop);
	getoondeFoto = -1*(margin + 58)/164 + 1;

	if (getoondeFoto != 1) {
		var target = -1*(getoondeFoto-2)*164 - 58;
		shiftDown(divname,target);
		getoondeFoto--;
	}
	showGalleryArrow(divname,'pijlUp');
	if (getoondeFoto == 1)  {
		hideGalleryArrow(divname,'pijlDown');
	} 		
}


function hideGalleryArrow(divname,pijlname) {
	var theDiv = divname;
	var s = theDiv.substr(7);
	var r = pijlname + s;
 	var div = document.getElementById(r);
	div.style.display = 'none';
}

function showGalleryArrow(divname,pijlname) {
    var theDiv = divname;
	var s = theDiv.substr(7);
	var r = pijlname + s;
	var div = document.getElementById(r);
	div.style.display = 'block';
}

function scrollDown(divname) {
	divje = divname;
	divjeObj = document.getElementById(divje);
	var x = 'div#'+divname + ' div.scroll';
	scrollbox = document.getElementsBySelector(x);
    if (!scrollbox[0]) {
	scrollbox = document.getElementsByClassName('scrollgroot');   
	}
	if (!scrollbox[0]) {
	return;
		}
	    
	if (!scrollbox[0].style.marginTop) {
    scrollbox[0].style.marginTop = "0px"
	    }
    var thelength=scrollbox[0].offsetHeight;
    var stop_scroll = (300 - parseInt(thelength));
    if (parseInt(scrollbox[0].style.marginTop)>stop_scroll)
    {
	var the_top = parseInt(scrollbox[0].style.marginTop)  - 5;
    scrollbox[0].style.marginTop = the_top + "px";
    timeoutScroll =  setTimeout("scrollDown(divje);",50);
	}
}


function scrollUp(divname) {
	timeoutScroll =  setTimeout("","");
	divje = divname;
	divjeObj = document.getElementById(divje);
	var x = 'div#'+divname + ' div.scroll';
    scrollbox = document.getElementsBySelector(x);
    if (!scrollbox[0]) {
	scrollbox = document.getElementsByClassName('scrollgroot');   
	}
	if (!scrollbox[0]) {
	return;
		}
	
    if (parseInt(scrollbox[0].style.marginTop) < 0)
    {
    var the_top = parseInt(scrollbox[0].style.marginTop)  + 5;
    scrollbox[0].style.marginTop = the_top + "px";
    timeoutScroll =  setTimeout("scrollUp(divje);",50);
	}
}


function resetScroll(divname, direction) {
    divje = divname;
	divjeObj = document.getElementById(divje);
	var x = 'div#'+divname + ' div.scroll';
    scrollbox = document.getElementsBySelector(x);
    if (!scrollbox[0]) {
	scrollbox = document.getElementsByClassName('scrollgroot');   
	}
	if (direction == 'begin') {
    scrollbox[0].style.marginTop = 0 + "px";
    } else if (direction == 'eind') {
    var thelength=scrollbox[0].offsetHeight;
    var stop_scroll = (300 - parseInt(thelength));   
    scrollbox[0].style.marginTop = stop_scroll + "px"; 
    }
}





/* document.getElementsBySelector(selector)
   - returns an array of element objects from the current document
     matching the CSS selector. Selectors can contain element names, 
     class names and ids and can be nested. For example:
     
       elements = document.getElementsBySelect('div#main p a.external')
     
     Will return an array of all 'a' elements with 'external' in their 
     class attribute that are contained inside 'p' elements that are 
     contained inside the 'div' element which has id="main"

   New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
   See http://www.w3.org/TR/css3-selectors/#attribute-selectors

   Version 0.4 - Simon Willison, March 25th 2003
   -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
   -- Opera 7 fails 
*/

function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector) {
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words 
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }
    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}

function popUp(URL, width,height) {
	day = new Date();
	id = day.getTime();
	optionsString = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height+',left = 50,top = 50';
	window.open(URL, id, optionsString);
//	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=PWIDTH,height=PHEIGHT,left = NaN,top = NaN');");
}


/* That revolting regular expression explained 
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
  \---/  \---/\-------------/    \-------/
    |      |         |               |
    |      |         |           The value
    |      |    ~,|,^,$,* or =
    |   Attribute 
   Tag
*/
