/* IDENTIFY START */
var identifier = 0;

/* DOM READY */
$(function() {
	
	//menu uitklap items mogen niet buiten design vallen
	var totalWidth = 0;
	var mainMenuWidth = $('#mainMenu').width();
	$("#mainMenu > ul > li").each(
		function( intIndex ){
			var parentWidth = $(this).width()+1;
			$(this).children('.mainmenuFoldoutContainer:first').each(
				function( intIndex ){
					var width = $(this).width();
					if(totalWidth+width>mainMenuWidth){
						var margin = (totalWidth+width)-mainMenuWidth;
						$(this).css('margin-left','-'+String(margin)+'px');
					}
				}		
			);
			totalWidth = totalWidth + parentWidth;
		}
	);
	
	/* external links */
	$('a[rel="external"]').attr('target', '_blank');
	
	/* popup links */
	$('a[rel="popup"]').click(function() {
		var name = $(this).attr('id');
		if(!name) {
			name = 'identifier_' + ++identifier;
			$(this).attr('id', name);
		}
		var width   = height = 650,
		    top     = left   = 0,
		    percent = 80;
		if(!!screen.width) {
			width = Math.ceil((screen.width / 100) * percent);
			left  = Math.ceil((screen.width - width) / 2);
		}
		if(!!screen.height) {
			height = Math.ceil((screen.height / 100) * percent); 
			top    = Math.ceil((screen.height - height) / 2);
		}
		window.open($(this).attr('href'), name, 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=yes');
		return false;
	});
	
	/* download links */
	$('a[rel="download"]').click(function() {
		var file = $(this).attr('href'),
		    ext  = file.split('.').pop().toLowerCase();
		if($.inArray(ext, ['gif', 'png', 'jpg', 'jpeg', 'bmp']) > -1) {
			window.open(file);
			return false;
		}
	});
	
	$('img').live('contextmenu', function() {
		return false;
	});
});
