(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }

	$("document").ready(function() {
		/* jQuery logica voor EVENEMENTEN pagina's */
		$('.inside .eventDate').each(function(index) {
			var myDate = new Date($(this).html());
			var curr_date = myDate.getDate();
			var curr_day = myDate.getDay();
			var curr_month = myDate.getMonth();
			var curr_year = myDate.getFullYear();
	
			curr_day +='';
			curr_day = curr_day.replace("0", "maandag, ");
			curr_day = curr_day.replace("1", "dinsdag, ");
			curr_day = curr_day.replace("2", "woensdag, ");
			curr_day = curr_day.replace("3", "donderdag, ");
			curr_day = curr_day.replace("4", "vrijdag, ");
			curr_day = curr_day.replace("5", "zaterdag, ");
			curr_day = curr_day.replace("6", "zondag, ");
	
			curr_month +='';
			curr_month = curr_month.replace(/10/, "november");
			curr_month = curr_month.replace(/11/, "december");
			curr_month = curr_month.replace(/0/, "januari");
			curr_month = curr_month.replace(/1/, "februari");
			curr_month = curr_month.replace(/2/, "maart");
			curr_month = curr_month.replace(/3/, "april");
			curr_month = curr_month.replace(/4/, "mei");
			curr_month = curr_month.replace(/5/, "juni");
			curr_month = curr_month.replace(/6/, "juli");
			curr_month = curr_month.replace(/7/, "augustus");
			curr_month = curr_month.replace(/8/, "september");
			curr_month = curr_month.replace(/9/, "oktober");
	
			$(this).html(curr_day + curr_date + " " + curr_month + " " + curr_year);
		
		});
		/* jQuery logica voor FOCUS pagina */
		$('img.showalt').mouseover(function(){
			var hoverclass = $(this).attr('id')+'m';
			$(this).attr('src', this.src.replace('.png', '-h.png'));
			// use the alt text of the image to fill a paragraph at the bottom
			$('p#focus-caption').text(this.alt);
	
			/* due to lack of ID's in menu CMS light, workarround with classes */
			if ($('#sub-navigation a').hasClass($(this).attr('id')+'m')) {
				$('#sub-navigation a.'+hoverclass).addClass('selectedPage');
			}
		});
		$('img.showalt').mouseout(function(){
			var hoverclass = $(this).attr('id')+'m';
			// return to the base image
			$(this).attr('src', this.src.replace('-h.png', '.png'));
			// remove the paragraph text
			$('p#focus-caption').text('');
	
			/* due to lack of ID's in menu CMS light, workarround with classes */
			if ($('#sub-navigation a').hasClass($(this).attr('id')+'m')) {
				$('#sub-navigation a.'+hoverclass).removeClass('selectedPage');
			}
		});
		$('.focus div#sub-navigation a').mouseover(function(){
			// get value of menu item and concatenate ID to valid image ID
			var str = $(this).text()+'ID';
			// go an look for the image to rollover and make sure the source is valid
			$('img#'+str).attr('src', $('img#'+str).attr('src').replace('.png','-h.png'));
			// use the alt text of the image to fill a paragraph at the bottom
			$('p#focus-caption').text($('img#'+str).attr('alt'));
		});
		$('.focus div#sub-navigation a').mouseout(function(){
			// get value of menu item and concatenate ID to valid image ID
			var str = $(this).text()+'ID' ;
			// return to the base image
			$('img#'+str).attr('src', $('img#'+str).attr('src').replace('-h.png','.png'));
			// remove the paragraph text
			$('p#focus-caption').text('');
		});

		var searchButton = $("input.searchButton");
		if(searchButton.val() != '') {
			searchButton.val('zoek');
		}
		var submitButton = $(".submitButtonContainer input.submitButton");
		if(submitButton.val() != '') {
			submitButton.val('verzenden');
		}
		var goBack = $(".blogBack a, .eventBack a");
		if(goBack.text() != '') {
			goBack.text("< ga terug");
		}
		var attachment = $(".postAttachment a");
		if(attachment.text() != '') {
			attachment.attr('title', 'klik op deze link om het bestand ('+attachment.text()+ ') te downloaden');
			attachment.text("download");
			attachment.attr('target', 'external_link');
		}
		var searchResults = $(".detail h1");
		if(searchResults.text() == 'Search Results') {
			searchResults.text("Zoekresulaten");
		}
		/* logica om bezoeker niet op 'laatste pagina' te laten komen */
		var selectedPage = $(".globalRootMenu  li.selectedPage a.selectedPage");
		var selectedPageRoot = $(".globalRootMenu  li.selectedPageRoot a.selectedPageRoot");
		if (selectedPage.text() == 'media'){
			$("#sub-navigation ul li a[href='/laatste-nieuws']").attr('href', '/media');
			$("#sub-navigation ul li a[href='/media']").addClass('selectedPage');
		} else if (selectedPageRoot.text() == 'media') {
			$("#sub-navigation ul li a[href='/laatste-nieuws']").attr('href', '/media');
			$("#sub-navigation ul li a[href='/media']").removeClass('selectedPage');
		}
		else {
			$("#sub-navigation ul li a[href='/media']").removeClass('selectedPage');
		}
	});

})(jQuery)
