servernaam = 'http://www.werkenbijdelandmacht.nl';

function initmenu() {
	$('#nav>li').hover(function(){
		$heading = $(this);
		if ($heading.siblings().find('ul:visible').size()>0)
			$heading.find('ul').hide();
		else
			$heading.find('ul').show();
	},
	function(){
		$(this).find('ul').hide();
	});
	$('.openblok').click(function(){
		nummer = $(this).attr('id').substring(8);
		opensluit = $('#blokul'+nummer).is(':visible') ? 'sluit' : 'open';
        if (opensluit=='open')
            $('#blokopen'+nummer).text('SLUIT').removeClass('sluitblok');
        else
            $('#blokopen'+nummer).text('OPEN').addClass('sluitblok');
		$('#blokul'+nummer).slideToggle('slow');
		if(!tdatemplate)
			$.post('/ajax/openofsluitblok.php',{blokkopid:nummer, opensluit: opensluit });
	});
	$('select').selectbox();
	$('input:radio').checkbox({cls:'jquery-radio'});
	$('input:checkbox').checkbox();
	positioneernavigatie();
	$(window).scroll(positioneernavigatie);
	$('#frm_zoekform_do_submit').after('<a href="#" id="frm_zoekform_do_submit" class="formlink">Zoek</a>').remove();
	$('#ticket_do_submit').after('<a href="#" id="ticket_do_submit" class="formlink">Verstuur</a>').remove();
	$('#frm_do_submit').after('<a href="#" id="frm_do_submit" class="formlink">Verstuur</a><input type="hidden" name="do_submit" value="Versturen" />').before('<hr />').remove();
	$('#frm_zoekform_do_submit').click(function(){$('#frm_zoekform').submit();});
	$('#ticket_do_submit').click(function(){$('#ticket').submit();});
	$('#frm_do_submit').click(function(){$('#frm').submit();});
	$('#fs_frm_lbl_alggegevens, #fs_frm_lbl_onderwijs, #fs_frm_lbl_stage').before('<hr />');
	
	$('.formlink').prepend('&gt; ');
	
	if(typeof(g_nClusterId) != "undefined" && g_nClusterId>-1){
		$('#menu').html('<img src="'+servernaam+'/img/ajax-loader.gif"/>');
		 $.getJSON(servernaam+"/ajax/menu.php?tdaclusterid="+g_nClusterId+"&_callback=?",
	        function(data){
	            $('#menu').html(data.item);
	        });
	}
	
	if(tdatemplate) {
		$('#rightside').find("a[href$='javascript:print();']").attr('href','javascript:print();');
	}
}

function positioneernavigatie() {
	if ($(window).scrollTop()>104) {
		$('#nav').css('position','fixed');
		$('#navbgcontainer').css('position','fixed');
		$('#nav').css('top','-18px');
		$('#navbgcontainer').css('top','-18px');
	} else {
		$('#nav').css('position','relative');
		$('#navbgcontainer').css('position','relative');
		$('#nav').css('top','auto');
		$('#navbgcontainer').css('top','auto');
	}
}

function zoekboxzoeken() {
	if ($('#zoekboxinput').val().length>1) {
		$('#zoekboxdiv').css('background-image','url('+servernaam+'/img/zoekboxloader.gif)');
		//$('#zoekresultatendiv').load(servernaam+'/ajax/zoekbox.php',{text:$('#zoekboxinput').val()},function(){
		$.getJSON(servernaam+'/ajax/zoekbox.php?_callback=?',{text:$('#zoekboxinput').val()},function(data){
				$('#zoekresultatendiv').html(data.item);			
				$('#zoekresultatendiv').slideDown('slow');
				$('#zoekboxdiv').css('background-image','url('+servernaam+'/img/zoekbox.gif)');
		});
	} else
		$('#zoekresultatendiv').slideUp('slow');
}

function anderenbezochtenook(cid) {
	$('#anderenbezochtenook').slideToggle().load(servernaam+'/ajax/anderenbezochtenook.php',{cid:cid},function(){
		$('.anderenbezochtenookbloklink').hover(function(){
			$(this.firstChild).attr("src", '/img/pageiconhover.gif');
		},function(){
			$(this.firstChild).attr("src", '/img/pageicon.gif');
		})	
	});
}

function initzoekbox() {
	$('#zoekboxinput').keyup(zoekboxzoeken);
	$('#zoekboxdiv').click(zoekboxzoeken);
	$('#zoekboxinput').blur(function(){
		$('#zoekresultatendiv').slideUp('slow');
	});
}

function popitup(url, width, height)
{
	newwindow=window.open(url,'name','height='+ height + ', width=' + width);
	if (window.focus) {newwindow.focus()}
	return false;
}


jQuery.fn.clearonfocus = function() {
	jQuery(this)
	.bind('focus', function() {
		// Set the default value if it isn't set
		if ( !this.defaultValue ) this.defaultValue = this.value;
		// Check to see if the value is different
		if ( this.defaultValue && this.defaultValue != this.value ) return;
		// It isn't, so remove the text from the input
		this.value = '';
	})
	.bind('blur', function() {
	// If the value is blank, return it to the defaultValue
	if ( this.value.match(/^\s*$/) )
		this.value = this.defaultValue;
	});
};