function close_gallery()
{
    $("#motivcheck-gallery").animate(
        {
            opacity:0.0
        },500,function(){
            $("#motivcheck-gallery").remove();
            
			$("#loader-screen").animate(
		        {
		            opacity:0.0
		        },500,function(){
		            $("#loader-screen").css("display","none");
		        }
		    );
        }
    );
}

function motivcheck_page(d)
{
    if (animating) return;
    
    animating = true;
    var c = parseInt($("#motivcheck-current-image").val());
    var o = c;
    var t = 13;
    
    if (d)
    {
        c = (c+1) % t;
    } else {
        c = c-1;
        if (c < 0) c = t-1;
    }
    
    $("#lightbox-image-"+o).animate(
        {
            opacity:0.0
        },300,function(){
            $("#lightbox-image-"+o).css("display","none");
            
            $("#lightbox-image-"+c).css("display","block");
            $("#lightbox-image-"+c).animate(
                {
                    opacity:1.0
                },300,function(){
                    $("#motivcheck-current-image").val(c);
                    animating = false;
                }
            );
        }
    );
}

