
// This array contains the history, in form of a array with the commands
// that is executed to run as an eval
var back_history = new Array();

// This is a lock, make sure history entrys are not added as new when you go back and forward
var dont_add=false;

// This is the current page history nr shown, also a lock to make sure go_back_to does not execute if we are not walking in history.
var current_page=0;

// Call this with an eval value, to add that command on the history stack.
function back_add(command)
{
    if(dont_add)
	return;
	
    // Here is a good place to new page to google analytics.
    try {
	pageTracker._trackPageview("/"+command.replace("(","/").replace(",","/").replace(")", ""));
    } catch(e) {}
	
    console.info("Add back command: " + command);
    back_history.push(command);

    current_page=back_history.length-1;

    var backframe = document.getElementById("backframe");
    // This is an url to a javascript that just executes 'parent.go_to_page(cnt)'
    backframe.src="/bc.php?cnt=" + current_page;
}

// Use this command to navigate in history.
function go_back_to(go_to_page)
{
    if(go_to_page == current_page)
	return;
	
    // Get entry in stack
    var last=back_history[go_to_page];
    console.warn("go_back_to ["+go_to_page+"]: " + last);
    
    // Lock so this command wont add again to stack
    dont_add=true;
    eval(last);
    dont_add=false;

    // Set this page as current shown
    current_page=go_to_page;
}