
/*  tab_navigation.js
    author: erick bianes
    version: 1.0
    !?! does not work in IE 5
*/

var config = {
  id: "navigation", // ul id='navigation'
  trigger: "" + document.title, 
  anchor_start: "Gerry's Grill - ",
  anchor_end: "|",
  defaults: "Home",
  active: "selected"
}

// library for functions
var fxn = {
	getId: function(id) {	return document.getElementById(id); },
	delId: function(attr_id) { var e = document.getElementById(attr_id); e.id = null; },
	selId: function(e, val) { e.setAttribute('id', val); e.id = val; /* for IE */ },
  // encoding of &nbsp; and &amp; 
  encodeHTML: function(txt) { var char = txt.replace(/\&nbsp;/g, ' ');
                                char = char.replace(/\&amp;/g, '&'); 
                                return char; }
}

function set_VTab(group, anchor1, anchor2, _default) {
  var group = fxn.getId(group);
  var members = [];
  var title = '' + config.trigger;
  var page_title = title.indexOf(anchor2) > 0 ? title.substring(title.indexOf(anchor1) + anchor1.length, title.indexOf(anchor2) - 1) : _default ;
  
  for(var m = group.firstChild; m != null; m = m.nextSibling) {
    if(m.nodeType == 1) members.push(m.firstChild); // if child is an html tag i.e. <a>, add the child to members
  }
  
  var len = members.length;
  for(var i=0; i < len; i++) {
    var link_title = '' + fxn.encodeHTML(members[i].innerHTML);
    if(link_title === page_title) fxn.selId(members[i], config.active);   
  }  
}

// set Tabs on <ul id='navigation'>  
window.onload = function() { set_VTab(config.id, config.anchor_start, config.anchor_end, config.defaults); };
