var red_rollover_text_color = '#DC0009';
var text_color = '#777';

var thumb_grid = [];
var surrounding_items = [];
var sti;

$(document).ready(function()
{
	//  setup a grid 2d array
	setupGrid();
	
	//  hide the gear nav
	$('#gear_sub_nav_ul').hide();
	
	// ========================================
	// HANDLE RED ROLLOVER IMAGE REPLACEMENT
	// ========================================
	$('.ne_thumb').mouseover(function()
	{
		$(this).find('.ne_name').css({color:red_rollover_text_color});  //  label under photo
		$(this).find('.ne_thumb_thb').css({'display':'none'});  // norm image
		$(this).find('.ne_thumb_thb_red').css({'display':'block'});  // red image
	});
	
	$('.ne_thumb').mouseout(function()
	{
		$(this).find('.ne_name').css({color:text_color});  // label under photo
		$(this).find('.ne_thumb_thb').css({'display':'block'});  // norm image
		$(this).find('.ne_thumb_thb_red').css({'display':'none'});  // red image
	});
	
	// $('.ne_thumb').click(function()
	// {
	// 	findMe($(this).attr('id'));
	// });
	
	$('#flash_content_neb').css({'height':ht + 'px'});
	$('#flash_container_neb').css({'height':ht + 'px'});
	$('#flash_content_neb').css({'margin-bottom':mb + 'px'});
});


// ========================================
// layout the thumb grid rows and columns
// ========================================
function setupGrid()
{
	// thumb_grid
	var thbs = $('#news_events_thumbs').children();
	
	for(var i = 0; i < thbs.length; i++)
	{
		thumb_grid.push(thbs[i].id);
	}
}


// ========================================
//  turn surrounding members white on click
// ========================================
function findMe(a_id)
{
	//  just to make sure on thrash clicking
	clearTimeout(sti);
	showAgain(false);
	
	var curr_row = null;
	var prev_row = null;
	var next_row = null;
	
	surrounding_items = [];
	
	for(var i = 0; i < thumb_grid.length; i++)
	{
		if (a_id == thumb_grid[i])
		{
			if(i - 1 >= 0)
			{
				prev_row = i - 1;
			}
	
			if(i + 1 < thumb_grid.length)
			{
				next_row = i + 1;
			}
		}
	}
		
	// top
	if(prev_row != null)
	{
		surrounding_items.push(thumb_grid[prev_row]);
	}
	// bottom
	if(next_row != null)
	{
		surrounding_items.push(thumb_grid[next_row]);
	}
			
	hideItems();
	return;
}

function hideItems()
{
	for(var i = 0; i < surrounding_items.length; i++)
	{
		$('#' + surrounding_items[i]).fadeTo(50 + (Math.random() * 950), 0);
	}
	
	sti = setTimeout('showAgain(true)', 1500);
}

function showAgain(a_bFromTimer)
{
	if(!a_bFromTimer)
	{
		for(var i = 0; i < surrounding_items.length; i++)
		{
			$('#' + surrounding_items[i]).fadeTo(10, 1);
		}
	}
	else
	{
		for(var i = 0; i < surrounding_items.length; i++)
		{
			$('#' + surrounding_items[i]).fadeTo(50 + (Math.random() * 950), 1);
		}
		
		$.scrollTo(0, 750, {easing:'easeInOutExpo'});
		// window.scrollTo(0,0);
	}
}
