/* 
	Requires Jquery
  Coder: VC 2008-08
 */
var totalRelatedItems = 0;
var currentRelatedIndex = 0;

$(document).ready(function() {
	totalRelatedItems = jQuery('#secondary-content .related li').length;

	if( totalRelatedItems > 1){
		jQuery('#secondary-content .related li').hide();
	
		//turn first one on
		jQuery('#secondary-content .related li:first').show();
	
		//add the paging
		jQuery('<p class="paginator"><span class="prev prev_grey">&gt;</span><span class="pagenum">1/'+totalRelatedItems+'</span> <span class="next">&lt;</span></p>').insertBefore(jQuery('#secondary-content .related ul'));
		jQuery('#secondary-content .related').addClass('js-related');
		
		//event handlers
		jQuery('#secondary-content .related .prev').click(function(event){
			if(currentRelatedIndex != 0){
				related_browse_prev();
			};
			event.preventDefault();
		});
		jQuery('#secondary-content .related .next').click(function(event){
			if(currentRelatedIndex != totalRelatedItems-1){
				related_browse_next();
			};
			event.preventDefault();
		});
	};	
});

function related_browse_next(){
	jQuery('#secondary-content .related li').hide();
	jQuery('#secondary-content .related .next').removeClass('next_grey');
	jQuery('#secondary-content .related .prev').removeClass('prev_grey');
	currentRelatedIndex = currentRelatedIndex+1;
	if(currentRelatedIndex == totalRelatedItems-1){
		jQuery('#secondary-content .related .next').addClass('next_grey');
	};

	jQuery('#secondary-content .related li:eq('+currentRelatedIndex+')').show();
	jQuery('#secondary-content .related .paginator span.pagenum').text(currentRelatedIndex+1 + "/" + totalRelatedItems);
};

function related_browse_prev(){
	jQuery('#secondary-content .related li').hide();
	jQuery('#secondary-content .related .next').removeClass('next_grey');
	jQuery('#secondary-content .related .prev').removeClass('prev_grey');	
	currentRelatedIndex = currentRelatedIndex-1;
	if(currentRelatedIndex == 0){
		jQuery('#secondary-content .related .prev').addClass('prev_grey');
	};
	
	jQuery('#secondary-content .related li:eq('+currentRelatedIndex+')').show();
	jQuery('#secondary-content .related .paginator span.pagenum').text(currentRelatedIndex+1 + "/" + totalRelatedItems);
};
