    var curId = 0;
    var loadCount = 0;
    var totalImages = 5;
    
    $("document").ready( function () {
    
        $("#splashImage").parent().click( function() { nextImage(); return false; });
        
        /* display the animation of the candle burning out */
        
        // Preload the images
        for(var i = 0; i < totalImages; i++) {
            $("<img />")
                .attr("src", "images/splash_stage0" + (i+1) + ".png")
                .attr("id", "image" + i)
                .css("position", "absolute")
    	        .css("top", "50%")
    	        .css("left", "50%")
    	        .css("margin", "-295px 0 0 -4px")
    	        .css("width", "400px")
    	        .css("height", "190px")
    	        .css("z-index", "1" + i)
    	        .hide()
    	        .load( function(){ loadCount++ })
                .appendTo("body");
        }
        
        $("<div />")
            .attr("id", "flicker")
            .css("position", "absolute")
    	    .css("top", "50%")
    	    .css("left", "50%")
    	    .css("margin", "-164px 0 0 10px")
    	    .css("width", "52px")
    	    .css("height", "48px")
    	    .css("z-index", i)
    	    .appendTo("body");
    	
    	$("<img />")
    	    .attr("src", "images/flicker_stage00.png")
    	    .attr("width", "52")
    	    .attr("height", "48")
    	    .appendTo("#flicker");

        
        $.timer(100, function (timer) {
            if(loadCount == totalImages) {
                timer.stop();
                //nextImage();
            }
        });
        
        $.timer(1000, function (timer) {
            var flickNum = Math.round(Math.random() * 9);
            $("#flicker").css("background", "url(images/flicker_stage0" + flickNum + ".png)");
            $("#flicker img").fadeOut(500, function() { $("#flicker img").attr("src", "images/flicker_stage0" + flickNum + ".png").show(); } );
        });
        
                
            
    });
    
    
    function nextImage() {
        
        curId++;
        
        if($("#image" + curId).length == 1) {
            $("#image" + curId).fadeIn(1000, nextImage);
        } else {
            setInterval('window.location=\'index2.php\'', 500);
        }
                    
    }
