/* Dutch (UTF-8) initialisation for the jQuery UI date picker plugin. */
/* Written by Mathias Bynens <http://mathiasbynens.be/> */
jQuery( function($) {
    $.datepicker.regional['nl'] = {
        closeText: 'Sluiten',
        prevText: '?',
        nextText: '?',
        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,
        changeYear: true,
        yearRange : 'c-90:c+5',
        yearSuffix: ''};
    $.datepicker.setDefaults($.datepicker.regional['nl']);

    $(window).ready(init);

    function init() {
        function generatePeriod(div) {
					if(typeof periode != 'undefined') {
						$.each(periode, function(key, value) {
							if($(div+' .year_'+value.year).length < 1){
								$(div).append('<ul class="year_'+value.year+'"><li><b class="yearClick">'+value.year+'</b><ul></ul></li></ul>');
								$(div+' li ul').hide();
							}
							$(div+' .year_'+value.year+' li ul').append('<li><a href="'+value.url+'" rel="'+value.rel+'">'+value.title+'</a></li>');
						});
	
						$(div+' .yearClick').click(function() {
							if($(this).hasClass('current')) {
								$(this).removeClass('current');							
								$(this).parent().find('ul').slideUp();
							} else {
								$(div+' .current').parent().find('ul').slideToggle();
								$(div+' .current').removeClass('current');
								
								$(this).parent().find('ul').slideToggle();
								$(this).addClass('current');
							}
						});
						
						$(div+' .yearClick').first().click();
						
						$(div+' a').click(function() {
							$(div+' a').css('background', 'none');
							$(this).css('background', '#fbe327');
						});
					}					
				}
				
				generatePeriod('#eventArchive');
				generatePeriod('#newsArchive');
				
				$(window).ready( function() {
          if($( ".CalendarTextBox" ).length)  $(".CalendarTextBox").datepicker();
            initFooter();
            initListForm();
        })
        function initListForm() {
            $('.CalendarIcon').each( function(i,elm) {
                $(elm).removeAttr('onclick');
            })
            $('.CalendarIcon').click( function(e) {
                $(this).prevAll('input.CalendarTextBox').trigger('focus');
                e.preventDefault();
            })
            $('.chkAll').each( function(index,elm) {
                $(elm).click( function() {
                   $(this).parent().parent().find('input').not('.chkAll').attr('checked',$(this).attr('checked'));
                })
            })
        }

        function initFooter() {
            if($('#sitemap').length) {
                $('#sitemap > ul > li').addClass("masonry");

                $('#sitemap').find('.CMSSiteMapList').find('li').each( function() {
                    $(this).find('ul').find('li').each( function() {
                        $(this).html("<span>|</span> " + $(this).html());
                    } );
                } );
                $('#sitemap').masonry({
                    columnWidth: 220,
                    itemSelector: '.masonry'
                });
            }
        }
				
				$('.ItemImageWrapper ul li img').click(function(){
					console.log($(this).data("img"));
					$('.ItemImageWrapper .ItemImage img').attr('src', $(this).data("img"));
				});


    }

});
