/*

There is plenty of work to still do on this script. There are several parts in it that could use fine tunning. 
For the most part the functionality is done but the code could definitely be improved. 

Bedrich 

*/


function tab(path)
{
	var link_path = path + " li" + " a";
	var href_path = path + " li" + " a[href]";
	var fragments = $(href_path);
	var links = $(link_path);
	var tabbed_divs = [];
	
	// gathers all fivs belonging to the tab system
	fragments.each(function(i)
	{
		var href = this.toString();
		tabbed_divs[i] = $(href.slice(href.indexOf("#")));
	});
	
	// hide tabbed divs except for the first one
	hideDivs(tabbed_divs,0);
	
	// create navigation and current state for selected link
	links.each(function(i)  
	{			
		if(i==0)
		{
			$(this).addClass("current");
		}
		
    	$(this).click(function() 
     	{  
     		links.removeClass("current");     		
     		$(this).addClass("current");
        	var target = $(this).attr("href");
        	hideDivs(tabbed_divs,-1);    
         	$(target).fadeIn("slow");  
         	return false;
    	});  
	});  			
}
			
function hideDivs(tabbed_divs, x)
{
	for(var i=0; i<tabbed_divs.length; i++)
	{
		if (i!=x)
		{
			tabbed_divs[i].css("display","none");
		}
	}
}