function checkRequired() {
	var count = 0;
	$('frmUpdateUser').onsubmit = function() {

		$$('.required').each(function(el) {

			if (el.getProperty('value') == "") {
				el.setStyle('border', '1px solid red');
				count = count + 1;
			}
		});


		if (count > 0) {
			count = 0;
			alert("Please fill in all required fields.");
			return false;
		}
		else {
			//check password



			//check email
			/*
			if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test($("user_email").getProperty("value"))) {

				alert("Dit is een ongeldig E-mailadres, controleer s.v.p. uw E-mailadres en probeer het opnieuw.");
				$("user_email").setStyle('border', '1px solid red');
				return false;
			}
			else {
			*/
				$('frmUpdateUser').set('send', { onComplete: function(txt) {
					//	alert(txt);
					alert('Thank you. Your request has been sent.');
				}
				});
				this.send();

				$$('.download-contact-form input.fields').each(function(el){ el.setProperty('value', ''); });

			//}
			return false;
		}
	}
}

function checkImgWidth() 
{
	if (Browser.Engine.trident4)
	{
		var el = $$(".content .floating-img")[0];

		if ( el != null )
		{
			var size = el.getSize();

			if (size.x >= "420")
			{
				el.setStyle("margin", "0 !important");
			}
		}
	}
}

function searchIconSwap() 
	{ if ( Browser.Engine.trident4 )
		{
		 var el = $$('.search-submit');
		 el.addEvent("mouseover", function()
			 {
				el.addClass("search-submit-ie6"); 
			 });
		  el.addEvent("mouseout", function()
			 {
				el.removeClass("search-submit-ie6"); 
			 });
		} 
	}

function getNavHistory()
{
	var elements = $$('li.main ul li');
	
	elements.each(function(el){ 
		el.addEvent("mouseenter", function(){ 
			var parent = this.getParent('li.has-sub');
			var current = this.getParent('ul');

			if( parent != null )
			{	
				parent.addClass('nav-active'); 
				current.addEvent("mouseleave", function(){ parent.removeClass('nav-active'); });

			}
			
		});
	});
}


function initNavigation() {
	

	if( Browser.Engine.trident )
	{
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			var el = $(sfEls[i]);
			el.onmouseover=function() {
				
				this.addClass("hoverIE");
				this.addClass("main-active");
				
			}
			el.onmouseout=function() {
				
				this.removeClass("hoverIE");
				this.removeClass("main-active");
			}
		}

		if( !(navigator.userAgent.indexOf('MSIE 8.0' != -1)) ) {
			var aSpans = $$("#nav li.main span a");
			aSpans.each(function(el){
				el.setStyle("position","relative");
			});
		}
		
	}
	
	
	if(document.getElementById("landing"+window.currentNavItem) != null){
	document.getElementById("landing"+window.currentNavItem).addClass("main-active_page");
	}
}


function setCurrentCatButton(val) {
		window.currentNavItem = val;
}


//related links manual last
function related_manual_links(){
	var arrUl = $$(".related-quicklinks-content ul li");
	if(arrUl.length > 0) arrUl[arrUl.length-1].addClass("last");
}

// Vacancy scripts
function loadVacancySelection() {	
	var sUrl = "index.php?action=get-vacancy-list&page=" + iVacancyPage;
	var sPostBody = "specialisms=" + aVacancySpecialisms + "&locations=" + aVacancyLocations;
	
	var oRequest = new Request({
		method: 'post', 
		url: sUrl,
		data: sPostBody,
		onSuccess: function(responseText, responseXML) {
			$("content-selector-data").set('html', responseText);
			hoverLibraryItemsPro();
		}

	});
	
	oRequest.send();
}

function selectVacancySpecialism(e) {
	var e = new Event(e);
	var sSpecialism = this.getProperty("href");
	
	if (aVacancySpecialisms.contains(sSpecialism)) {
		aVacancySpecialisms.erase(sSpecialism);
		this.removeClass("active");
	} else {
		aVacancySpecialisms.push(sSpecialism);
		this.addClass("active");
	}

	iVacancyPage = 1; // Set page to 1
	loadVacancySelection(); // reload the vacancy selection
	e.stop(); //stop propagation
}

