$(document).ready( function()
{
	var curTabId = 'tabs-1';
	var busy = false;
	var rotate = true;
	
	featureRotate();
	
	$('#featured').bind( 'mouseover', function()
	{
		rotate = false;
	});
	
	$('#featured').bind( 'mouseout', function()
	{
		rotate = true;
	});
	
	$('#featured .ui-tabs-nav-item a').bind( 'mouseover', function()
	{
		var tabid = $(this).parent().attr('id');
		tabid = tabid.replace('nav-', '');
		
		featureSlide( tabid );
	});
	
	function featureRotate()
	{
		rotateTimer = setInterval( function()
		{
			if( rotate )
			{
				var maxNum = 4;
				var curNum = curTabId.replace('tabs-', '');

				curNum++;
				if( curNum > 4 ) curNum = 1;

				featureSlide( 'tabs-' + curNum );
			}
		}, 7000 );
		
	}
	
	function featureSlide( tabid )
	{
		if( curTabId != tabid && !busy )
		{
			busy = true;
			$('#featured .ui-tabs-nav-item').removeClass('ui-tabs-selected');
			$('#featured #nav-' +tabid ).addClass('ui-tabs-selected');

			$('#featured div#' + curTabId ).fadeOut( 'fast', function() {
				$('#featured .ui-tabs-panel').hide();
				$('#featured div#' + tabid ).fadeIn();
			});
			
			curTabId = tabid;
			busy = false;
		}
	}
});
