// JavaScript Document
//Version 0.1 11-June-2008

function getBrowserWidth(){
	if (window.innerWidth){
		return window.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth != 0){
		return document.documentElement.clientWidth; 
	}else if (document.body){
		return document.body.clientWidth;
	}
	return 0;
}
function getBrowserHeight(){
	if (window.innerHeight){
		return window.innerHeight;
	}else if (document.documentElement && document.documentElement.clientHeight != 0){
		return document.documentElement.clientHeight; 
	}else if (document.body){
		return document.body.clientHeight;
	}
	return 0;
}
//********************************************************************
/*				<div style="width: 200px;height: 130px;">
				<div id="slideshow1_1" style="width: 200px;height: 130px;"><a href="../nl/babys/babys.html"><img src="../_img/template_v1/babys/Alexander1.JPG" alt="Baby" width="200" height="130" border="0" /></a></div>
				
				<div id="slideshow1_2" style="display: none;width: 200px;height: 130px;"><a href="../nl/babys/babys.html"><img src="../_img/template_v1/babys/baby_01.jpg" alt="Baby" width="200" height="130" border="0" /></a></div>
				
				<div id="slideshow1_3" style="display: none;width: 200px;height: 130px;"><a href="../nl/babys/babys.html"><img src="../_img/template_v1/babys/Alexander2.jpg" alt="Baby" width="200" height="130" border="0" /></a></div>
				
				<div id="slideshow1_4" style="display: none;width: 200px;height: 130px;"><a href="../nl/babys/babys.html"><img src="../_img/template_v1/babys/jong001.jpg" alt="Baby" width="200" height="130" border="0" /></a></div>							
				
				
				</div>
*/
				
function switch_slides(idPrefix,frame, start_frame, end_frame, delay) {
	return (function() {
		Effect.Fade(idPrefix + frame);
		if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
		setTimeout("Effect.Appear('" + idPrefix + frame + "');", 950);
		setTimeout(switch_slides(idPrefix, frame, start_frame, end_frame, delay), delay + 950);
	})
}
//*******************************************************************
/*
Nested lists where the nesting depth is limited except for one path. For this path are the
items highlighted and have another depth (the depth of the path + 1).

            <ul id="vertMenuFromUL"  class="displayNoneByJS">
              <li><a href="../nl/nieuws/nieuws.html">Nieuws</a></li>
              <li><a href="../nl/onderzoek/onderzoek.html">Het onderzoek</a>
                <ul>
                  <li><a href="../nl/onderzoek/onderzoeksfasen/onderzoeksfasen.html">Onderzoeksfasen</a></li>
                  <li><a href="../nl/onderzoek/onderzoeksresultaten/onderzoeksresultaten.html">Onderzoeksresultaten</a></li>
                  <li><a href="../nl/onderzoek/onderzoeksteam/onderzoeksteam.html">Onderzoeksteam</a></li>
                </ul>
              </li>
            </ul>
			
listHighlightAndCollapse($('vertMenuFromUL'),[]);
listHighlightAndCollapse($('vertMenuFromUL'),[0]);
listHighlightAndCollapse($('vertMenuFromUL'),[1]);
listHighlightAndCollapse($('vertMenuFromUL'),[1,2]);
*/
	function listHighlightAndCollapse(ulElement,arrHighlightIndexes){
		var childElements = ulElement.childElements();
		if(arrHighlightIndexes.length==0){
			//for the current element all sub elements should be displayed but no item should highlighted.
			//no recursive calls should be made if a UL is found
			for (var i = 0; i < childElements.length; i++) {
				if(childElements[i].tagName=="LI"){
					var grandChilds=childElements[i].childElements();
					for (var j = 0; j < grandChilds.length; j++) {
						if(grandChilds[j].tagName!="UL"){
							//NOP just display
						}else{
							//sub lists must not be showed
							grandChilds[j].hide();//the sub menu will not expand further
						}
					}
				}else{
					//since ulElement should be a unordered list, only LI elements are expected
					alert("ulElement should only have LI elements, it now has a "+childElements[i].tagName+" element.");
				}
			}
		}else{
			//for the current element all sub elements should be displayed and some highlighted.
			//recursive calls should be made if a UL is found
			for (var i = 0; i < childElements.length; i++) {
				//alert("i:"+(i+1)+"/"+childElements.length+" level:"+arrHighlightIndexes.length);
				if(childElements[i].tagName=="LI"){
					var grandChilds=childElements[i].childElements();
					for (var j = 0; j < grandChilds.length; j++) {
						//at this stage we go trough every child of the <li>
						if(i==arrHighlightIndexes[0]){
							//this <li> is selected
							if(grandChilds[j].tagName=="UL"){
								//Recursive call the sub menu will expand further
								var arrHighlightIndexesForSubULS= new Array(0);
								if(arrHighlightIndexes.length>1){
									arrHighlightIndexesForSubULS=arrHighlightIndexes.slice(1,arrHighlightIndexes.length);
								}								
								listHighlightAndCollapse(grandChilds[j],arrHighlightIndexesForSubULS);
							}else{
								//The element will display in the selected style
								if(i==arrHighlightIndexes[0]){
									if(grandChilds[j].className=="menu_header"){
										//no operation
									}else{
										//grandChilds[j].style.color = "green";
										grandChilds[j].className = "menu_selected";
									}
								}								
							}						
						}else{
							//this <li> is not selected
							if(grandChilds[j].tagName=="UL"){
								grandChilds[j].hide();//the sub menu will not expand further
							}else{
								//NOP, it will display but not highlighted
							}
						}
					}
				}else{
					//since ulElement should be a unordered list, only LI elements are expected
					alert("ulElement should only have LI elements, it now has a "+childElements[i].tagName+" element.");
				}
			}
			
			//highlight the index for this level
			//alert("setting index "+arrHighlightIndexes[0]+"of"+childElements[arrHighlightIndexes[0]]);
			//childElements[arrHighlightIndexes[0]].style.color = "green";
		}
		return;
	}
