// Written by Sean Treadway 2006 sean@treadway.info
// Free Beer and Free Speech - the best license of all
// http://sean.treadway.info/articles/2006/05/17/simple-in-page-tabs-with-prototype-js-selector

TabControl = function(control_id, options) {
  var id = "#" + control_id;
  $$(id+' ul.tab-navi li a').each(function(a,x) {
    var page = a.readAttribute('href').match(/[-_\w]+$/i)[0];

		
    if (page != options['current']) { $(page).hide() } 
    else { $(a.parentNode).addClassName('current') }
    
    if  ((x == 0) && (options['current'] == undefined) ) { $(page).show(); $(a.parentNode).addClassName('current') };


    Event.observe(a, 'click', function(e) {
      $$(id+' ul.tab-navi li.current').each(function(e) { e.removeClassName('current'); })
      $$(id+' .tab_page[id!='+page+']').each(function(e) { e.hide() });
      $(a.parentNode).addClassName('current');
      $(page).show();
      Event.stop(e);
      a.blur();
    });
  });
};
