// Let's make the count fetch from a source elsewhere ie on myupdates and it's updated by CRON

// The SetInterval can then go off and read the value

	var roomNum = "033186";
	var wallNum = "130840";
	var wN = wallNum;
	var rN = roomNum;
	
	// add AJAX here
	function updateRoom() {
    	jQuery.get("/js/counter.php?type=room", 
    	    function(data){
            roomNum = data;
        });
    }
	
	function updateWall() {
    	jQuery.get("/js/counter.php?type=wall", function(data){
            wallNum = data;
        });
    }
	
	var imgLoc = "/images/numbers/";
	function preload() {
		outstring = "";
		for(i=0;i<10;i++) {
			outstring += "<img src='" + imgLoc + i + ".jpg' />";
		}
		jQuery("#preload").html(outstring);
	}
	
	function stepCount(counter) {
	    if(counter == "roomcount") {
	        updateRoom();
	        if(!isNaN(roomNum) && roomNum.length >= 5) {
		        var startcount = roomNum.toString();
            } else {
                startcount = rN;
            }
	    } else {
	        updateWall();
	        if(!isNaN(wallNum) && wallNum.length >= 5) {
		        var startcount = wallNum.toString();	        
            } else {
                var startcount = wN;
            }
	    }
		var scTmp = new Array();
		if(startcount.length == 5) {
	        startcount = "00" + startcount;
	    }
	    if(startcount.length == 6) {
	        startcount = "0" + startcount;
	    }
		scTmp = startcount.split("");
		var outstring = "";
		jQuery.each(scTmp, function() {
			outstring += "<img src='" + imgLoc + this + ".jpg' />";
		});
		var countBase = "#" + counter;
		jQuery(countBase).html(outstring);
	}
	
	jQuery(document).ready(function() {
		preload();
		stepCount('roomcount');
	    stepCount('wallcount');
		setInterval("stepCount('roomcount')",2000);
		setInterval("stepCount('wallcount')",5000);
		
	});
