// custom tabs plugin. Overwrites jQuery UI's tabs function to work with classes instead of id's
// (to make it compatible with template.js)

jQuery.fn.tabs = function(){
	// keep reference to object
	var that = this;
	
	// hide all tabs, except the first one
	var nr = 0;
	this.find('div.tab').each(function(){
		if(nr > 0){
			$(this).hide();
		}
		nr++;
	});

	nr = 0;
	// add events to menu items
	this.find('ul li a').each(function(){
		// make first li active
		if(nr === 0){
			$(this).addClass('active opacity8');
		}else{
			$(this).addClass('opacity5');
		}
		
		$(this).click(function(){
			var current = this;
			
			// make the li active (and all others inactive)
			$(that).find('ul li a').each(function(){
				if($(this).attr('href') == $(current).attr('href')){
					$(this).addClass('active opacity8');
				}else{
					$(this).removeClass('active');
					$(this).addClass('opacity5');
				}
			});
			
			
			// get classname that has to be matched
			var tabId = $(this).attr('href').substr(1);
			
			// find tab that matches that classname
			$(that).find('div.tab').each(function(){
				if($(this).hasClass(tabId)){
					$(this).show();
				}else{
					$(this).hide();
				}
			});
			
			// we don't want the a href to do anything...
			return(false);
		});
		nr++;
	});
	
	
	/*
		*/
	
	
}

