jQuery.noConflict();
(function($) {
	$(document).ready(function() {
		// External links in new window
		$('a[href^="http://"]').attr('rel', 'external');
		$('a[rel="external"]').attr('target', '_blank');
		
		// Attach slideshow to content elements
		$('.slideshow').each(function() {
			var imHeight = 0;
			$('.csc-textpic .csc-textpic-imagewrap img', this).each(function(){
				if ($(this).height() > imHeight) {
					imHeight = $(this).height();
				}
			});
			$('.csc-textpic .csc-textpic-imagewrap', this).height(imHeight).cycle({pause:1});
		});
		// Open project overlay
		$('a[class=overlay]').each(function() {
			$(this).attr('href', $(this).attr('href') + '?type=10');
			$(this).colorbox({onComplete:function() {
				$project = $('#ajax_content .tx-tfeproject-project-controller');
				$('.detail .images', $project).cycle({
					prev: $('a.prev', $project),
					next: $('a.next', $project),
					speed: 500,
					after: function() {
						var matches = $(this).attr('class').match(/i(\d)/);
						$('.nav .page .current', $(this).parents('.detail')).html(parseInt(matches[1]) + 1);
						$(this).parent().height($(this).height());
					}
				});
				var manPaused = false;
				$('a.play-pause', $project).bind('click', function(evt) {
					evt.preventDefault();
					if ($(this).hasClass('play')) {
						$('.detail .images').get(0).cyclePause = 0;
						manPaused = false
					} else {
						$('.detail .images').get(0).cyclePause = 1;
						manPaused = true
					}
					$(this).toggleClass('pause').toggleClass('play');
				});
				$('.image-wrap', $project).hover(
					function() {
						$('.detail .images').get(0).cyclePause = 1;
						$('.nav a.play-pause').removeClass('pause').addClass('play');
					},
					function() {
						if (!manPaused) {
							$('.detail .images').get(0).cyclePause = 0;
							$(this).toggleClass('pause');
							$('.nav a.play-pause').addClass('pause').removeClass('play');
						}
					}
				);
			}, close: 'venster sluiten', scrolling: false});
		});
		$('.tx-tfeproject-project-controller .list .even').after('<div class="clearer"></div>');
	});
})(jQuery);
