function showContent(linkid) {	
   // Update the tab rollver effect to select item.
   $('.tab a').css({'background-position':'left 0'});
   $('#' + linkid).css({'background-position':'left -43px'});

	$('.content-wrapper').fadeOut('fast', function(){
		$('.content-wrapper > .content-block').hide('fast');  // Hide all content divs.
		
		// Turn on only specified content area.
		$('.content-wrapper #' + linkid + '-content').show('fast', function(){
         
		});
		
		// Fade in the updated content.
      setTimeout(function(){$('.content-wrapper').fadeIn('slow'); resetShopTitleSifr();}, 300) ;
	});
}

function resetShopTitleSifr() {
   sIFR.replace(gothambook, {
     selector: '.header-white-light-27',
     css: '.sIFR-root { font-size: 27px; color: #FFFFFF; display:block; }',
     wmode: 'transparent'
   });

   sIFR.replace(gothambook, {
     selector: '.header-orange-light-27',
     css: '.sIFR-root { font-size: 27px; color: #d47106; display:block; }',
     wmode: 'transparent'
   });

   sIFR.replace(gothambook, {
     selector: '.header-white-light-14',
     css: '.sIFR-root { font-size: 14px; color: #FFFFFF; }',
     wmode: 'transparent'
   });
}

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);
	}
}

function hideContent() {
	$('.content-wrapper').css('display', 'none');
}

$(document).ready(function() {

   // Start the auto rotation.
	var interval_id	= setInterval(function(){rotateContent();}, 4000);
	

	$('.tab a').bind('mouseover',
   	function() {
   		clearInterval(interval_id);
			showContent(this.id);
	});

   // Pause automation.
   $('.content-wrapper').bind('mouseenter', function(){
		clearInterval(interval_id);
   });
});
