ajax.history = {
    'button'  : '.history_back',
    'current' : 0,
    'hash' : {
        0  : '#'
    }
};

ajax.history.init = function() {

    $(ajax.history.button).bind('click.history', function () {
        ajax.history.back();
    });

}

ajax.history.add = function(url) {
//console.info('*ajax.history.add*');

    $(ajax.history.button).attr('href',ajax.history.hash[ajax.history.current]);
    ajax.history.current++;
    ajax.history.hash[ajax.history.current] = url;

}

ajax.history.back = function() {
//console.info('*ajax.history.back*');

    if (ajax.history.current > 0) {
        ajax.history.current--;
    }


}


ajax.history.try_add = function(url) {
//console.info('*ajax.history.try_add*');

    ex_url      = ajax.history.hash[ajax.history.current - 1];
    current_url = ajax.history.hash[ajax.history.current];

//    console.warn('comparing urls: '+url+' - '+ex_url);
    if (url == ex_url) {
        return;
    }
//    console.warn('comparing urls: '+url+' - '+current_url);
    if (url == current_url) {
        return;
    }

    ajax.history.add(url);

}


ajax.history.update_href = function() {

    if (ajax.history.current > 0) {
        $(ajax.history.button).attr('href',ajax.history.hash[ajax.history.current-1]);
    }

}