var home = false;
window.onload = function() {

    initPrint();
    // initHomeLink();
    initSubnav();
    initSnelzoeker();
    initWhitespace();
    initSectorHeader();
	popmeup();
	startPushbox();
}

function popmeup() {
    var height = 400;
    var width = 500;
    var top = (screen.height / 2) - (height / 2);
    var left = (screen.width / 2) - (width / 2);
	  //var top = 50;
    //var left = 50;
    //window.open("/melding.htm", "FNV Formaat","left="+left+",top="+top+",height="+height+",width="+width+",status=no,location=no");
	if(home) window.open("/melding.htm", "FNVFormaat","left="+left+",top="+top+",height="+height+",width="+width+",status=no,location=no");
}

function initWhitespace() {
	if(ge('content_opsomming'))
	{
		stripWhiteSpace(ge('content_opsomming'));
	}
}

function initPrint() {
    if(ge('print')) {
        ge('print').onclick = function() {
            window.print();
            return false;
        }
    }

    if(ge('print_content')) {
        ge('print_content').onclick = function() {
            window.print();
            return false;
        }
    }

}

function initHomeLink() {

	var h1 = ge('header').getElementsByTagName('h1');

	for(var i = 0; i < h1.length; i++) {

        h1[i].onclick = function() {
            document.location = "/";
            return false;
        }

    }

}

function initSubnav()
{
	var subnav = ge('subnav');
	if(subnav)
	{

		var subnavlinks = subnav.getElementsByTagName('li');

		var start_subnav = 1;

		var el = ge('content_homesub'+start_subnav);
		if (el) el.style.display='block';

	 	for(var i = 0; i < subnavlinks.length; i++) {

	 		subnavlinks[i].onclick=function()
	 		{
	 			var subnavli = ge('subnav').getElementsByTagName('li');
	   		for(var j = 0; j < subnavli.length; j++)
	   		{
	   			var href = subnavli[j].getElementsByTagName('A');
	   			for(var link = 0; link < href.length; link++)
	   			{
	   				removeClassName(href[link],'active');
	   			}
	   		}

	 			var a = this.getElementsByTagName('A');
	   		for(var i = 0; i < a.length; i++)
	   		{
	   			addClassName(a[i],'active');
	   		}

				subid = this.className.replace('sub','');
				subid = subid.replace(' last','');

				ge('content_homesub'+start_subnav).style.display='none';
				ge('content_homesub'+subid).style.display='block';
				start_subnav = subid;
			}
		}
	}
}

function initSnelzoeker(i){

	var snelzoeker = ge('snelzoeker');
 	 if(snelzoeker)
 	 {
	 	snelzoeker.onchange = function()
	 	{
 			if(this.value!='') document.location.href = this.value;
		}
	}
}

function showOne(pId)
{
	var elShow = ge(pId);
	var elFam = document.getElementsByTagName(elShow.tagName);
	for (var i=0; i<elFam.length; i++)
	{
		var elHide = elFam[i];
		if (elHide.className == elShow.className && elHide != elShow)
		{
			elHide.style.display = 'none';
		}
	}
	elShow.style.display = (elShow.style.display != 'block') ? 'block' : 'none' ;
}

function gaNaar(id)
{
	var pag = document.getElementById(id).value;
	document.location.href = pag;
}

var laatste= 0;

function changeVisual(i, v) {

    if (!i || !v) return;

	if(ge('sector_kop')) {
		ge('sector_kop').style.display='none';
	}

	if(laatste!=0) {
		ge('kop_'+laatste).style.display='none';
	}
	ge('kop_'+i).style.display='block';
	laatste = i;

	ge('sector').style.backgroundImage = 'url('+v+')';
	ge('sector').style.backgroundRepeat = 'no-repeat';

}


function setBackgroundImageSector(v) {

	if(v!='') {
		ge('sector').style.backgroundImage = 'url('+v+')';
	}

}



function changeVisualContentHeaderLeft(v) {

	if(v!='') {
		var v2 = v.replace(' ','%20');
		ge('content_header_left').style.backgroundImage = 'url('+v2+')';
	}

}

function gotoCursusSearch(selThema, selMaand)
{
	var selT = ge(selThema).options[ge(selThema).selectedIndex].value;
	var selM = ge(selMaand).options[ge(selMaand).selectedIndex].value;

	document.location = 'Open aanbod/Cursus zoek resultaat.aspx?thema=' + selT + '&maand=' + selM;

}

function gotoCursusSearchThema(selThema, selMaand)
{
	document.location = 'Cursus zoek resultaat thema.aspx?thema=' + selThema + '&maand=' + selMaand + '&page=1';
}

/*function gotoKennisbankSearch(selThema, searchValue)
{
	var selT = ge(selThema).options[ge(selThema).selectedIndex].value;
	document.location = 'Kennisbank/Kennisbank zoek resultaat.aspx?thema=' + selT + '&search=' + searchValue;
}

function gotoKennisbankSearchThema(selThema, searchValue)
{
	document.location = 'Kennisbank zoek resultaat thema.aspx?thema=' + selThema + '&search=' + searchValue + '&page=1';
}
*/

function gotoKennisbankOpsomming(control)
{
	var selValue = control.options[control.selectedIndex].value;
	document.location.href = selValue;
}

function doSearch()
{
	var el = document.getElementById('searchtext');
	if (el && el.value != '') top.location='/Zoeken.aspx?search='+el.value;
	return false;
}

function opEnterZoek(e, dit) 
{
	var keynum;
	var waarde;

	if(window.event) // IE
	{
	    keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	    keynum = e.which
	}

	if(keynum == 13)
	{
	    window.event.cancelBubble = true;	
		window.onunload = function()
		{
			doSearch()
		}		
		doSearch()
	}
}

var sectorCount = 0;
function initSectorHeader()
{
    var i = Math.ceil(Math.random() * sectorCount);
    var e = document.getElementById("sector_header_" + String(i));
    if (e) e.onclick();
}

/**
 * starts pushbox
 *
 * @author Klaas Dieleman <klaas[AT]efocus.nl>
 * @since 1.0, 18 jan, 2010
 * @return void
 */

function startPushbox() {
	if (!document.getElement('div.pushbox')) return;
	
	new Pushbox({
		'viewport': document.getElement('div.pushbox'),
		'slides': document.getElements('div.pushbox ul.pushbox_slides li'),
		'navigation': document.getElements('div.pushbox ul.pushbox_nav li'),
		'transition': 'fade',
		'delay': 4
	});
}