
function loadEmbed(frame)
{
	var link = '';
  if ( frame == 'login' )
  	link = '/login.php';
	var embedDiv = document.getElementById('iframeHost');
  if ( embedDiv != null )
  {
  	window.overlayHideFunction = overlayHide;
  	window.test = 'overlayHide';
		embedDiv.innerHTML = '<iframe width="300" height="90" src="' + link + '" frameborder="0"></iframe>';
    overlayShow(-1);
    embedDiv.style.display = 'block'; 
  }
}

function play(obj)
{
	var mediaCaption = '';
  var mediaDescription = '';
  var mediaValue = '';
	var playerDiv = document.getElementById('jwPlayer');
	if ( obj != null && playerDiv != null )
  {
  	// read special values
    for ( i=0; i<obj.children.length; i++ )
    {
    	if ( obj.children.item(i).name == 'mediaCaption' )
      {
				mediaCaption = obj.children.item(i).value;
        continue;
      }
    	if ( obj.children.item(i).name == 'mediaDescription' )
      {
				mediaDescription = obj.children.item(i).value;
        continue;
      }
      if ( obj.children.item(i).name == 'mediaValue' )
      {
				mediaValue = obj.children.item(i).value;
        continue;
      }      
    } // for
    document.getElementById('overlayCaption').innerHTML = mediaCaption;
    document.getElementById('overlayInfo').innerHTML = mediaDescription;
    
  	jwplayer('mediaspace').setup({
     'flashplayer': '/includes/player.swf',
     'file': mediaValue,
     'controlbar': 'bottom'
     , 'width': '470'
     , 'height': '320'
    });
    overlaySetMediaCntr(470, 360);
    playerDiv.style.display = 'block';    
  	overlayShow(1);
    jwplayer('mediaspace').play();

  }
}

function playYoutube(obj)
{
var mediaCaption = '';
  var mediaDescription = '';
  var mediaValue = '';
	var playerDiv = document.getElementById('youtubePlayer');
	if ( obj != null && playerDiv != null )
  {
  	// read special values
    for ( i=0; i<obj.children.length; i++ )
    {
    	if ( obj.children.item(i).name == 'mediaCaption' )
      {
				mediaCaption = obj.children.item(i).value;
        continue;
      }
    	if ( obj.children.item(i).name == 'mediaDescription' )
      {
				mediaDescription = obj.children.item(i).value;
        continue;
      }
      if ( obj.children.item(i).name == 'mediaValue' )
      {
				mediaValue = obj.children.item(i).value;
        continue;
      }      
    } // for
    document.getElementById('overlayCaption').innerHTML = mediaCaption;
    document.getElementById('overlayInfo').innerHTML = mediaDescription;

  	playerDiv.innerHTML = '<iframe width="420" height="315" src="' + mediaValue + '" frameborder="0" allowfullscreen></iframe>';
    overlaySetMediaCntr(420, 354);
    playerDiv.style.display = 'block';
  	overlayShow(2);
  }
}

function overlayFade(InorOut)
{
	if ( InorOut )
  {
  	window.overlayValue += 10;
    if ( window.overlayValue != 60 )
    	window.overlayTimer = setTimeout('overlayFade(1)' , 30);
  } else {
  	window.overlayValue -= 10;
    if ( window.overlayValue != 0 )
    	window.overlayTimer = setTimeout('overlayFade(0)' , 30);
    else {
    	window.overlayDiv.style.display = 'none';
      
    }
 
  }
  if ( window.browser.ie )
	  window.overlayDiv.style.filter = 'alpha(opacity=' + window.overlayValue + ')';
  else
	  window.overlayDiv.style.opacity = '0.' + window.overlayValue;
}

