(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var h = $($(this).parent()[0]).height();
	var mt = h / 2;
	var ih = $(this).outerHeight();
	var nih = ih / 2;
	var nh = mt + nih;
	var np = mt - nih;
	$(this).parent('a').css("padding-top", np);	
	$(this).parent('a').css("height", nh);
	});	
};
})(jQuery);

// JavaScript Document
$(document).ready(function(){
													 
	//external links pop out
	$('a.extimg[href^=http],a.extlink[href^=http]').click(function() {
		window.open(this.href);
		return false;
	});
	$("a.extlink").after(" <img src='/images/popup.png' alt='Nieuw scherm' />");

	$("#menu-links span.l1").vAlign();
	$("#agenda").load("/scripts/calendar.php");
	$("a.newsitem").click(function(event) {
		var item_ID = $(this).attr("data-item");
		$('a.archief').removeClass('active');
		$('a.newsitem').removeClass('active');
		$(this).addClass('active');
		$("#newscontent").load('/scripts/nieuws-display.php', {'id': item_ID}, function() {
			$("#newsextra").load('/scripts/nieuws-extra.php', {'id': item_ID});
		});
	});
	$("a.archief").click(function(event) {
		var item_ID = "archief";
		$('a.newsitem').removeClass('active');
		$("a.archief").addClass('active');
		$("#newscontent").load('/scripts/nieuws-display.php', {'id': item_ID});
	});
	$(".panorama1").colorbox({width:"750", height:"400", iframe:true});
	$(".panorama2").colorbox({width:"750", height:"400", iframe:true});
	$(".routewindow").colorbox({width:"800", height:"470", iframe:true});
	$(".nieuwsartikel").colorbox({width:"700", height:"500", iframe:true});
	$(".aanmeldwindow").colorbox({width:"500", height:"560", iframe:true});
	$(".agenda-window").colorbox({width:"600", height:"560", iframe:true}); //.colorbox({width:"560", height:"420"}); 
  $(".youtube").colorbox({width:"853", height:"505", iframe:true});    
	$("table#program tr:even").addClass("even");
});

$("#agenda a.browse").live('click', function(event) {
	var m = $(this).attr("data-month");
	var y = $(this).attr("data-year");
	$("#agenda").children(".calendar-jquery").animate({
	opacity: 0}, 500, function() {
		$("#agenda").load("/scripts/calendar.php?month="+m+"&year="+y);
		$("#agenda").children(".calendar-jquery").animate({opacity: 100});
	});
	event.preventDefault();
});

function loadItUp(file) {
  document.getElementById('rotator').loadFile({file:file});
}
