function slideSwitch() {
	$('#beeld img').css('visibility', 'visible');
    var $active = $('#beeld img.active');

    if ( $active.length == 0 ) $active = $('#beeld img:last');

    var $next = $active.next().length ? $active.next() : $('#beeld img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
    .addClass('active')
    .animate({opacity: 1.0}, 2500, function() {
        $active.removeClass('active last-active');
    });
}

function pageAtBottom() {
	if ($(window).scrollTop() + $(window).height() == $(document).height()) {
		return true;
	} else {
		return false;
	}
}

/* function pageNearBottom(offset) {
	offset = parseInt(offset);
	
	if (! offset) {
		offset = 100;
	}
	
	if ($(window).scrollTop() + $(window).height() > $(document).height() - ofsset) {
		return true;
	} else {
		return false;
	}
} */

function pageNearBottom() {
	if ($(window).scrollTop() + $(window).height() > $(document).height() - $('#footer').height()) {
		return true;
	} else {
		return false;
	}
}

$(document).ready(function() {
	if ($('#beeld img').length > 1) {
		setInterval("slideSwitch()", 5000 );
	}

	$('#loginToggle a, #loginClose a, #loginOverlay').click(function() {
		if ( $('#loginToggle').hasClass('active') ) {
			$('#login').hide();
			$('#loginOverlay').hide();
			$('#loginToggle').removeClass('active');
		} else {
			$('#login').show();
			$('#loginOverlay').show();
			$('#loginToggle').addClass('active');
			$('#login #userEmail').focus();
		}
		
		return false;
	});
	
	$('#login form').submit(function() {
		var error = false;
		
		if ( $('#login #userEmail').val().length > 0 ) {
			$('#login #userEmail').removeClass('error');
		} else {
			$('#login #userEmail').addClass('error');
			$('#login #userEmail').focus();
			
			error = true;
		}
		
		if ( $('#login #userPassword').val().length > 0 ) {
			$('#login #userPassword').removeClass('error');
		} else {
			$('#login #userPassword').addClass('error');
			
			if (! error) {
				$('#login #userPassword').focus();
			}
			
			error = true;
		}
		
		if (error) {
			return false;
		} else {
			return true;
		}
	});
	
	/* $('#menuLeft').find('li').mouseover(function() {
		$(this).children('ul.inactive').slideDown(300);
	}).mouseleave(function() {
		$(this).children('ul.inactive').slideUp(300);
	}); */
});

