function showContent(linkid) {	
	$('.content-wrapper').fadeOut('fast', function(){
		$('.content-wrapper > div').hide('fast');
		$('.content-wrapper #' + linkid + '-content').show('fast', function(){			
				window.resetShopTitles();
				$('.tab a').css({'background-position':'left 0'});
				$('#' + linkid).css({'background-position':'left -43px'});
			});
		$('.content-wrapper').fadeIn('slow');
	});
}

function rotateContent() {
	var max_count	= '', 
		link_ids		= new Array(),
		linkid		= '';
		
	// Find the currently displayed item ( if none choose 1 ) 
	$('.tab a').each(function(i){
		link_ids[i]	= this.id;			
		
		if ($('#link-' +i + '-content').css('display') == 'block') {
			linkid	= this.id;
		}
	});
	
	// If no link id, then find the first one in the list.
	if (!linkid || linkid == '') {
		linkid	= $('.tab a').eq(0).attr('id');
	}

	// If this is the last tab...
	if (parseFloat(linkid) == link_ids.length) {
		linkid	= $('.tab a').eq(0).attr('id');	
	}
	
	// Show that link id.
	if (linkid && linkid != '' && typeof linkid != 'undefined') {
		showContent(linkid);
	} else {
		alert('Error: ' + linkid);
	}
}

$(document).ready(function() {

	var interval_id	= setInterval(function(){
		rotateContent();
	}, 4000);
	
	$('.tab a').bind('mouseover',
   	function() {
   		clearInterval(interval_id);
			showContent(this.id);
		}
   );

   $('.tab').bind('mouseleave',
   	function() {
			interval_id	= setInterval(function(){
				rotateContent();
			}, 4000);
		}
   );
   
   // Pause automation.
   $('.content-wrap').bind('mouseenter', function(){
		clearInterval(interval_id);
   })
   // Plauy automation.
   $('.content-wrapper').bind('mouseleave', function(){
		interval_id	= setInterval(function(){
			rotateContent();
		}, 4000);
   })
   
});	