//***********************************
	function attachJavaScriptHideCSS(){
		var cssNode = document.createElement('link'); 
		cssNode.setAttribute('rel', 'stylesheet');
		cssNode.setAttribute('type', 'text/css');
		//alert(getRootUrl()+'_styles/hideByJS.css');
		cssNode.setAttribute('href', getRootUrl()+'/_styles/hideByJS.css');
		document.getElementsByTagName('head')[0].appendChild(cssNode); 
	}
//*********************
function getCSSRule(ruleName, deleteFlag) {               // Return requested style obejct
   ruleName=ruleName.toLowerCase();                       // Convert test string to lower case.
   if (document.styleSheets) {                            // If browser can play with stylesheets
      for (var i=0; i<document.styleSheets.length; i++) { // For each stylesheet
         var styleSheet=document.styleSheets[i];          // Get the current Stylesheet
         var ii=0;                                        // Initialize subCounter.
         var cssRule=false;                               // Initialize cssRule. 
         do {                                             // For each rule in stylesheet
            if (styleSheet.cssRules) {                    // Browser uses cssRules?
               cssRule = styleSheet.cssRules[ii];         // Yes --Mozilla Style
            } else {                                      // Browser usses rules?
               cssRule = styleSheet.rules[ii];            // Yes IE style. 
            }                                             // End IE check.
            if (cssRule)  {                               // If we found a rule...
               if (cssRule.selectorText.toLowerCase()==ruleName) { //  match ruleName?
                  if (deleteFlag=='delete') {             // Yes.  Are we deleteing?
                     if (styleSheet.cssRules) {           // Yes, deleting...
                        styleSheet.deleteRule(ii);        // Delete rule, Moz Style
                     } else {                             // Still deleting.
                        styleSheet.removeRule(ii);        // Delete rule IE style.
                     }                                    // End IE check.
                     return true;                         // return true, class deleted.
                  } else {                                // found and not deleting.
                     return cssRule;                      // return the style object.
                  }                                       // End delete Check
               }                                          // End found rule name
            }                                             // end found cssRule
            ii++;                                         // Increment sub-counter
         } while (cssRule)                                // end While loop
      }                                                   // end For loop
   }                                                      // end styleSheet ability check
   return false;                                          // we found NOTHING!
}                                                         // end getCSSRule 

function killCSSRule(ruleName) {                          // Delete a CSS rule   
   return getCSSRule(ruleName,'delete');                  // just call getCSSRule w/delete flag.
}                                                         // end killCSSRule

function addCSSRule(ruleName) {                           // Create a new css rule
   if (document.styleSheets) {                            // Can browser do styleSheets?
      if (!getCSSRule(ruleName)) {                        // if rule doesn't exist...
         if (document.styleSheets[0].addRule) {           // Browser is IE?
            document.styleSheets[0].addRule(ruleName, null,0);      // Yes, add IE style
         } else {                                         // Browser is IE?
            document.styleSheets[0].insertRule(ruleName+' { }', 0); // Yes, add Moz style.
         }                                                // End browser check
      }                                                   // End already exist check.
   }                                                      // End browser ability check.
   return getCSSRule(ruleName);                           // return rule we just created.
} 
//****************************************
/*
Add a css rule so all tags with class="displayNoneByJS" will be hidden
or class="title left displayNoneByJS”
*/
function displayNoneByJS() { 
	//Apply class="displayNoneByJS"
	rule = addCSSRule(".displayNoneByJS");
	if(rule){
		rule.style.display = "none";		
	}
}
/***********************************************/
//Cookie is written by Carlos Reche. It is available on the Scripaculous wiki. 
//It is displayed here because it is not displayed correctly on that page.
//modified by Pieter Schiepers
var Cookie = {
  set: function(name, value, daysToExpire, optPath) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();	
    }
	var path = '';
	if(optPath != undefined){
      path = '; path=' + optPath;		
	}
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire + path);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};
/****************************************************/
