//*** This code is copyright 2002-2003 by Gavin Kistner and Refinery; www.refinery.com
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt
//*** Reuse or modification is free provided you abide by the terms of that license.
//*** (Including the first two lines above in your source code satisfies the conditions.)

//***Adds a new class to an object, preserving existing classes
function AddClass(obj,cName){ KillClass(obj,cName); return obj && (obj.className+=(obj.className.length>0?' ':'')+cName); }

//***Removes a particular class from an object, preserving other existing classes.
function KillClass(obj,cName){ return obj && (obj.className=obj.className.replace(new RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),'')); }

//***Returns true if the object has the class assigned, false otherwise.
function HasClass(obj,cName){ return (!obj || !obj.className)?false:(new RegExp("\\b"+cName+"\\b")).test(obj.className) }


/**
 * Make tabs
 */
var cName = 'tabset_tab';
var tabs = Array();

function showTab(){
    target = this.href.substr(this.href.indexOf('#')+1);
    hideTabs(target);
    AddClass(document.getElementById(target), 'tabset_content_active');
    return false;
}

function hideTabs(id){
    for (i=0; i<tabs.length; i++){
        if (tabs[i] != id){
            KillClass(document.getElementById(tabs[i]), 'tabset_content_active');
            AddClass(document.getElementById(tabs[i]), 'tabset_content');
        }
    }
}

function makeTabs(){
    var links = document.getElementsByTagName('a');

    for(i=0; i<links.length; i++){
        if (HasClass(links[i], cName)){
            tabs.push(links[i].href.substr(links[i].href.indexOf('#')+1));
            links[i].onclick = showTab;
        }
    }

    //Tab indiqué dans l'url ?
    //histoire de pouvoir se refiler un lien...
    var id = window.location.href.split('#')[1];
    for (i=0; i<tabs.length; i++){
        if (tabs[i] == id){
            hideTabs(id);
            AddClass(document.getElementById(id), 'tabset_content_active');
        }
    }
}

//window.onload=makeTabs;
//AttachEvent(window,'load',makeTabs,false);
addLoadEvent(makeTabs);