$(function() {
	/* afrondingen in menu */
	$('#header .menu li a').append('<div class="links"></div><div class="rechts"></div>');

	/* HTML5 placeholder compatibility fix voor oude browsers */
	if (!("placeholder" in document.createElement("input"))) {
		$('input[placeholder]').each(function() {
			$(this).val($(this).attr('placeholder'));
		}).focus(function() {
			$(this).val('');
		}).blur(function() {
			if ($(this).val()=='') {
				$(this).val($(this).attr('placeholder'));
			}
		});
	}
	
	/* mouseover grayscale / full color */
	$('.grayscale').mouseover(function() {
		$(this).css('background-image', $(this).css('background-image').replace('grayscale', 'color'))
	}).mouseout(function() {
		$(this).css('background-image', $(this).css('background-image').replace('color', 'grayscale'))
	});
	
	/* slideshow homepage */
	$('.slideshow-next').click(function() {
		// workaround: alle posities weer naar begin
		$('.slideshow li').css('left',0);
		// schuif opzij en verplaats in DOM-structuur
		$('.slideshow li:last').animate({left: $('.slideshow').width()}, {duration: 1000, complete: function() {
			$('.slideshow').prepend($('.slideshow li:last').css('left',0));
		}});
	});
	
	/* overlay klik */
	$('.overlay').click(function() {
		location.href=$('a:first').attr('href');
	});
	
	/* twitter */
	$.ajax({
		url: 'http://twitter.com/status/user_timeline/wmogo.json?count=10&callback=?',
		dataType: 'json',
		type: 'GET',
		success: function(data, textStatus, jqXHR) {
			$.each(data, function(i,item){
				if (i<2) {
					var d = new Date(item.created_at);
					var text = item.text;
					text = text.replace(/http(s)?\:\/\/[^\s]+/igm,function(m) {
						return '<a href="' + m + '" target="_blank">' + m + '</a>';
					});
					$('.twitter').append($('<div class="kader_item"><span class="datum">' + d.getDate() + '.' + (d.getMonth()+1) + '.' + d.getFullYear() + '</span><br/>' + text + '</div>'));
				}
			});
			// hoogte bijstellen
			$('.kader_home_container').each(function() {
				var maxHeight = 0;
				for (i=0; i<this.childNodes.length; i++) {
					if (this.childNodes[i].tagName) {
						var h = $(this.childNodes[i]).outerHeight() + $(this.childNodes[i]).position().top;
						if (h>maxHeight) {
							maxHeight = h;
						}
					}
				}
				$(this).height(maxHeight);
			});
		}
	});

	/* homepage kaders */
	$('.kader_home_container').each(function() {
		var maxHeight = 0;
		for (i=0; i<this.childNodes.length; i++) {
			if (this.childNodes[i].tagName) {
				var h = $(this.childNodes[i]).outerHeight() + $(this.childNodes[i]).position().top;
				if (h>maxHeight) {
					maxHeight = h;
				}
			}
		}
		$(this).height(maxHeight);
	});
});
