var mod_onglet_current=""
// CSS helper functions
CSS = {
    // Adds a class to an element.
    AddClass: function (e, c) {
        if (!e.className.match(new RegExp("\\b" + c + "\\b", "i")))
            e.className += (e.className ? " " : "") + c;
    },
    
    // Removes a class from an element.
    RemoveClass: function (e, c) {
        e.className = e.className.replace(new RegExp(" \\b" + c + "\\b|\\b" + c + "\\b ?", "gi"), "");
    }
};

// Functions for handling tabs.
Tabs = {
    // Changes to the tab with the specified ID.
    GoTo: function (contentId, skipReplace) {
        // This variable will be true if a tab for the specified
        // content ID was found.
        var foundTab = false;

        // Get the TOC element.
        var toc = document.getElementById("toc");
        if (toc) {
            var lis = toc.getElementsByTagName("li");
            for (var j = 0; j < lis.length; j++) {
                var li = lis[j];

                // Give the current tab link the class "current" and
                // remove the class from any other TOC links.
                var anchors = li.getElementsByTagName("a");
                for (var k = 0; k < anchors.length; k++) {
                    if (anchors[k].id == "go_" + contentId) {
                        CSS.AddClass(li, "current");
                        foundTab = true;
                        break;
                    } else {
                        CSS.RemoveClass(li, "current");
                    }
                }
            }
        }

        // Show the content with the specified ID.
        var divsToHide = [];
        var divs = $$('.tab_content');
        for (var i = 0; i < divs.length; i++) {
            var div = divs[i];
            if (div.id == contentId)
               var divToDisplay = div;
            else
				div.style.display = "none";
        }
	
		//Display div
		if(divToDisplay)
			divToDisplay.style.display = "block";
			
		//Record Goto
		mod_onglet_current = contentId;
    },

    Init: function (contentId) {
        if(contentId && $("toc") && $("toc").select(".current").length==0)
        	Tabs.GoTo(contentId);
    }
};


var myrules = {
 	'.tab_onglet' : function(tab) {
 		//Recuperation du premier onglet
 		//Ou First ou le premier
 		if($('go_First'))
	 		Tabs.Init("First");
 		else
 		{
 			var onglet = $$('.tab_onglet_link');
 			var idonglet = onglet[0].id.replace("go_","");
	 		Tabs.Init(idonglet);
 		}
 	},
 	
 	'.tab_onglet_link' : function(link) {
 		link.onclick = function() {
 			Tabs.GoTo(link.id.replace("go_", ""));
 		}
 	}
 }
// Enregistrement des regles definies ci dessus dans Behaviour
Behaviour.register(myrules);
