var history_changed = function(newLocation, historyData)
{
  if (newLocation != null) show_item(newLocation, false);
}

function detect_item()
{
  var section = location.hash;
  if (section != null && section.length > 1 && section.charAt(0) == '#')
  {
    show_item(section.substring(1), false);
  }
}

window.dhtmlHistory.create({
        toJSON: function(o) {
                return Object.toJSON(o);
        }
        , fromJSON: function(s) {
                return s.evalJSON();
        }
});

window.onload = function() {
        dhtmlHistory.initialize();
        dhtmlHistory.addListener(history_changed);
        detect_item();
};

function show_item(item, add_to_history)
{
  if (item == null || item == '') return;

  if (item != current_item)
  {
    var current_item_name = 'item_' + current_item.replace(/-/g, '_');
    var item_name = 'item_' + item.replace(/-/g, '_');

    if (current_item != '') $(current_item_name).className = unselected_class;

    $(item_name).className = selected_class;
    current_item = item;
    if (add_to_history) dhtmlHistory.add(item, null);
  }
}
