String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


function formatText(index, panel)
{
  return index;
}

function onAfter(curr, next, opts) {

	var index = opts.currSlide;
	jQuery('a#prev_herring,a#next_herring').hide();
	jQuery('a#prev,a#next').show().css('display','inline-block');
	
	// hide all the links
	jQuery('#thumbLinks a').addClass('hide');
	
	if(index == 0) {
		jQuery('a#prev_herring').show().css('display','inline-block');
		jQuery('a#prev').hide();
		jQuery('#thumbLinks a:eq(0),#thumbLinks a:eq(1),#thumbLinks a:eq(2)').removeClass('hide');
	} else if(index == opts.slideCount-1) { 
		a = index-2;
		b = index-1;
		c = index;
		jQuery('a#next_herring').show().css('display','inline-block');
		jQuery('a#next').hide(); 
		jQuery('#thumbLinks a:eq('+a+'),#thumbLinks a:eq('+b+'),#thumbLinks a:eq('+c+')').removeClass('hide');
	} else {
		a = index-1;
		b = index;
		c = index+1;
		jQuery('#thumbLinks a:eq('+a+'),#thumbLinks a:eq('+b+'),#thumbLinks a:eq('+c+')').removeClass('hide');
	}
}

jQuery(function(){
	if(jQuery('body.home').size() > 0)
	{
		var IE = /*@cc_on!@*/false;
		jQuery('.description').each(function(){
			if(IE)
			{
				contents = jQuery(this).html();
				if(contents.length == 0){ jQuery(this).remove(); }
			} else {
				if(jQuery(this).html().trim() == ""){ jQuery(this).remove(); }
			}
		});

		jQuery('a#prev_herring,a#next_herring').click(function(){ return false; });
		jQuery('ul.photos').cycle({
			fx:     'fade',
			speed:  'slow',
			prev:   '#prev',
			next:   '#next',		
			timeout: 10000,
			pager:  '#thumbLinks',
			after:   onAfter,
			slideExpr: 'li'
		});
		
		// on page load show those first three
		jQuery('#thumbLinks a').addClass('hide');
		jQuery('#thumbLinks a:eq(0),#thumbLinks a:eq(1),#thumbLinks a:eq(2)').removeClass('hide');
	}
});
