jQuery(function(){
	var current_tab = 1; // start with first tab.
	var tab_count = 1; // loop counter.
	var tab_auto = 10; // how many seconds to wait for auto scroll
	// first name each of our tab contents.
	jQuery('#tab_content li').each(function(){
		jQuery(this).attr('rel',tab_count);
		if(tab_count != current_tab)jQuery(this).hide(); // hide all that are not current.
		else jQuery(this).show();
		tab_count++;
	});
	tab_count = 1;
	// bind the clicks.
	function tab_gogo(this_tab_id){
		// find an existing tab, fade it out.
		var tab = jQuery('#home_tabs li a[rel='+this_tab_id+']');
		if(current_tab){
			if(jQuery.browser.msie)jQuery('#tab_content li[rel=' + current_tab + ']').hide();
			else jQuery('#tab_content li[rel=' + current_tab + ']').fadeOut();
		}
		// find the tab to display... fade it in.
		if(jQuery.browser.msie)jQuery('#tab_content li[rel=' + this_tab_id + ']').show();
		else jQuery('#tab_content li[rel=' + this_tab_id + ']').fadeIn();
		// remove any old current list items.
		jQuery('#home_tabs li.current').removeClass('current');
		// change the state of the holding li item to current for styling.
		jQuery(tab).parent('li').addClass('current');
		current_tab = this_tab_id;
	}
	jQuery('#home_tabs li a').each(function(){
		// each of the a links, find it's count and set a callback on the a link.
		jQuery(this).attr('rel',tab_count);
		// just for first time loading.
		if(tab_count == current_tab)jQuery(this).parent('li').addClass('current'); 
		jQuery(this).click(function(){
			var this_tab_id = jQuery(this).attr('rel');
			tab_auto = 0;
			tab_gogo(this_tab_id);
			return false;
		});
		tab_count++;
  	});
	if(tab_auto){
		function tab_auto_gogo(){
			if(!tab_auto)return;
			// how many tabs are there.
			var this_current = current_tab;
			if(this_current >= jQuery('#home_tabs li a').size())this_current = 1;
			else this_current++;
			tab_gogo(this_current); //jQuery('#home_tabs li a[rel='+this_current+']').click();
			setTimeout(tab_auto_gogo,tab_auto*1000);
		}
		setTimeout(tab_auto_gogo,tab_auto*1000);
	}
});
