/* --[ Ugly anti-copy content js ]-- */
var message="© 2012 Projectable bv All rights reserved";
function clickIE4(){if(event.button==2){alert(message);return false;}}function clickNS4(e){if(document.layers||document.getElementById&&!document.all){if(e.which==2||e.which==3){alert(message);return false;}}}if(document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS4;}else if(document.all&&!document.getElementById){document.onmousedown=clickIE4;}document.oncontextmenu=new Function("alert(message);return false");if(document.body && (typeof document.body.style.MozUserSelect != "undefined")) document.body.style.MozUserSelect = 'none';

if(window.jQuery) {

	function handleMenuHover(element) {
		// Get the content that needs to be shown
		var cur = $(element).find('ul');
		// Get the content that needs to be hidden
		var old = $('#main nav ul li ul');
		// Make sure the content that needs to be shown isn't already visible
		if(cur.is(':visible'))
			return false;
		// Hide the old content
		old.slideUp(500);
		// Show the new content
		cur.stop().slideDown(500);
	}

	$(document).ready(function() {

		/* --[ ugly content selecting prevention ]-- */
		$('body')
			.bind('selectstart', function(e) { console.log(e); return false; })
			.bind('dragstart', function(e) { console.log(e); return false; })
			.bind('select', function(e) { console.log(e); return false; });

		/* --[ searchbox ]-- */
		$('#siteSearch')
			.each(function() {
				if($(this).attr('placeholder') != '' || $(this).val() == $(this).attr('placeholder'))
					$(this).addClass('default').val($(this).attr('placeholder'));
			})
			.focus(function() {
				if($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))
					$(this).removeClass('default').val('');
			})
			.blur(function() {
				if($.trim($(this).val()) == '' || $(this).val() == $(this).attr('placeholder'))
					$(this).addClass('default').val($(this).attr('placeholder'));
			});

		/* --[ print button ]-- */
		$('li.print a')
			.click(function(e) {
				e.preventDefault();
				window.print();
			});

		/* --[ footer nav ]-- */
		$('footer li:last').addClass('last');

		/* --[ external links ]-- */
		$('a[rel*="external"]').attr('target', '_blank');

		/* --[ navigation interaction ]-- */
		var MaxAmount	= 0,
			RuleHeight	= 0,
			timeout		= false;
		$(function() {
			// Hide all the content except the current or first
			$('#main nav ul ul').hide();
			if($('#main nav li.open ul').length <= 0) {
				$('#main nav li:first ul').show();
			} else {
				$('#main nav li.open ul').first().show();
			}

			// Calculate subnav-itemheight and set all sub-ul's to same height
//			$("#main nav ul ul").each(function() {
//				MaxAmount = Math.max(MaxAmount, $(this).children().length);
//			});
//			RuleHeight = Math.round(($("#main nav ul ul:visible").first().height() / $("#main nav ul ul:visible").first().children().length * 100) / 100);
//			$("#main nav ul ul").css('height', (MaxAmount * RuleHeight) + 'px');
			$("#main nav ul ul").css('height', '126px');

			// Handle the hover / mouseover event
			$('#main nav > ul > li:has(ul)')
				.addClass('node')
				.hoverIntent(
					function() {
						// Get the content that needs to be shown
						var cur = $(this).find('ul');
						// Get the content that needs to be hidden
						var old = $('#main nav ul li ul');
						// Make sure the content that needs to be shown isn't already visible
						if(cur.is(':visible'))
							return false;
						// Hide the old content
						old.slideUp(500);
						// Show the new content
						cur.stop().slideDown(500);
					},
					function() {
						return;
					}
				)
				.find('> a').click(function(e) {
					e.preventDefault();
					// Get the content that needs to be shown
					var cur = $(this).parent().find('ul');
					// Get the content that needs to be hidden
					var old = $('#main nav ul li ul');
					// Make sure the content that needs to be shown isn't already visible
					if(cur.is(':visible'))
						return false;
					// Hide the old content
					old.slideUp(500);
					// Show the new content
					cur.stop().slideDown(500);
					// Stop following link
					return false;
				});
			$('#main').delegate('nav', 'mouseout', function() {
				if($('#main nav > ul > li.open').length > 0) {
					timeout = setTimeout("handleMenuHover($('#main nav > ul > li.open'));", 5000);
				}
			});
			$('#main').delegate('nav', 'mouseover', function() {
				clearTimeout(timeout);
			});
		});

		/* --[ image slideshow ]-- */
		var $images = $('#visuals img'),
			$slideshow = $('#headerVisuals'),
			$slideshowclone = $slideshow.clone().attr('id', 'headerVisualWrap').html('').insertBefore($slideshow);
		$slideshow.html('').append($images).cycle({
			fx:			'fade',
			speed:		1000,
			timeout:	5000
		});
		$('#visuals').html('');

	});

}