function overlayHide()
{
	window.overlayDiv = document.getElementById('overlay');
	if ( window.overlayDiv != null ) 
	{
  	mediaDiv = document.getElementById('mediaCntr');
		
    if ( mediaDiv != null ) 
		mediaDiv.style.display = 'none';
    switch ( window.showingPlayer )
    {
    	case 1: 
      {
      	var playerDiv = document.getElementById('jwPlayer');
			  if ( playerDiv != null )
			  {
          playerDiv.style.display = 'none';
        }
		  	jwplayer('mediaspace').stop();
      	break;
      }
      case 2:
      {
      	var playerDiv = document.getElementById('youtubePlayer');
			  if ( playerDiv != null )
			  {
			  	playerDiv.innerHTML = '';
          playerDiv.style.display = 'none';
        }
      	break;
      }
      case -1:
      {
      	var playerDiv = document.getElementById('iframeHost');
			  if ( playerDiv != null )
			  {
			  	playerDiv.innerHTML = '';
          playerDiv.style.display = 'none';
        }
      	break;
      }
    } // switch
  	window.overlayTimer = setTimeout('overlayFade(0)' , 30);
  }
}

function overlaySetMediaCntr(Width, Height)
{
	mediaDiv = document.getElementById('mediaCntr');
	if ( mediaDiv != null ) 
	{
  	//alert(mediaDiv.style.marginLeft);	
  	mediaDiv.style.width = Width;
  	mediaDiv.style.height = Height;
    mediaDiv.style.marginLeft = -(Width / 2) + 'px';
    mediaDiv.style.marginTop = -(Height / 2) + 'px';
    mediaDiv.style.display = 'block';
  }
}

function overlayShow(typePlayer)
{	
	clearTimeout(window.overlayTimer);
	window.showingPlayer = typePlayer;
	window.overlayDiv = document.getElementById('overlay');
	if ( window.overlayDiv != null ) 
	{
  	if ( window.browser.ie )
	  	window.overlayDiv.style.filter = 'alpha(opacity=0)';
    else
	  	window.overlayDiv.style.opacity = '0.0';
    
  	window.overlayDiv.style.display = 'block';
    window.overlayValue = 0;
    window.overlayTimer = setTimeout('overlayFade(1)' , 30);
  }
  /*
	var _div = document.getElementById('overlayCntr');
	if ( _div != null ) 
	{
		window.showingPlayer = typePlayer;
  	_div.style.visibility = 'visible';
  }*/
}

function slideImage()
{	
	slideX = 225 * ( 1.0 / (1.0+(1.0/0.001) * Math.exp(-slideT*0.7)) ) + 0.5;
	slideT++;
posX = leftOffset - slideX;
  for ( i=0; i<4; i++ )
  {
    //window.carouselImages[i] = _div.children.item(i);	
 	window.carouselImages[i].style.left = Math.round(-slideX) + (225 * i) + "px";
  }
    
  if ( slideX >= 225 )
  {
  	slideX = 0;
    slideT = 0;
 	leftOffset -= 225;
    saved = window.carouselImages[0];
    for ( i=0; i<window.carouselImages.length-1; i++ )
    	window.carouselImages[i] = window.carouselImages[i+1];
    window.carouselImages[window.carouselImages.length-1] = saved;
	  //if ( leftOffset == -1125 )
  	  //	leftOffset = 0;
	window.slidetimer = setTimeout('slideImage()' , 3000);
  } else
   window.slidetimer = setTimeout('slideImage()' , 30);
    
    
    
    /*
  	slideX = 225 * ( 1.0 / (1.0+(1.0/0.001) * Math.exp(-slideT*0.7)) ) + 0.5;
    slideT++;
	posX = leftOffset - slideX;
		_div.style.left = posX + "px";
    if ( slideX >= 225 )
    {
    	slideX = 0;
      slideT = 0;
   	leftOffset -= 225;
	    if ( leftOffset == -1125 )
  	  	leftOffset = 0;
		window.slidetimer = setTimeout('slideImage()' , 3000);
    } else
   	window.slidetimer = setTimeout('slideImage()' , 30);
    */
		
	//clearTimeout( window.slidetimer );
}