function setVacancySpecialismEvents(array) {		
	array.each(function(id) {		
		if ((el = $("vacancy-specialism-list").getElement("a[href=" + id + "]")) != null) {
			aVacancySpecialisms.push(el.getProperty("href"));
			el.addClass("active");
		}
	});

		
	
	$("vacancy-specialism-list").getElements("li a").each(function(el) { 		
		el.addEvent("click", selectVacancySpecialism);
	});
}

function selectVacancyLocation(e) {
	var e = new Event(e);
	var sLocation = this.getProperty("href");
	
	if (aVacancyLocations.contains(sLocation)) {
		aVacancyLocations.erase(sLocation);
		this.removeClass("active");
	} else {
		aVacancyLocations.push(sLocation);
		this.addClass("active");
	}
	
	iVacancyPage = 1; // Set page to 1
	loadVacancySelection(); // reload the vacancy selection
	e.stop(); //stop propagation
}

function getNextVacancyPage() {
	iVacancyPage++;
	loadVacancySelection(); // reload the vacancy selection
}

function getPreviousVacancyPage() {
	iVacancyPage--;
	loadVacancySelection(); // reload the vacancy selection
}

function setVacancyLocationEvents(array) {
	array.each(function(id) {		
		if ((el = $("vacancy-location-list").getElement("a[href=" + id + "]")) != null) {
			aVacancyLocations.push(el.getProperty("href"));
			el.addClass("active");
		}
	});

	$("vacancy-location-list").getElements("li a").each(function(el) { 	
		el.addEvent("click", selectVacancyLocation);
	});
}

var aVacancySpecialisms = new Array();
var aVacancyLocations = new Array();
var iVacancyPage = 1;


// Project scripts
function loadProjectSelection() {	
	var sUrl = "index.php?action=get-project-list&page=" + iProjectPage;
	var sPostBody = "solutions=" + aProjectSolutions + "&areas=" + aProjectAreas;
	var oRequest = new Request({
		method: 'post', 
		url: sUrl,
		data: sPostBody,
		onSuccess: function(responseText, responseXML) {
			$("content-selector-data").set('html', responseText);
			hoverLibraryItemsPro();
		}

	});
	
	oRequest.send();
}

function selectProjectSolution(e) {
	var e = new Event(e);
	var sSolution = this.getProperty("href");
	
	if (aProjectSolutions.contains(sSolution)) {
		aProjectSolutions.erase(sSolution);
		this.removeClass("active");
	} else {
		aProjectSolutions.push(sSolution);
		this.addClass("active");
	}

	iProjectPage = 1; // Set page to 1
	loadProjectSelection(); // reload the project selection
	e.stop(); //stop propagation
}

function setProjectSolutionEvents() {
	$("solution-list").getElements("li a").each(function(el) { 
		el.addEvent("click", selectProjectSolution);
	});
}

function selectProjectArea(e) {
	var e = new Event(e);
	var sArea = this.getProperty("href");
	
	if (aProjectAreas.contains(sArea)) {
		aProjectAreas.erase(sArea);
		this.removeClass("active");
	} else {
		aProjectAreas.push(sArea);
		this.addClass("active");
	}
	
	iProjectPage = 1; // Set page to 1
	loadProjectSelection(); // reload the project selection
	e.stop(); //stop propagation
}

function getNextProjectPage() {
	iProjectPage++;
	loadProjectSelection(); // reload the project selection
}

function getPreviousProjectPage() {
	iProjectPage--;
	loadProjectSelection(); // reload the project selection
}

function setProjectAreaEvents() {
	$("area-list").getElements("li a").each(function(el) { 
		el.addEvent("click", selectProjectArea);
	});
}

var aProjectSolutions = new Array();
var aProjectAreas = new Array();
var iProjectPage = 1;


