var rotate = 
{
	// global vars
	image_url: new Array(),
	arrayLength: null,
	
	changeImage: function(type)
	{
		// fade image out
		$('#currentImage').animate({opacity: 0.1}, 'fast', function()
		{
			var thisNum = parseInt($('#currentImage').attr('alt').replace(/Featured Project /g,''));
			var newImageId = 0;
			
			if(type == 'prev')
			{
				// determine next image
				newImageId = (thisNum > 0) ? (thisNum-1) : rotate.arrayLength;				
			}
			else
			{
				// determine next image
				newImageId = (thisNum < rotate.arrayLength) ? (thisNum+1) : 0;				
			}
			
			// force image to load
			var nextImage = new Image(); 
			nextImage.src = rotate.image_url[newImageId][0];
			
			$('#featName').text(rotate.image_url[newImageId][1]);
			//$('#featLocation').text(rotate.image_url[newImageId][2]);
			$('#featLink').attr('href', ('/Careers/CultureHighlight/' + rotate.image_url[newImageId][2] + '?KeepThis=true&TB_iframe=true&height=580&width=630'));
			//$('#viewProjectLink').attr('href', ('/Portfolio/ViewProject/' + rotate.image_url[newImageId][3]));
			
			if(nextImage.complete)
			{
				// fade new image in
				$('#currentImage').attr('src', rotate.image_url[newImageId][0]).attr('alt', ''+newImageId);
				$('#currentImage').animate({opacity: 1}, 'fast');
								
			}
			else
			{
				nextImage.onload = function()
				{
					$('#currentImage').attr('src',rotate.image_url[newImageId][0]).attr('alt', ''+newImageId);
					$('#currentImage').animate({opacity: 1}, 'fast');
				}								
			}						
		});		
	},

	init: function()
	{		                                                                                                          
		rotate.image_url[0] = new Array('/img/culture_highlights_popup/small/RT_30.jpg', 'Rebuilding Together', '1');
		rotate.image_url[1] = new Array('/img/culture_highlights_popup/small/RT_38.jpg', 'Rebuilding Together', '2');
		rotate.image_url[2] = new Array('/img/culture_highlights_popup/small/RT_44.jpg', 'Rebuilding Together', '3');
		rotate.image_url[3] = new Array('/img/culture_highlights_popup/small/RT_71.jpg', 'Rebuilding Together', '4');
		rotate.image_url[4] = new Array('/img/culture_highlights_popup/small/AS_1.jpg', 'T&R Employee Art Show', '5');
		rotate.image_url[5] = new Array('/img/culture_highlights_popup/small/AS_11.jpg', 'T&R Employee Art Show', '6');
		rotate.image_url[6] = new Array('/img/culture_highlights_popup/small/AS_16.jpg', 'T&R Employee Art Show', '7');
		rotate.image_url[7] = new Array('/img/culture_highlights_popup/small/AS_8.jpg', 'T&R Employee Art Show', '8');
		rotate.image_url[8] = new Array('/img/culture_highlights_popup/small/TDC_1.jpg', 'Napa Tour de Cure', '9');
		rotate.image_url[9] = new Array('/img/culture_highlights_popup/small/TDC_14.jpg', 'Napa Tour de Cure', '10');
		rotate.image_url[10] = new Array('/img/culture_highlights_popup/small/SB_9.jpg', 'Treadwell & Rollo Softball - Playing the Field', '11');
		rotate.image_url[11] = new Array('/img/culture_highlights_popup/small/SB_12.jpg', 'Treadwell & Rollo Softball - At Bat', '12');
		rotate.image_url[12] = new Array('/img/culture_highlights_popup/small/SB_16.jpg', 'Treadwell & Rollo Softball - The Team', '13');
		
		
		rotate.arrayLength = rotate.image_url.length;
		rotate.arrayLength -= 1;
		$('#hlPrevious').bind('click', function() { rotate.changeImage('prev'); });
		$('#hlNext').bind('click', function() { rotate.changeImage('next'); });
	}
}