function startCarousel()
  {
  	var _div = document.getElementById('div_carousel');
    if ( _div != null ) 
    {
    	if ( _div.children.length > 3 )
      {
    		window.carouselImages = new Array();
      	for ( i=0; i<_div.children.length; i++ )
      	{
  				window.carouselImages[i] = _div.children.item(i);
          //window.carouselImages[i].style.position = "absolute";
      	}	
        window.slidetimer = setTimeout('slideImage()' , 3000);
			}
    } 
  }

function submitForm(formName)
{
 	oForm = document.getElementById(formName);
	if ( oForm ) 
  {
	 	// We found the form, now process fields
	 	var oItem;
	 	var oFocusItem;
	 	oFocusItem = 0;
		for ( i=1;i<oForm.elements.length;i++ ) 
    {
	 	 	oItem = oForm.elements.item(i);
			if ( oItem.id.substr(0, 4) == 'man_' )
				if ( oItem.value == '' ) 
        {
					oItem.style.backgroundColor = '#fcffc6';
					if ( !oFocusItem )
					 	oFocusItem = oItem;
				}
	 	}
	 	if ( oFocusItem )
		 	oFocusItem.focus();
		else
		 	oForm.submit();
	}
}  	

//#### BEGIN SEARCHFORM FUNCTIONS ####//
document.ready = (
	function()
	{   
  	var sDefaultText = "Zoek"; 
  	var sErrorText = "Vul meer dan 2 letters in!"; 
    alert('1');
  /*//add events to form in subcontent area
  $(".questionform").each(function(){   
    prepareSearchForm("questionform");
  });
    
  //add events to form in maincontent area
  $(".mainsearchform").each(function(){
    prepareSearchForm("mainsearchform");
  });
    
  //function to prepare a form, attach events
  function prepareSearchForm(theForm){          
      
    //add default text to field
    setDefaultText(theForm);
      
    //attach onfocus event to input field
    $("#" + theForm + "_q").bind("focus",function(){        
      clearField(theForm);
      updateOtherForm(theForm);
    });

     //attach onblur event to input field
    $("#" + theForm + "_q").bind("blur",function(){        
      setDefaultText(theForm);
      updateOtherForm(theForm);
    });

    //attach preSubmit function to form
    $("#" + theForm).bind("submit",function(){        
      return checkSearchQuery(theForm);
    });
  }
    
  //function to clear the query field
  function clearField(theForm){
    var searchQuery = $("#" + theForm + "_q").attr("value");
      
    //only creal the field when it still contains the default text
    if(searchQuery == sDefaultText){       
      $("#" + theForm + "_q").attr("value","");
    }
  }
    
  //function to set the default value in the query field
  function setDefaultText(theForm){     
    //insert the default text to the field when its value is empty
    if($("#" + theForm + "_q").attr("value") == ""){
      $("#" + theForm + "_q").attr("value",sDefaultText);
    }
  }
    
  //function to validate search query before submit
  function checkSearchQuery(theForm){
    var searchQuery = $("#" + theForm + "_q").attr("value");
    if(searchQuery == sDefaultText){
      //field has its default value; display error text and don't submit the form
      $("#" + theForm + "_error").text(sErrorText);
      return false;
    }else if(searchQuery.length < 3){
      //field value is to short for the search; display error text and dont't submit the form
      $("#" + theForm + "_error").text(sErrorText);
      return false;
    }else{
      //field value is ok for search; submit form
      return true;
    }
  }

  function updateOtherForm(currentForm){
    var currectValue = $("#" + currentForm + "_q").attr("value");;
    switch(currentForm){
      case "questionform":
        var otherForm = "mainsearchform";
        break;
      case "mainsearchform":
        var otherForm = "questionform";
        break;
    }
    $("#" + otherForm + "_q").attr("value",currectValue);
  }*/
});
/*
//#### BEGIN SEARCHFORM FUNCTIONS ####//
$(document).ready(function(){   
  var sDefaultText = "Zoek"; 
  var sErrorText = "Vul meer dan 2 letters in!"; 
    
  //add events to form in subcontent area
  $(".questionform").each(function(){   
    prepareSearchForm("questionform");
  });
    
  //add events to form in maincontent area
  $(".mainsearchform").each(function(){
    prepareSearchForm("mainsearchform");
  });
    
  //function to prepare a form, attach events
  function prepareSearchForm(theForm){          
      
    //add default text to field
    setDefaultText(theForm);
      
    //attach onfocus event to input field
    $("#" + theForm + "_q").bind("focus",function(){        
      clearField(theForm);
      updateOtherForm(theForm);
    });

     //attach onblur event to input field
    $("#" + theForm + "_q").bind("blur",function(){        
      setDefaultText(theForm);
      updateOtherForm(theForm);
    });

    //attach preSubmit function to form
    $("#" + theForm).bind("submit",function(){        
      return checkSearchQuery(theForm);
    });
  }
    
  //function to clear the query field
  function clearField(theForm){
    var searchQuery = $("#" + theForm + "_q").attr("value");
      
    //only creal the field when it still contains the default text
    if(searchQuery == sDefaultText){       
      $("#" + theForm + "_q").attr("value","");
    }
  }
    
  //function to set the default value in the query field
  function setDefaultText(theForm){     
    //insert the default text to the field when its value is empty
    if($("#" + theForm + "_q").attr("value") == ""){
      $("#" + theForm + "_q").attr("value",sDefaultText);
    }
  }
    
  //function to validate search query before submit
  function checkSearchQuery(theForm){
    var searchQuery = $("#" + theForm + "_q").attr("value");
    if(searchQuery == sDefaultText){
      //field has its default value; display error text and don't submit the form
      $("#" + theForm + "_error").text(sErrorText);
      return false;
    }else if(searchQuery.length < 3){
      //field value is to short for the search; display error text and dont't submit the form
      $("#" + theForm + "_error").text(sErrorText);
      return false;
    }else{
      //field value is ok for search; submit form
      return true;
    }
  }

  function updateOtherForm(currentForm){
    var currectValue = $("#" + currentForm + "_q").attr("value");;
    switch(currentForm){
      case "questionform":
        var otherForm = "mainsearchform";
        break;
      case "mainsearchform":
        var otherForm = "questionform";
        break;
    }
    $("#" + otherForm + "_q").attr("value",currectValue);
  }
});

*/