// Branche scripts
function loadBrancheSelection() {	
	
	if(document.getElementById("search").value != ""){
		document.getElementById("search").value = "";
	}
	
	var sUrl = "index.php?action=get-branche-list&page=" + iBranchePage;	
	var sPostBody = "locations=" + aBrancheLocations;
	var oRequest = new Request({
		method: 'post', 
		url: sUrl,
		data: sPostBody,
		onSuccess: function(responseText, responseXML) {
			$("content-selector-data").set('html', responseText);
			hoverLibraryItems();
		}

	});
	
	oRequest.send();
}

function selectBrancheLocation(e) {
	var e = new Event(e);
	var sLocation = this.getProperty("href");
	
	if (aBrancheLocations.contains(sLocation)) {
		aBrancheLocations.erase(sLocation);
		this.removeClass("active");
	} else {
		aBrancheLocations.push(sLocation);
		this.addClass("active");
	}

	iBranchePage = 1; // Set page to 1
	loadBrancheSelection(); // reload the project selection
	e.stop(); //stop propagation
}

function setBrancheLocationEvents() {
	$("location-list").getElements("li a").each(function(el) { 		
		el.addEvent("click", selectBrancheLocation);
	});
}

function getNextBranchePage() {
	iBranchePage++;
	loadBrancheSelection(); // reload the project selection
}

function getPreviousBranchePage() {
	iBranchePage--;
	loadBrancheSelection(); // reload the project selection
}

var aBrancheLocations = new Array();
var iBranchePage = 1;

// Video selector scripts
function loadVideoSelection() {	
	var sUrl = "index.php?action=get-video-list&page=" + iVideoPage;	
	var sPostBody = "categories=" + aVideoCategories;
	var oRequest = new Request({
		method: 'post', 
		url: sUrl,
		data: sPostBody,
		onSuccess: function(responseText, responseXML) {
			$("content-selector-data").set('html', responseText);			
			hoverLibraryItems();
			initSqueezeBox();
		}
	});
	
	oRequest.send();
}

function selectVideoCategory(e) {
	var e = new Event(e);
	var sCategory = this.getProperty("href");
	
	if (aVideoCategories.toString().indexOf(sCategory) != -1) {
		aVideoCategories.erase(sCategory);
		this.removeClass("active");
	} else {
		aVideoCategories.push(sCategory);
		this.addClass("active");
	}
	
	iVideoPage = 1; // Set page to 1
	loadVideoSelection(); // reload the project selection
	e.stop(); //stop propagation
}

function setVideoCategoryEvents() {
	$("video-category-list").getElements("li a").each(function(el) { 		
		el.addEvent("click", selectVideoCategory);
	});
}

function setVideoCategoryAndPick(val) {
	$("video-category-list").getElements("li a").each(function(el) { 		
		el.addEvent("click", selectVideoCategory);
		if(el.getProperty("href") == val){
			el.addClass("active");	
		}
	});
	if(typeof(val) != "undefined"){
	aVideoCategories.push(val.toString());
	}
	iVideoPage = 1; // Set page to 1
	loadVideoSelection(); // reload the project selection
	
	if(typeof(e)!="undefined"){ 
		//e.stop(); //stop propagation
	}
	
}

function getNextVideoPage() {
	iVideoPage++;
	loadVideoSelection(); // reload the project selection
}

function getPreviousVideoPage() {
	iVideoPage--;
	loadVideoSelection(); // reload the project selection
}

var aVideoCategories = new Array();
var iVideoPage = 1;

// Fleet selector scripts
function loadFleetSelection() {	
	var sUrl = "index.php?action=get-fleet-list&page=" + iFleetPage;	
	var sPostBody = "categories=" + aFleetCategories;
	var oRequest = new Request({
		method: 'post', 
		url: sUrl,
		data: sPostBody,
		onSuccess: function(responseText, responseXML) {
			$("content-selector-data").set('html', responseText);			
			hoverLibraryItems();
		}

	});
	
	oRequest.send();
}

function selectFleetCategory(e) {
	var e = new Event(e);
	var sCategory = this.getProperty("href");
	
	if (aFleetCategories.contains(sCategory)) {
		aFleetCategories.erase(sCategory);
		this.removeClass("active");
	} else {
		aFleetCategories.push(sCategory);
		this.addClass("active");
	}

	iFleetPage = 1; // Set page to 1
	loadFleetSelection(); // reload the project selection
	e.stop(); //stop propagation
}

