var placeFooter = function() {
	// placing footer @ bottom of page if needed.
	var margin = $(window).height() - $('#siteContainer').height();
	if (margin > 0) {
		$('#contentContainer').height($('#contentContainer').height() + margin);
	} else {
		$('#contentContainer').css('height', 'auto');
	}
}

/* doesn't work in IE 6 & 7
$(window).resize(function() {
	placeFooter();
});
*/

$(document).ready(function() {
	// sifr breaks when a span is missing?
	$('#page8426896 a').html('Aanmelden nieuwsbrief');
	$('#menu li a, #footerMenu li a, ').wrap('<span></span>');

	//change menu according wishes...

	// label hiding
	if ($('input.hideMyLabel').val() != '') {
		$('label.hideMe[for='+$(this).attr('id')+']').hide();
	}

	$('input.hideMyLabel').focus(function() {
		$('label.hideMe[for='+$(this).attr('id')+']').hide();
	});

	$('input.hideMyLabel').blur(function() {
		if ($(this).val() == '') {
			$('label.hideMe[for='+$(this).attr('id')+']').show();
		}
	});

	// form validation
	$('#placeReactionForm').validate({
		errorPlacement: function(error, element) {
			if (element.attr('name') == 'comment') {
				error.insertAfter('label[for="reaction"]');
			} else {
				error.insertAfter(element);
			}
		}
	});

	// menu stuff
	$('#menu').superfish({
		autoArrows: false,
		disableHI: true,
		delay: 50
	});

	// help popup
	$('a.infoLink').click(function(){
		$('#helpPopup').fadeIn();
		return false;
	});
	$('#closePopup').click(function(){
		$('#helpPopup').fadeOut();
		return false;
	});

	// calendar tricks
	$('#calendar .eventInfo').hover(function() {
		$(this).find('.eventInfoBubble').append('<li class="specialArrow"></li>').fadeIn();
	}, function() {
		$(this).find('.eventInfoBubble').fadeOut(function() {
			$(this).find('.specialArrow').remove();
		});
	});

	// galery things
	$('ul.gallery li:first').addClass('active');
	$('ul.gallery').galleria({
		history   : false,
		clickNext : true,
		onImage   : function(image, caption, thumb) {
			if(! ($.browser.mozilla && navigator.appVersion.indexOf('Win') != -1) ) {
				image.css('display', 'none').fadeIn(1000);
			}
			caption.css('display', 'none').fadeIn(1000);
			var _li = thumb.parents('li');
			_li.siblings().children('img.selected').fadeTo(500, 0.3);
			thumb.fadeTo('fast', 1).addClass('selected');
			image.attr('title', 'Volgende foto');
		},
		onThumb : function(thumb) {
			var _li = thumb.parents('li');
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			thumb.css({display:'none', opacity:_fadeTo}).fadeIn(1500);
			thumb.hover(
				function() { thumb.fadeTo('fast', 1); },
				function() { _li.not('.active').children('img').fadeTo('fast', 0.3); }
			)
		}
	});

	// Top vacatures
	if ($('.jobOpeningList').length > 0) {
		var vacatureCount = 0;
		$('.jobOpeningList').attr('id', 'list0').load('/gateway/html?localAction=topVacatures&start=0&count=15', '', function() {
			function scrollHandler(){
				var scrollTo;
				scrollTo = -$('#list0 li:eq(1)').position().top;
				$('#list0').animate({top: scrollTo}, 2000, 'linear', function() {
					$('#list0 li:first').appendTo('#list0'); //push the first element on the end
					$('#list0').css('top', 0); //make sure the list doesn't move
					scrollHandler();
				});
			}
			scrollHandler();
			$('#list0').hover(function() {
				$('#list0').stop();
			}, function() {
				scrollHandler();
			});
			/* $('#prevJobList').click(function() { // disabled by request
				$('#list0 li:gt(10)').prependTo('#list0');
				return false;
			});
			$('#nextJobList').click(function() {
				$('#list0 li:lt(4)').appendTo('#list0');
				return false;
			}); */
		});
	}

	// stuff for vacaturetkrant
	if ($('h1:contains("Vacature")').length > 0) {
		$('h1:contains("Vacature")').parent().wrapInner('<div id="vkExtendedSearch"></div>');
	}
	if ($('h1:contains("Inloggen als werkzoeker")').length > 0) {
		$('h1:contains("Inloggen als werkzoeker")').parent().wrapInner('<div id="vkLogin"></div>');
	}
	if ($('h1:contains("Registreren")').length > 0) {
		$('h1:contains("Registreren")').parent().wrapInner('<div id="vkRegister"></div>');
	}
	if ($('h1:contains("CV")').length > 0) {
		$('h1:contains("CV")').parent().wrapInner('<div id="vkRegister"></div>');
	}
	if ($('h1:contains("Curriculum Vitae")').length > 0) {
		$('h1:contains("Curriculum Vitae")').parent().wrapInner('<div id="vkRegister"></div>');
	}
	if ($('h1:contains("bewerken")').length > 0) {
		$('h1:contains("bewerken")').parent().wrapInner('<div id="vkRegister"></div>');
	}

	// opener for business events acties
	$('.promotionAnchor').click(function(){
		$('.promotionDescription').hide('slow');
		if (!$(this).siblings('.promotionDescription').is(':visible')) {
			$(this).siblings('.promotionDescription').show('slow');
		}
		return false;
	});

	placeFooter();
});

//as requested by Millian #9293163
function toggleVisible(id){
	$('#'+id).show();
}

function toggleInvisible(id){
	$('#'+id).hide();
}

function openurl(id, boek){
	var url;
	url = 'http://www.millian.nl/'+ boek +'/minimal.phtml?pid='+ id +'&p='+ boek +'+Overzicht+Instituut';
	newwin = open(url,'Instituutinfo','width=600,height=500,status=no,toolbar=no,menubar=no,scrollbars=yes');
}

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));