$( function() {

	function scroll(direction) {

		var scroll, i,
		positions = [],
		here = $(window).scrollTop(),
		collection = $('.post');

		collection.each( function() {
			positions.push(parseInt($(this).offset()['top'],10));
		});
		for(i = 0; i < positions.length; i++) {
			if (direction == 'next' && positions[i] > here) {
				scroll = collection.get(i);
				break;
			}
			if (direction == 'prev' && i > 0 && positions[i] >= here) {
				scroll = collection.get(i-1);
				break;
			}
		}

		if (scroll) {
			$.scrollTo(scroll, {
				duration: 1000
			});
		}

		return false;
	}

	$("#next,#prev").click( function() {
		return scroll($(this).attr('id'));
	});

	$(".scrolltoanchor").click( function() {
		$.scrollTo($($(this).attr("href")), {
			duration: 1000
		});
		return false;
	});

});

(function(){

	$.fn.pangoCalendar = function(){

		var daysWithShow = [];
		setDaysWithShow();

		function setDaysWithShow(year, month){
			var date_text	= '';

			if(month != undefined && year != undefined){
				date_text	= month + '-' + year;
			}
			else{
				var current_date = new Date();
				date_text	= (current_date.getMonth() + 1) + '-' + current_date.getFullYear();
			}

			var link		= '/includes/ajax/calendar.day.shows.php?month=' + date_text;

			$.ajax({
				url			: link,
				dataType	: 'json',
				async		: false,
				success		: function(data){
					$.each(data, function(index, value){
						if(Number(value) >= 1){
							daysWithShow.push(index);
						}
					});
				},
				error		: function(xhr, ajax_options, thrownError){
					/*alert(thrownError + '\n' + xhr.status);*/
				}
			});
			
		}

		return this.each(function(){

			$(this).datepicker({
				closeText			: 'Sluiten',
				prevText			: 'vorige',
				nextText			: 'volgende',
				currentText			: 'Vandaag',
				monthNames			: ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december'],
				monthNamesShort		: ['jan', 'feb', 'maa', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],
				dayNames			: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],
				dayNamesShort		: ['zon', 'maa', 'din', 'woe', 'don', 'vri', 'zat'],
				dayNamesMin			: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
				weekHeader			: 'Wk',
				dateFormat			: 'dd-mm-yy',
				firstDay			: 1,
				isRTL				: false,
				showMonthAfterYear	: false,
				yearSuffix			: '',
				onSelect			: function(date_text){
					var link = '/programma/dag/' + date_text;
					document.location.href = link;
				},
				onChangeMonthYear	: setDaysWithShow,
				beforeShowDay		: function(date){
					var date_string = $.datepicker.formatDate('dd-mm-yy', date);

					for(var i= 0; i < daysWithShow.length; i++){
						if(daysWithShow[i] == date_string){
							return [true];
						}
					}

					return [false];
				}
			});

		});
		
	}

})(jQuery);

(function($){
	
	$.fn.pangoMenu = function(){

		return this.each(function(){

			$(this).parent('li').hoverIntent({
				timeout : 100,
				over	: function(){
					$(this).children('ul').show();
				},
				out		: function(){
					$(this).children('ul').hide(500);
				}
			});

		});

	};
	
})(jQuery);