function setFleetCategoryEvents() {
	$("fleet-category-list").getElements("li a").each(function(el) { 		
		el.addEvent("click", selectFleetCategory);
	});
}

function getNextFleetPage() {
	iFleetPage++;
	loadFleetSelection(); // reload the project selection
}

function getPreviousFleetPage() {
	iFleetPage--;
	loadFleetSelection(); // reload the project selection
}

var aFleetCategories = new Array();
var iFleetPage = 1;


// Global scripts
function hoverCriteriaSecondLevel(){
	if(	$(document.body).getElement('.criteria-selector-2e-level') != null ) {
		$$('.criteria-selector-2e-level')[0].getElements("ul li a").each(function(el) { 
				el.addEvent("mouseenter",  function(){
													
					this.addClass('active');
					
				});
				el.addEvent("mouseleave",  function(){
					this.removeClass('active');
				});
			});
		}
}

function hoverCriteriaSecondLevelJobs(){
	if(	$(document.body).getElement('.criteria-selector-2e-level-jobs') != null ) {
		$$('.criteria-selector-2e-level-jobs')[0].getElements("ul li a").each(function(el) { 
				el.addEvent("mouseenter",  function(){
					this.addClass('active');
					
				});
				el.addEvent("mouseleave",  function(){
					this.removeClass('active');
				});
			});
		}
}


function hoverCriteriaSecondLevelPro(){
	if(	$(document.body).getElement('.criteria-selector-2e-level-pro') != null ) {
		$$('.criteria-selector-2e-level-pro')[0].getElements("ul li a").each(function(el) { 
				el.addEvent("mouseenter",  function(){
					this.addClass('active');
					
				});
				el.addEvent("mouseleave",  function(){
					this.removeClass('active');
				});
			});
		}
}

function hoverCriteriaSelector(){
	if(	$(document.body).getElement('.criteria-selector-content') != null ) {
		$$('.criteria-selector-content')[0].getElements("ul li a").each(function(el) { 
				el.addEvent("mouseenter",  function(){
					this.addClass('hover');
					
				});
				el.addEvent("mouseleave",  function(){
					this.removeClass('hover');
				});
			});
	}
}




function hideSub(){
	var el = $(document.body).getElement(".sub-nav ul li ul");
	
	el.setStyle('display', 'none');
}

function setVideoEvents ( ){
	
	$$(".video-content-overlay").each(function(el){
		el.addEvent("click", openVideo);
	});
}

function openVideo(){
	var el = $(document.body).getElement(".video-wrapper");
	//alert("TEST");
	el.setStyle('display', 'block');
	el.addEvent("click", closeVideo);
}

function closeVideo(){
	var el = $(document.body).getElement(".video-wrapper");
	el.setStyle('display', '');
}

function setVideoSubNav() {
	$(document.body).getElements(".selector-header-video").each(function(el) { 
		el.addEvent("click", showVideoSubNav);
		el.setStyle('cursor', 'pointer');
	});

	$(document.body).getElements(".subitems").each(function(el) { 
		el.setStyle('display', 'none');
	});
}

function showVideoSubNav() {
	var subitems = this.getElement(".subitems");
	
	if (oCurrentSubItem == subitems) {
		oCurrentSubItem.setStyle('display', 'none'); 
		oCurrentSubItem.getParent().removeClass('video-active');
		oCurrentSubItem = null;
		return;
	}
	
	if (oCurrentSubItem != null) {
		oCurrentSubItem.setStyle('display', 'none'); 
		oCurrentSubItem.getParent().removeClass('video-active');
	}

	if (subitems.getStyle('display') == 'none') { 
		subitems.setStyle('display', 'block');
		subitems.getParent().addClass('video-active');
	} 
	
	oCurrentSubItem = subitems;
}

