var currentHash = '';
var firstContent = '';
function contentLoad(uri) {
    if (! uri) {
        return true;
    }
    var coords = getCoords(document.getElementById('content'));
    var progressbar = document.getElementById('progressbar');
    progressbar.style.left = coords['left'] + 'px';
    progressbar.style.top = coords['top'] + 'px';
    progressbar.style.display = '';
    JsHttpRequest.query(
        '/ajax' + uri,
        { },
        function(result, errors) {
            if (result['content']) {
                document.getElementById('content').innerHTML = result['content'];
            }
            progressbar.style.display = 'none';
            return false;
        },
        false
    );
    window.location.hash = '#ajax' + uri;
    currentHash = window.location.hash;

    JsHttpRequest.query(
        '/ajax' + '/random/restaurant/show',
        { },
        function(result, errors) {
            if (result['content']) {
                document.getElementById('randRest').innerHTML = result['content'];
            }
//             progressbar.style.display = 'none';
            return false;
        },
        true
    );

    return false;
}
function bookmarkLoad() {
    if ('#ajax/' == window.location.hash.substring(0, 6)) {
        contentLoad(window.location.hash.substring(5));
    }
}
function historyLoad() {
    var hash = window.location.hash;
    if ('#ajax/' == hash.substring(0, 6) && currentHash != hash) {
        contentLoad(hash.substring(5));
    } else if ('#ajax/' != hash.substring(0, 6) && currentHash) {
        currentHash = '';
        document.getElementById('content').innerHTML = firstContent;
    }
    setTimeout('historyLoad()', 100);
}
function getCoords(element) {
    var left = element.offsetLeft;
    var top = element.offsetTop;
    for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
        left += parent.offsetLeft - parent.scrollLeft;
        top += parent.offsetTop - parent.scrollTop
    }
    return {
    	left: left,
    	top: top,
    	width: element.offsetWidth,
    	height: element.offsetHeight
    };
}

