//ajax.js

var delay = 7500; //set the frequency that check() runs
var rate = 1500; //set the rate of the fade
var container = '#current_count'; //text element or container for the numbers to go into;
var slider_open = false;

jQuery(document).ready(function(){//script to trigger async. refresh added AFTER page loads
    var head = document.getElementsByTagName('head')[0];
    var newScript = document.createElement('script');
    $(newScript).attr({type:'text/javascript', src: 'js/ajaxInsert.js'}).appendTo(head);
});

function check(){
    var oldCount = $(container).text();
    
    jQuery.ajax({
        url:'counter.aspx',
        dataType: 'text',
        cache: false,
        success: function(text) {
            var newCount = text;
            if(newCount != oldCount){
                $(container).fadeOut(rate, function() {
					var index = document.getElementById('index');
                    if((index.className != 'current')&& slider_open == false) {openSection();}
                    $(container).text(newCount).fadeIn(rate/2);
                });
            }
        },
        error: function() {
            clearInterval(ajaxTicker);
        }
    });
}

function openSection() {
    var headings = '#side_bar h2';
    var section = '#ajax_counter';
    jQuery(headings).removeClass('first');
    jQuery(section).slideDown(rate/3);
	slider_open = true;
}