function hoverLibraryItems(){
	
	if(	$(document.body).getElement('.selector-library') != null ) {
		$$('.selector-library')[0].getElements(".selector-library-item").each(function(el) { 
			
			el.addEvent("mouseenter",  function(){
												
				this.getElement('.library-item-caption').setStyle("color", "#ffffff");
				this.getElement('.selector-library-item-caption').setStyle("background-color", "#ff8702");
				//this.getElement('.selector-library-item-overlay').addClass('video-active');
			});
			el.addEvent("mouseleave",  function(){
				this.getElement('.library-item-caption').setStyle("color", "#024C6F");
				this.getElement('.selector-library-item-caption').setStyle("background-color", "#ffffff");
				//this.getElement('.selector-library-item-overlay').removeClass('video-active');
			});
		});
	}
};

function hoverLibraryItemsPro(){
	if(	$(document.body).getElement('.selector-library-pro') != null ) {
		$$('.selector-library-pro')[0].getElements(".selector-library-item").each(function(el) { 			
			el.addEvent("mouseenter",  function(){				
				this.getElement('.library-item-caption').setStyle("color", "#ffffff");
				this.getElement('.selector-library-item-caption').setStyle("background-color", "#ff8702");
				//this.getElement('.selector-library-item-overlay').addClass('video-active');
			});
			el.addEvent("mouseleave",  function(){
				this.getElement('.library-item-caption').setStyle("color", "#fff");
				this.getElement('.selector-library-item-caption').setStyle("background-color", "#000");
				//this.getElement('.selector-library-item-overlay').removeClass('video-active');
			});
		});
	}
};



function hoverLibraryItem(){
	var alink = this.getElement(".selector-library-item-caption");
		alink.setStyle('background-color', 'red');
};

	
function writeFlash2(el, sUrl) {
	// Clear element
	$(el).empty();
	$(el).setStyles({ width: 950, height: 300 });

	// Write flash
	var so = new SWFObject(sUrl, "flashvideo", "950", "300", "opaque");
	so.addParam("wmode", "transparent");
	so.write(el);
	
}
	
function writeFlash(el, sUrl, iWidth, iHeight) {
	// Clear element
	$(el).empty();
	$(el).setStyles({ width: iWidth, height: iHeight });

	// Write flash
	var so = new SWFObject(sUrl, "flashvideo", iWidth, iHeight, "opaque");
	so.addParam("wmode", "transparent");
	so.write(el);
	
}

function initSqueezeBox() {
	/**
     * Set default options, overrideable from later calls.
     */
    SqueezeBox.initialize({
        size: {x: 640, y: 520}
    });

    /**
     * Assign SqueezeBox to all links with rel="boxed" attribute, the class then reads the "href".
     */
    SqueezeBox.assign($$('a[rel=boxed]'));
}

function initSifR(){

	var lucida = {
    src: '/assets/project/flash/lucida.swf'
  };

sIFR.useStyleCheck = true;
sIFR.activate(lucida);


sIFR.replace(lucida, {
    selector: 'h1'
    ,css: [
      '.sIFR-root { color:#ff8702; font-size:20px; }'
    ]
	,wmode: 'transparent'
  });

  sIFR.replace(lucida, {
    selector: 'h2'
    ,css: [
      '.sIFR-root { color:#024c6f; font-size:16px; }'
    ]
	,wmode: 'transparent'
  });


}

function initPage () {
	//initSifR();
	initNavigation();
	//getNavHistory();
	searchIconSwap();
	setVideoSubNav();
	hoverLibraryItemsPro();
	hoverCriteriaSecondLevelPro();
	hoverCriteriaSecondLevel();
	hoverCriteriaSecondLevelJobs();
	hoverCriteriaSelector();
	hoverLibraryItems();
	initSqueezeBox();
	related_manual_links();
	checkImgWidth();
	//
	
	
}

var oCurrentSubItem;

window.addEvent("domready", initPage);

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function pauseFlash() {
	flashMovie = getFlashMovieObject("flashvideo");
	//alert(flashMovie);
	flashMovie.SetVariable("playStatus", "pause");
}

function playFlash() {
	flashMovie = getFlashMovieObject("flashvideo");
	//alert(flashMovie);
	flashMovie.SetVariable("playStatus", "play");	
}

function stopMovie() {
	var d = document.getElementById('videoplayer');
	
	d.parentNode.removeChild(d);
}