/* Gallery */
function createGalleryBox()
    {
    	var oDiv;
      var oImg;
    	var oGalleryDiv = document.createElement('div');
			oGalleryDiv.id = 'galleryBox';
      oGalleryDiv.style.left = '0px';
      oGalleryDiv.style.top = '62px';
      oOuterDiv = oGalleryDiv.appendChild(document.createElement('div'));
      oOuterDiv.id = 'outerImageContainer';
      oOuterDiv.style.height = '500px';
      oOuterDiv.style.width = '742px';
      
      oDiv = oOuterDiv.appendChild(document.createElement('div'));
      oDiv.id = 'imageContainer';
      oImg = oDiv.appendChild(document.createElement('img'));
      oImg.id = 'galleryImage';
      oImg.onload = imageLoaded;
      //oImg.src = 'http://www.certhon.nl/photos/1/125/image62-125-22.jpg';
      oDiv = oDiv.appendChild(document.createElement('div'));
      oDiv.id = 'hoverNav';
      document.prevButton = oDiv.appendChild(document.createElement('a'));
      document.prevButton.id = 'prevLink';
      document.prevButton.href = 'javascript:prevImage();';
      //oAnchor.style.display = 'none';
      document.prevButton.style.height = '480px';
      document.nextButton = oDiv.appendChild(document.createElement('a'));
      document.nextButton.id = 'nextLink';
      document.nextButton.href = 'javascript:nextImage();';
      //oAnchor.style.display = 'none';
      document.prevButton.style.height = '480px';
      
      oDiv = oOuterDiv.appendChild(document.createElement('div'));
      oDiv.id = 'imageDataContainer';
      oDiv.style.width = '100%'; //'742px';
      oDataDiv = oDiv.appendChild(document.createElement('div'));
      oDataDiv.id = 'imageData';
      oDiv = oDataDiv.appendChild(document.createElement('div'));
      oDiv.id = 'imageDetails';
      oSpan = oDiv.appendChild(document.createElement('span'));
      oSpan.id = 'caption';
      oSpan.appendChild(document.createTextNode(" This text was added to the DIV."));
      oSpan = oDiv.appendChild(document.createElement('span'));
      oSpan.id = 'numberDisplay';
      oSpan.appendChild(document.createTextNode("Afbeelding 1 van 10"));
      
      oDiv = oDataDiv.appendChild(document.createElement('div'));
      oDiv.id = 'bottomNov';
      oAnchor = oDiv.appendChild(document.createElement('a'));
      oAnchor.id = 'bottomNavClose';
      oAnchor.href = 'javascript:hideGallery();';
      oImg = oAnchor.appendChild(document.createElement('img'));
      oImg.src = 'http://www.wvds.nl/images/closelabel.gif';
      //oDiv.appendChild(document.createTextNode(" This text was added to the DIV."));
      
      document.body.appendChild(oGalleryDiv); 
    }
 
 		function imageLoaded()
    {
    	var oImg = document.getElementById('galleryImage');
      
    	var oDiv;
      oDiv = document.getElementById('outerImageContainer');
      oDiv.style.height = oImg.height + 20 + 'px';
      oDiv.style.width = oImg.width + 20 + 'px';
      
    	oDiv = document.getElementById('imageContainer');
    	oDiv.style.visibility = 'visible';
    }
    
    function nextImage()
    {
      if ( document.imageIndex == undefined)
        document.imageIndex = 0;
      document.imageIndex++;
      if ( document.imageIndex >= images.length )
        document.imageIndex = 0;
      // Get image
      updateImage();
    }

    function prevImage()
    {
      if ( document.imageIndex == undefined)
        document.imageIndex = 0;
      document.imageIndex--;
      if ( document.imageIndex < 0 )
        document.imageIndex = images.length-1;
      // Get image
      updateImage();
    }

    function hideGallery(index)
    {
    	var oDiv = document.getElementById('galleryBox');
      oDiv.style.display = 'none';
    	window.overlayTimer = setTimeout('overlayFade(0)' , 30);
		}
    
    function openGallery(index)
    {
    	overlayShow(5);
      if ( document.getElementById('galleryBox') == null )
      	createGalleryBox();
      var oDiv = document.getElementById('galleryBox');
      oDiv.style.display = '';
      document.imageIndex = index;
  		updateImage();	
    }
    
    function updateImage()
    {
  var s;
  /*
s = (document.imageIndex+1) + "/" + images.length;
  if ( texts[document.imageIndex] != "" )
    s = s + " (" + texts[document.imageIndex] + ")";
  var oInfo;
  oInfo = document.getElementById("imageInfo");
  if ( oInfo != undefined )
	  oInfo.innerHTML = s;
*/
		
		if ( document.imageIndex == 0 )
	    document.prevButton.style.display = 'none';
    else
	    document.prevButton.style.display = '';
		
    if ( document.imageIndex == images.length-1 )
	    document.nextButton.style.display = 'none';
    else
	    document.nextButton.style.display = '';

    var oDiv;
    var oImage;
    oImage = document.getElementById('galleryImage');
    oDiv = document.getElementById('imageContainer');
		
    var a = images[document.imageIndex].length;
		if ( oImage.src.substr(oImage.src.length - a,a) != images[document.imageIndex] )
    {
    	oDiv.style.visibility = 'hidden';
    
    	oImage.src = images[document.imageIndex];
    	var oSpan
    	oSpan = document.getElementById('caption');
    	oSpan.innerHTML = '';
    	oSpan = document.getElementById('numberDisplay');
    	oSpan.innerHTML = 'Image ' + (document.imageIndex + 1) + ' of ' + images.length;
    }
    //oImage.alt = texts[document.imageIndex];

}
