// JavaScript Document

$(document).ready(function ($) { 
							
	$(window).bind ('load', resizeFrame);
	$(window).bind ('resize', resizeFrame);
	
	$("nav a").click(function() { 
							  
		if ($(this).children('img').attr('src').match('1.gif'))
			var change = true;
		else
			var change = false;
			
		resetMainNav();
		resetSubNav();

		if (change)
			$(this).children('img').attr('src', $(this).children('img').attr('src').replace('1.gif', '2.gif'));
			
		$(".inline_popup:visible").each(function() { 
			closeInlinePopup ($(this)); 
		}); 
		
		var url = $(this).attr('href').replace('/', '');
		
		doPopup (url);
		$(this).blur();
			
		return false;
							  
	});
	
	$("#subnav a").click (function () { 
									
		resetMainNav();
		resetSubNav();
		$(this).addClass('subnav_active');
		
		$(".popup_project:visible").each(function() { 
			closeInlinePopup ($(this)); 
		}); 
		
		var url = $(this).attr('href').replace('/', '');
		if (url == 'login') {
			
			$(".inline_popup:not(.popup_project):visible").each(function() { 
				closeInlinePopup ($(this)); 
			}); 
			
		}
		
		doPopup (url);
		$(this).blur();
			
		return false;
		
	});
	
	$(".inline_popup a.sluiten").click (function() { closeInlinePopup ($(this).parent()); $(this).blur(); return false; });
	
	$(".popup_list li a").click (function() {
		$(this).parent().parent().find("img").each (function() {
			if ($(this).attr('src') == '/images/img_red.gif')
				$(this).attr('src', '/images/img_white.gif');
		});
		$(this).children().attr('src', '/images/img_red.gif');
		$(this).parent().parent().siblings('.popup_img_large, div').fadeOut (200, function() { $(this).remove(); });
		
		$.page = $(this).parent().parent().parent().attr('id').replace('popup_', '');
		
		$.post ('ajax.php', { cmd: 'geefProject', project_id: $(this).attr('data') }, function(data) {
			var temp = data.split(':inhoud:');
			$('#popup_' + $.page + ' img:first').after ('<img src="' + temp[0] + '" alt="" class="popup_img_large nodisplay" id="' + $.page + '_large" />');
			$('#popup_' + $.page + ' ul').after ('<div id="' + $.page + '_content" class="nodisplay">' + temp[1] + '</div>');
			$('#' + $.page + '_content, #' + $.page + '_large').fadeIn (300, function() { $(this).removeClass('nodisplay'); });
		});
		
	});
	
	$('#login_submit').click(function() {
		$('login_error').hide();
		var error = '';
		if ($('#emailadres').val() == '')
			error += 'E-MAILADRES IS LEEG<br />';
			
		if ($('#password').val() == '')
			error += 'WACHTWOORD IS LEEG<br />';
			
		if (error == '') {
			
			$.post('/ajax.php', { cmd: 'login', emailadres: $('#emailadres').val(), password: $('#password').val()}, function(data) {
				if (data == 'false')
					$('#login_error').html('INCORRECTE GEGEVENS INGEVULD').show();
				else {
					$('#login_error').html('');
					$('#login_content').load ('/ajax.php', { cmd: 'fileListing' });
					$('#upload').fadeIn();
					$('#login_form').fadeOut(300);
					$('#logout').fadeIn(300);
				}
			});
			
		} else
			$('#login_error').html(error).show();
	
		return false;
	});
	
	$("#logout").click(function() { 
								
		$('#login_form').fadeIn(300);
		$('#logout').fadeOut(300);
		$('#login_content').html('');
		$('#upload').fadeOut(300);
		
		return false;
	});

});
